2016-11-28 5 views
0
funktioniert

Ich habe ein Feld mit dem folgenden Mapping definiert:Mit der automatischen Vervollständigung mit E-Mail in Elasticsearch nicht

"my_field": { 
    "properties": { 
     "address": { 
      "type": "string", 
      "analyzer": "email", 
      "search_analyzer": "whitespace" 
     } 
    } 
} 

Meine E-Mail-Analysator wie folgt aussieht:

{ 
    "analysis": { 
     "filter": { 
      "email_filter": { 
       "type": "edge_ngram", 
       "min_gram": "3", 
       "max_gram": "255" 
      } 
     }, 
     "analyzer": { 
      "email": { 
       "type": "custom", 
       "filter": [ 
        "lowercase", 
        "email_filter", 
        "unique" 
       ], 
       "tokenizer": "uax_url_email" 
      } 
     } 
    } 
} 

Wenn ich suchen versuchen für eine E-Mail-ID, wie [email protected]

Suche nach Begriffen wie tes, test.xy etc. funktioniert nicht. Aber wenn ich nach test.xyz oder [email protected] suche, funktioniert es gut. Ich habe versucht, die Token mit meinem E-Mail-Filter zu analysieren und es funktioniert gut wie erwartet

Ex. http://localhost:9200/my_index/_analyze?analyzer=email&[email protected] Schlagen

ich:

{ 
    "tokens": [{ 
     "token": "tes", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.x", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.xy", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.xyz", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }] 
} 

So weiß ich, dass die Tokenisierung funktioniert. Während der Suche wird jedoch nicht nach Teilzeichenfolgen gesucht.

Für z. Auf der Suche nach http://localhost:9200/my_index/my_field/_search?q=test zeigt das Ergebnis keine Treffer.

Details von meinem Index:

{ 
    "my_index": { 
     "aliases": { 
      "alias_default": {} 
     }, 
     "mappings": { 
      "my_field": { 
       "properties": { 
        "address": { 
         "type": "string", 
         "analyzer": "email", 
         "search_analyzer": "whitespace" 
        }, 
        "boost": { 
         "type": "long" 
        }, 
        "createdat": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        }, 
        "instanceid": { 
         "type": "long" 
        }, 
        "isdeleted": { 
         "type": "integer" 
        }, 
        "object": { 
         "type": "string" 
        }, 
        "objecthash": { 
         "type": "string" 
        }, 
        "objectid": { 
         "type": "string" 
        }, 
        "parent": { 
         "type": "short" 
        }, 
        "parentid": { 
         "type": "integer" 
        }, 
        "updatedat": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        } 
       } 
      } 
     }, 
     "settings": { 
      "index": { 
       "creation_date": "1480342980403", 
       "number_of_replicas": "1", 
       "max_result_window": "100000", 
       "uuid": "OUuiTma8CA2VNtw9Og", 
       "analysis": { 
        "filter": { 
         "email_filter": { 
          "type": "edge_ngram", 
          "min_gram": "3", 
          "max_gram": "255" 
         }, 
         "autocomplete_filter": { 
          "type": "edge_ngram", 
          "min_gram": "3", 
          "max_gram": "20" 
         } 
        }, 
        "analyzer": { 
         "autocomplete": { 
          "type": "custom", 
          "filter": [ 
           "lowercase", 
           "autocomplete_filter" 
          ], 
          "tokenizer": "standard" 
         }, 
         "email": { 
          "type": "custom", 
          "filter": [ 
           "lowercase", 
           "email_filter", 
           "unique" 
          ], 
          "tokenizer": "uax_url_email" 
         } 
        } 
       }, 
       "number_of_shards": "5", 
       "version": { 
        "created": "2010099" 
       } 
      } 
     }, 
     "warmers": {} 
    } 
} 
+0

für die Suche haben Sie "search_analyzer": "Whitespace" -Analysator. entferne das und mach das Mapping – Backtrack

+0

@ Backtrack Ich glaube, das ist richtig. Überprüfen Sie http://stackoverflow.com/a/15932838/1465701. Wenn ich hier nicht etwas verpasse, sollte dies das richtige Verhalten sein. – nerandell

+2

Es gibt einen Tippfehler in Ihrem Mapping, "Analyser" sollte "Analyzer" lesen – Val

Antwort

1

Ok, alles korrekt aussieht, außer Ihrer Anfrage.

Sie müssen einfach nur die address Feld in Ihrer Abfrage wie folgt angeben, und es wird funktionieren:

http://localhost:9200/my_index/my_field/_search?q=address:test 

Wenn Sie das address Feld gebe, wird die Abfrage arbeiten auf dem _all Feld, dessen Suche Analysator ist die standard eine standardmäßig, weshalb Sie nichts finden.

+0

Es hat funktioniert. Ich akzeptiere dies als Antwort. – nerandell

+0

Super, froh, dass es geholfen hat! – Val

Verwandte Themen