Hi all,
My question is quite simple I think.
I have the query below where I use two types of aggregations. The query works fine.
GET /testeagg/_search
{
"aggregations": {
"group_by_id": {
"aggregations": {
"sum_qtd_item": {
"sum": { "field": "activities.qtd_itens" } }
},
"terms": {"field": "id_single_profile", "order": {"sum_qtd_item": "desc" } }
}
},
"ext": {},
"query": { "match_all": {} },
"size": 0
}
My output:
"aggregations": {
"group_by_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 555,
"doc_count": 1,
"sum_qtd_item": {
"value": 6
}
},
{
"key": 999,
"doc_count": 1,
"sum_qtd_item": {
"value": 6
}
},
{
"key": 123,
"doc_count": 1,
"sum_qtd_item": {
"value": 3
}
},
{
"key": 666,
"doc_count": 1,
"sum_qtd_item": {
"value": 0
}
}
]
}
}
All I need to do now is apply an filter in aggregation value (like we used to do by using HAVING clause in SQL).
For example, return all the keys with sum(activities.qtd_itens) > 3
.
I tried to use filter+range without success. I don't know where is the exactly place I need to put the line below.
"filter": { "range": { "sum_qtd_item": { "gte": 3 } } }
I'll appreciate if anyone can help me with this.
Thanks!