Group by Aggregation doc_count

Hi, I'm hoping someone could assist with this query.

I'm trying to group by the doc_count from another aggregation.

In SQL this query would look like this:

SELECT bucket, COUNT(1) AS bucket_count FROM (
    SELECT a_field, COUNT(1) AS bucket FROM table GROUP BY a_field
)
GROUP BY bucket

So initial aggregation would look like this:

"aggs": {
	"group_by_a_field": {
		"terms": {
			"field": "a_field"
		}
	}
}

How do i then go about grouping on the respective doc_count's?

Thanks in advance for any response!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.