elasticsearch - ES search without wildcards not getting results with analyzer -
after reading official documentation , q&a here still can't elasticsearch search partial words without wildcards.
i've got ~470k entries of companies , want accomplish kind of autocompletion when starting enter company name.
the index gets created this:
{ "lei-index" : { "aliases" : { }, "mappings" : { "record" : { "properties" : { "legalname" : { "type" : "text", "analyzer" : "legalname_analyzer", "search_analyzer" : "legalname_search" } } } }, "settings" : { "index" : { "number_of_shards" : "5", "provided_name" : "lei-index", "creation_date" : "1478597987141", "analysis" : { "filter" : { "legalname_filter" : { "type" : "edge_ngram", "min_gram" : "4", "max_gram" : "20" } }, "analyzer" : { "legalname_analyzer" : { "filter" : [ "legalname_filter", "lowercase" ], "type" : "custom", "tokenizer" : "legalname_tokenizer" }, "legalname_search" : { "filter" : [ "legalname_filter", "standard", "lowercase" ], "type" : "custom", "tokenizer" : "legalname_tokenizer" } }, "tokenizer" : { "legalname_tokenizer" : { "token_chars" : [ "letter" ], "min_gram" : "4", "type" : "edge_ngram", "max_gram" : "20" } } }, "number_of_replicas" : "1", "uuid" : "mubvjn9bsbayrkvxsixxqw", "version" : { "created" : "5000051" } } } } }
when know lets hapag-loyd, can search "hapag" , 3 results "hapag loyd", "hapag-loyd", , "hapag loyd"
but want archive can search "hapa" , results.
http://localhost:9200/lei-index/record/_search?pretty&q=hapa
0 results
with wildcard results, including hapag loyd, guess wildcards inefficient in larger indexes
http://localhost:9200/lei-index/record/_search?pretty&q=hapa*
i tried use keywords tokenizer , leaving filter out , use tokenizer didn't expected results.
testing analyzer:
curl -xpost 'localhost:9200/lei-index/_analyze?pretty' -d '{ "analyzer": "legalname_analyzer", "text": "hapag"}' { "tokens" : [ { "token" : "hapa", "start_offset" : 0, "end_offset" : 4, "type" : "word", "position" : 0 }, { "token" : "hapa", "start_offset" : 0, "end_offset" : 5, "type" : "word", "position" : 1 }, { "token" : "hapag", "start_offset" : 0, "end_offset" : 5, "type" : "word", "position" : 1 } ] }
would great if point out thinking goes wrong here, since it's first time work elasticsearch.
and 1 last thing, i've got nothing hapag-loyd, used example here.
thanks
when making following request, standard analyzer query_string
query kicks in.
http://localhost:9200/lei-index/record/_search?pretty&q=hapa
that's not want. instead, need specify legalname
field search_analyzer
field leveraged:
http://localhost:9200/lei-index/record/_search?pretty&q=legalname:hapa
another solution keep query override standard analyzer of query string own one:
http://localhost:9200/lei-index/record/_search?pretty&q=hapa&analyzer=legalname_search
Comments
Post a Comment