I have two objects in the index "name" and "email". "name" can be of ngrams max of 10. I want to create index with above. So I have created my index with mappings and settings as
{
"mappings": {"properties": {"email": {"type": "text", "analyzer": "keyword_analyzer"}, "name": {"type": "text", "analyzer": "keyword_analyzer"} } },
"settings": {"index": {"analysis" : {"analyzer" : {"keyword_analyzer" : {"filter" : ["lowercase"], "tokenizer" : "keyword"} } }, "number_of_shards": "1", "number_of_replicas": "0", "max_ngram_diff" : "5"} } }
I have inserted some data
{"name": "divya p", "email": "divya@email.com"}
{"name": "divya a", "email": "divya12123@email.com"}
{"name": "kumar a", "email": "kumar@email.com"}
{"name": "aruna v", "email": "aruna@email.com"}
and I want to search all the names that have name "divya" so i have used a query
{"query": {"bool": {"should": [{"match": {"name": "divya"} } ] } } }
it doesnt return any result, but if i give the full name it gives me the results
{"query": {"bool": {"must": [{"match": {"name": "divya a"} } ] } } }
to check the issue I have modified the settings by adding "filter" as mentioned in the link's first answer. But when I am running the query I am getting all the 4 values inserted. Please guide where I went wrong ? My modified settings as below
"settings": {"index": {"analysis": {"analyzer": {"keyword_analyzer": {"filter": ["lowercase", "ngram_filter"], "type": "custom", "tokenizer": "standard"} }, "filter": {"ngram_filter": {"type": "nGram", "min_gram": "1", "max_gram": "5"} } }, "number_of_shards": "1", "number_of_replicas": "0", "max_ngram_diff" : "50"} }