Getting the count of filtered buckets in elasticsearch

Hi,I want to get the count of the buckets array after applying bucket_filter in the aggregated bucket.This is how my document looks like-

{
          "cdid" : "CD1234",
          "transactionid" : "000000261119929",
          "itemid" : "612",
          "transactionDate" : "2019-09-17 00:00:09.196 +00:00",
          "quantity" : 2,
          "rate" : 7.12,
          "amount" : "7.12",
          "billAmt" : 248.48,
          "id" : "13"
 }

Since this is a transaction document I wanted to aggregate it with the cdid and filter all the documents whose sum of quantity is greater than 10.And then finally get the count of the total count of the customers satisfying the criteria.This is how I tried.

{
  "aggs": {
    "CDID": {
      "terms": {
        "field": "cdid.keyword"
      },
      "aggs": {
        "quanity": {
          "sum": {
            "field": "quantity",
            
          }
        },
        "bucket_filter": {
          "bucket_selector": {
            "buckets_path": {
              "the_doc_count01": "quanity"
            },
            "script": "(params.the_doc_count01 > 10)"
          }
        }
      }
    },
    "count":{
      "cardinality": {
        "field": "CDID"
      }
    }
  }
}

But I'm getting the count of the first aggregated bucket and not the filtered bucket.Can anyone tell me how could I solve this

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