elasticsearch - sum of total amount is greater than some amount using aggregation elasticsearch - sum of total amount is greater than some amount using aggregation elasticsearch elasticsearch

elasticsearch - sum of total amount is greater than some amount using aggregation


You need to use a bucket_selector pipeline aggregation, you cannot do it in the query part:

{  "query": {    "bool": {      "must": [        {          "term": {            "client_id": 1          }        }      ]    }  },  "aggs": {    "customers": {      "terms": {        "field": "custid"      },      "aggs": {        "amount_spent": {          "sum": {            "field": "total_amount"          }        },        "amount_spent_filter": {          "bucket_selector": {            "buckets_path": {              "amountSpent": "amount_spent"            },            "script": "params.amountSpent > 1000"          }        }      }    }  }}