SQL like GROUP BY AND HAVING
I want to get the counts of groups which satisfy a certain condition. In SQL terms, I want to do the following in Elasticsearch. SELECT COUNT(*) FROM ( SELECT senderResellerId, SUM(requestAmountValue) AS t_amount FROM transactions GROUP BY senderResellerId HAVING t_amount > 10000 ) AS dum; So far, I could group by senderResellerId by term aggregation. But when I apply filters, it does not work as expected. Elastic Request { "aggregations": { "reseller_sale_sum": { "aggs": { "sales": { "aggregations": { "reseller_sale": { "sum": { "field": "requestAmountValue" } } }, "filter": { "range": {