2013-05-07 12 views
6

Mam trzy dokumenty z "username" polu:ElasticSearch edgeNGram dla autouzupełniania wpisywanie znaków z wyprzedzeniem, to mój search_analyzer ignorowane

  • 'briandilley'
  • 'briangumble'
  • 'briangriffen'

Kiedy szukam "briana", wszystkie trzy odzyskują zgodnie z oczekiwaniami, ale kiedy szukam "briandilley", wciąż odzyskuję wszystkie trzy. Interfejs API analizy mówi mi, że używa filtru ngram w ciągu wyszukiwania, ale nie jestem pewien dlaczego. oto moja konfiguracja:

ustawienia Index:

{ 
    "analysis": { 
     "analyzer": { 
      "username_index": { 
       "tokenizer": "keyword", 
       "filter": ["lowercase", "username_ngram"] 
      }, 
      "username_search": { 
       "tokenizer": "keyword", 
       "filter": ["lowercase"] 
      } 
     }, 
     "filter": { 
      "username_ngram": { 
       "type": "edgeNGram", 
       "side" : "front", 
       "min_gram": 1, 
       "max_gram": 15 
      } 
     } 
    } 
} 

mapowanie:

{ 
    "user_follow": { 

     "properties": { 
      "targetId": { "type": "string", "store": true }, 
      "followerId": { "type": "string", "store": true }, 
      "dateUpdated": { "type": "date", "store": true }, 

      "userName": { 
       "type": "multi_field", 
       "fields": { 
        "userName": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "autocomplete": { 
         "type": "string", 
         "index_analyzer": "username_index", 
         "search_analyzer": "username_search" 
        } 
       } 
      } 
     } 
    } 
} 

wyszukiwania:

{ 
    "from" : 0, 
    "size" : 50, 
    "query" : { 
     "bool" : { 
      "must" : [ { 
       "field" : { 
        "targetId" : "51888c1b04a6a214e26a4009" 
       } 
      }, { 
       "match" : { 
        "userName.autocomplete" : { 
         "query" : "brian", 
         "type" : "boolean" 
        } 
       } 
      } ] 
     } 
    }, 
    "fields" : "followerId" 
} 

I ve wypróbowane matchQuery, matchPhraseQuery, textQuery i termQuery (java DSL api) i uzyskuję zawsze te same wyniki.

Odpowiedz

9

Myślę, że nie robisz dokładnie tego, co myślisz, że robisz. Dlatego warto przedstawić rzeczywisty przypadek testowy z pełnymi oświadczeniami curl, zamiast go skracać.

Twój Powyższy przykład działa na mnie (nieco zmodyfikowane):

Tworzenie indeksu z ustawień i mapowania:

curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d ' 
{ 
    "mappings" : { 
    "test" : { 
     "properties" : { 
      "userName" : { 
       "fields" : { 
       "autocomplete" : { 
        "search_analyzer" : "username_search", 
        "index_analyzer" : "username_index", 
        "type" : "string" 
       }, 
       "userName" : { 
        "index" : "not_analyzed", 
        "type" : "string" 
       } 
       }, 
       "type" : "multi_field" 
      } 
     } 
    } 
    }, 
    "settings" : { 
    "analysis" : { 
     "filter" : { 
      "username_ngram" : { 
       "max_gram" : 15, 
       "min_gram" : 1, 
       "type" : "edge_ngram" 
      } 
     }, 
     "analyzer" : { 
      "username_index" : { 
       "filter" : [ 
       "lowercase", 
       "username_ngram" 
       ], 
       "tokenizer" : "keyword" 
      }, 
      "username_search" : { 
       "filter" : [ 
       "lowercase" 
       ], 
       "tokenizer" : "keyword" 
      } 
     } 
    } 
    } 
} 
' 

Główna część danych:

curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d '{ 
    "userName" : "briangriffen" 
} 
' 

curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d ' 
{ 
    "userName" : "brianlilley" 
} 
' 

curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d ' 
{ 
    "userName" : "briangumble" 
} 
' 

poszukiwanie brian znalezisk wszystkie dokumenty:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1' -d '{ 
    "query" : { 
    "match" : { 
     "userName.autocomplete" : "brian" 
    } 
    } 
} 
' 

# { 
# "hits" : { 
#  "hits" : [ 
#   { 
#    "_source" : { 
#    "userName" : "briangriffen" 
#    }, 
#    "_score" : 0.1486337, 
#    "_index" : "test", 
#    "_id" : "AWzezvEFRIykOAr75QbtcQ", 
#    "_type" : "test" 
#   }, 
#   { 
#    "_source" : { 
#    "userName" : "briangumble" 
#    }, 
#    "_score" : 0.1486337, 
#    "_index" : "test", 
#    "_id" : "qIABuMOiTyuxLOiFOzcURg", 
#    "_type" : "test" 
#   }, 
#   { 
#    "_source" : { 
#    "userName" : "brianlilley" 
#    }, 
#    "_score" : 0.076713204, 
#    "_index" : "test", 
#    "_id" : "fGgTITKvR6GJXI_cqA4Vzg", 
#    "_type" : "test" 
#   } 
#  ], 
#  "max_score" : 0.1486337, 
#  "total" : 3 
# }, 
# "timed_out" : false, 
# "_shards" : { 
#  "failed" : 0, 
#  "successful" : 5, 
#  "total" : 5 
# }, 
# "took" : 8 
# } 

Poszukiwanie brianlilley stwierdza tylko, że dokument:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1' -d ' 
{ 
    "query" : { 
    "match" : { 
     "userName.autocomplete" : "brianlilley" 
    } 
    } 
} 
' 

# { 
# "hits" : { 
#  "hits" : [ 
#   { 
#    "_source" : { 
#    "userName" : "brianlilley" 
#    }, 
#    "_score" : 0.076713204, 
#    "_index" : "test", 
#    "_id" : "fGgTITKvR6GJXI_cqA4Vzg", 
#    "_type" : "test" 
#   } 
#  ], 
#  "max_score" : 0.076713204, 
#  "total" : 1 
# }, 
# "timed_out" : false, 
# "_shards" : { 
#  "failed" : 0, 
#  "successful" : 5, 
#  "total" : 5 
# }, 
# "took" : 4 
# } 
+0

Robię to w badanej jednostki Java - więc dlatego nie ma żadnych wypowiedzi CURL (za pomocą klienta w pamięci). –

+0

Są szanse, że wtedy robisz coś złego. Odwzorowując to jako zwinięcie, możesz zobaczyć, czy możesz odtworzyć problem. Jeśli nie, problem występuje w kodzie Java. (Mam na myśli ręczne tworzenie instrukcji zwijania, co możesz zrobić) – DrTech

+0

Miałeś rację - indeksowałem nazwę użytkownika celu zamiast jego nazwę użytkownika. Zasadniczo złe indeksowanie z mojej strony. Oceniłem twoją odpowiedź jako poprawną, ponieważ pomogłeś doprowadzić mnie do prawdziwego problemu. –

Powiązane problemy