I want to perform following in the elasticsearch.
select distinct name, city from students where class = 10 and age = 15;
and it should return all distinct values for name and city. How to perform this?
I want to perform following in the elasticsearch.
select distinct name, city from students where class = 10 and age = 15;
and it should return all distinct values for name and city. How to perform this?
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-collapse. Field collapsing Should be helpful here.
{
"query": {
"bool": {
"must": [
{"match":
{
"class": 10
}
},
{"match":
{
"age": 15
}
}
]
}
},
"collapse" : {
"field" : "name.keyword" ,
"inner_hits" : {
"name": "by_type",
"collapse" : {"field" : "city.keyword"}
}
},
"size": 100
}
The above query will return one document par name and city after matching with class and age.