Dividing buckets values

Hi Community,

Below is my query. It is performing count no. of response_code and total no. of response_code using filters aggregation. I want to divide response_code by total no of response_code

For dividing i used bucket_script aggregation.

{
  "query": {
    "bool": {
      "filter": [
        { "range":
            {
              "@timestamp":
              {
                "gte": "2022-09-21T09:00:00.000Z",
              "lte": "2022-09-21T09:30:00.000Z",
              "format":"yyyy-MM-dd HH:mm:ss||strict_date_optional_time ||epoch_millis"
              }
            }
          }
      ]
    }
  }, 
  "aggs": {
    "response_percentage": {
      "filters": {
        "filters": {
          "response_code":
          {
            "bool": {
               "should": [
            {
              "match_phrase": {
                "ResponseCode": "005"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "008"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "081"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "091"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "096"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "900"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "009"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "0068"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "153"
              }
            }
          ]
            }
          },
          "without_response":
          {
              "bool": {
                "must": [
                  {
                    "match_all": {}
                  }
                ]
              }
          }
        }
      },
      "aggs": {
        "response_percentage": {
          "bucket_script": {
            "buckets_path": {
              "response":"response_percentage>response_code",
              "total":"response_percentage>without_response"
            },
            "script": "params.response/params.total*100"
          }
        }
      }
    }
  }
}

I am getting this Validation Error

{
  "error" : {
    "root_cause" : [
      {
        "type" : "action_request_validation_exception",
        "reason" : "Validation Failed: 1: Cyclical dependency found with pipeline aggregator [response_percentage];"
      }
    ],
    "type" : "action_request_validation_exception",
    "reason" : "Validation Failed: 1: Cyclical dependency found with pipeline aggregator [response_percentage];"
  },
  "status" : 400
}

Hi @Aniket_Pant

Look the same names:

    "response_percentage": {
      .....
      },
      "aggs": {
        "response_percentage": {
      .....
       }

Hi @RabBit_BR
I changed above response_percentage to response_agg

  "aggs": {
    "response_agg": {
      "filters": {
        "filters": {
          "response_code":
          {
            "bool": {
               "should": [
            {
              "match_phrase": {
                "ResponseCode": "005"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "008"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "081"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "091"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "096"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "900"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "009"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "0068"
              }
            },
            {
              "match_phrase": {
                "ResponseCode": "153"
              }
            }
          ]
            }
          },
          "without_response":
          {
              "bool": {
                "must": [
                  {
                    "match_all": {}
                  }
                ]
              }
          }
        }
      },
      "aggs": {
        "response_percentage": {
          "bucket_script": {
            "buckets_path": {
              "response":"response_agg>response_code",
              "total":"response_agg>without_response"
            },
            "script": "params.response/params.total*100"
          }
        }
      }
    }
  }
}

Error

{
  "error" : {
    "root_cause" : [
      {
        "type" : "action_request_validation_exception",
        "reason" : "Validation Failed: 1: No aggregation found for path [response_agg>response_code];"
      }
    ],
    "type" : "action_request_validation_exception",
    "reason" : "Validation Failed: 1: No aggregation found for path [response_agg>response_code];"
  },
  "status" : 400
}

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