I am doing my autocompletion project and new to Elasticsearch. I have used Edge NGram filter for autocompletion. I am trying to get unique results for autocompletion, So I have used terms aggregation for all the fields. I am getting good results for the field having 1 value, but for the fields having more than one value.. if the query matches at least one value from that field.. it is giving me all the values from that field(whether the query matches or not in other values).
My settings and mapping under the garments index are :
PUT /garments
{
"settings" :
{
"number_of_replicas": 3,
"number_of_shards": 2,
"analysis":
{
"analyzer":
{
"autocomplete":
{
"tokenizer": "autocomplete",
"filter":
[
"lowercase"
]
},
"autocomplete_search":
{
"tokenizer": "lowercase"
}
},
"tokenizer":
{
"autocomplete":
{
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10,
"token_chars":
[
"letter"
]
}
}
}
},
"mappings":
{
"properties":
{
"color":
{
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search",
"fields":
{
"keyword":
{
"type": "keyword"
}
}
}
........
........
........
}
}
(note that i am using text type) suppose I have a color field in a doc having multi values like :["blue","black","orange","marble","jet black"] and my search query is :
GET /garments/_search
{
"size": 0,
"query":
{
"query_string": {
"query": "bl"
}
},
"aggs":
{
"Term_aggregation":
{
"terms":
{
"field": "color.keyword",
"size": 100
}
}
}
}
this gives me all the outputs i.e.: "blue","black","orange","marble","jet black". But i wanted only blue, black, jet black as my results(query is "bl"). Later I used
"include": " .*bl.*"
filter in my terms aggs.. which gave me blue,black,marble,jet black as my results.. this include filter is case sensitive... Please help!