How do I summarize the buckets from a term aggregation

Hi I have query that looks like...

{
  "query": {
    "bool": {
      "must": [
        {"match": {"TxnCode.keyword": "XX"}}
      ]
    }
  },
  "size": 0,
  "aggs": {
      "date_buckets": {
      "terms": {
        "field": "Date.keyword",
        "order": {"_key": "desc"}
      },
      "aggs": {
        "terminal_buckets": {
            "terms": {
                "field": "TermID.keyword",
                "order": {"_key": "desc"}
            }
        }
    }
  }
}
}

This gives me a breakdown, by date, of how many times I see Terminal ID has TxnCode = XX. Ie:

Date : 2019-10-01

  • Terminal1 : 6
  • Terminal2 : 15
  • Terminal3 : 10
  • Terminal4 : 25

What I want now is to count the numbers of terminals group by number of occurances. Ie:

Date 2019-10-01

  • 1 to 5 : 0
  • 6 to 10: 2
  • 11 to 20 : 1
  • 20+ : 1

Is that possible?

Thanks
Paul

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