elasticsearch - Multi match query in elastic not matching initial character -


hello trying setup single search box partial searches on fields , standard searches on others. there failing past following hurdle:

this index:

put /my_index {     "mappings": {         "blogpost": {             "properties": {                 "firstname": {                     "fields": {                         "autocomplete": {                             "index_analyzer": "autocomplete",                             "type": "string"                         },                         "firstname": {                             "index_analyzer": "standard",                             "type": "string"                         }                     },                     "type": "string"                 }             }         }     },     "settings": {         "index": {             "analysis": {                 "analyzer": {                     "autocomplete": {                         "tokenizer": "ngram_tokenizer",                         "type": "custom"                     },                     "standard": {                         "type": "standard"                     }                 },                 "tokenizer": {                     "ngram_tokenizer": {                         "max_gram": "20",                         "min_gram": "2",                         "type": "ngram"                     }                 }             },             "creation_date": "1431690991641",             "number_of_replicas": "0",             "number_of_shards": "3",             "uuid": "w4ug6iads9myun5_pqlhow",             "version": {                 "created": "1040499"             }         }     } } 

index 1 document:

put /my_index/blogpost/1 {"firstname" : "albert"} 

simple query:

/_search?q=albert 

returns albert. good.

multi_match query:

{   "query": {     "multi_match": {       "query": "albert",       "fields": [         "firstname",         "firstname.autocomplete"       ]     }   } } 

also returns albert. good.

if replace albert bert returns albert. good.

but "al" or "al" or "alber" or "alber" not! search beginning letter included fails.

yet

/my_index/_search?firstname.autocomplete:al 

is good.

please help.

the search analyzer field.autocomplete default standard.

so when search al looking "al" "al" end searching lowercase version.

however while indexing using autocomplete analyzer not normalizing data lowercase has term "al" in index.

you can use analyze api check how data has been analyzed

get /my_index/_analyze?field=firstname.autocomplete&text=albert" 

adding lowercase token filter "autocomplete" analyzer should fix issue :

   "autocomplete": {                         "tokenizer": "ngram_tokenizer",                         "type": "custom",                         "filter" :[                             "lowercase"                         ]                     }, 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -