Elasticsearch aggregation. Order by nested bucket doc_count
What I want to achieve is aggregation by unique pairs (city, STATE). As per Elasticsearch documentation The terms aggregation does not support collecting terms from multiple fields in the same document . Thus I created a nested agg like this: { "size": 0, "aggs": { "cities": { "terms": { "field": "address.city", "size": 12 }, "aggs": { "states": { "terms": { "field": "address.stateOrProvince" }, "aggs": { "topCity": { "top_hits": { "size": 1, "sort": [ { "price.value": { "order": "desc" }}]}}}}}}}} As a result of this aggregation I get response like this: { "aggregations": { "cities": {