# Dividing buckets values

**URL:** <https://discuss.elastic.co/t/dividing-buckets-values/314938>\
**Category:** Elasticsearch\
**Created:** [September 22, 2022, 11:46am UTC](https://discuss.elastic.co/t/dividing-buckets-values/314938 "2022-09-22T11:46:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [September 22, 2022, 11:46am UTC](https://discuss.elastic.co/t/dividing-buckets-values/314938/1 "2022-09-22T11:46:32Z")

</div>

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.

```auto
{
  "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**

```auto
{
  "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
}

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [September 22, 2022, 1:49pm UTC](https://discuss.elastic.co/t/dividing-buckets-values/314938/2 "2022-09-22T13:49:55Z")

</div>

Hi @Aniket_Pant

Look the same names:

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

```

---

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [September 22, 2022, 3:13pm UTC](https://discuss.elastic.co/t/dividing-buckets-values/314938/3 "2022-09-22T15:13:33Z")

</div>

Hi @RabBit_BR  
I changed above `response_percentage` to `response_agg`

```auto
  "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

```auto
{
  "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
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 20, 2022, 3:14pm UTC](https://discuss.elastic.co/t/dividing-buckets-values/314938/4 "2022-10-20T15:14:20Z")

</div>

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