Two aggregations on different filter in same query

I perform two separate request for my aggregations as:

  1. For sum of payments of bill number = 3

     {
       "query": {
          "bool": {
            "must": [
              {"match": {"num_ra_bill_no": 2 }}
           ]
          }
        },
        "aggs": {
          "upToDatePayment": {
            "sum": {
              "script": "doc['num_upto_date_qty'].value * doc['num_rate'].value "
            }
          }
        }
     }
    
  2. For sum of payments of bill number less than 3

    {
           "query": {
              "bool": {
                "must": [
                 {"range": {"num_ra_bill_no": {"lt": 2 } }}
               ]
              }
            },
            "aggs": {
              "previousPayment": {
                "sum": {
                  "script": "doc['num_upto_date_qty'].value * doc['num_rate'].value "
                }
              }
            }
         }
    

As You can see both the request perform the same operations only the change is the filter.

Is there a way such that I can perform 1 aggregation on different filter and 2nd aggregation on another filter??

Have a look at:

Thanks!:grinning:

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