elasticsearch n-gram example clarification -
with reference example quoted here https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.html
looking "adler" returns results. search “adler” becomes query 3 terms adl, dle, , ler:
but why query "zdler" returning results though zdl not 1 of terms ?
get /my_index/my_type/_search { "query": { "match": { "text": { "query": "zdler" } } } } applying match query search on "adler" returns record -- expected.
however, match query on "zdler" returns record (because dle , ler match). setting "minimum_should_match": "100%" returns record - not expected
applying term query search on "adler" returns nothing -- not expected
post /my_index/my_type/_search { "query": { "term": { "text": { "value": "adler" } } } } how achieve returning record search on "adler" , not on "zdler" ?
"settings": { "index": { "number_of_shards": "5", "provided_name": "my_index", "creation_date": "1501069624443", "analysis": { "filter": { "trigrams_filter": { "type": "ngram", "min_gram": "3", "max_gram": "3" } }, "analyzer": { "trigrams": { "filter": [ "lowercase", "trigrams_filter" ], "type": "custom", "tokenizer": "standard" } } }, "number_of_replicas": "1", "uuid": "z5bxi_rjtacztsr_-nu9tw", "version": { "created": "5040099" } } } and these mappings
{ "my_index": { "mappings": { "my_type": { "properties": { "text": { "type": "text", "analyzer": "trigrams" } } } }
match query applies field analyzer on input query before throwing query. produces tokens input ("zdler") matched again inverted index. same not case terms query doesn't apply field analyzer on input value
match query breaks "adler" -> "a", "d", "l", "e" ..... on matched against inverted index.
try understand follow 2 queries
post index5/_search { "query": { "match": { "text": "zdler" } } } post index5/_search { "query": { "term": { "text": { "value": "zdler" } } } }
Comments
Post a Comment