Elasticsearch match query with partial text match -


newbie question on elasticsearch. have set elasticsearch lucene index , use searching names contain term, such as

search_response = es.search(index = 'sample', body = {'query':{'match':{'first_name':"just"}}}) 

this not return me name "justin" following query does

search_response = es.search(index = 'sample', body = {'query':{'match':{'first_name':"justin"}}}) 

what doing wrong? shouldn't "match" query return me records contain term? thanks.

the best way handle need creating custom analyzer uses edgengram token filter. forget wildcards , using * in query strings, underperform edgengram approach.

so you'd have create index first , reindex data it.

curl -xput http://localhost:9200/sample -d '{     "settings": {         "analysis": {             "filter": {                 "prefixes": {                     "type": "edgengram",                     "min_gram": 1,                     "max_gram": 15                 }             },             "analyzer": {                 "my_analyzer": {                     "type": "custom",                     "tokenizer": "standard",                     "filter": ["lowercase", "prefixes"]                 }             }         }     },     "mappings": {         "your_type": {             "properties": {                 "first_name": {                     "type": "string",                     "analyzer": "my_analyzer",                     "search_analyzer": "standard"                 }             }         }     } }' 

then when indexing first_name: justin, you'll following indexed tokens: j, ju, jus, just, justi, justin, prefixes of justin.

you'll able search second query , find expect.

search_response = es.search(index = 'sample', body = {'query':{'match':{'first_name':'just'}}}) 

Comments

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -