# Percentile aggregation for nested aggregations

**URL:** <https://discuss.elastic.co/t/percentile-aggregation-for-nested-aggregations/79705>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 8:21am UTC](https://discuss.elastic.co/t/percentile-aggregation-for-nested-aggregations/79705 "2017-03-23T08:21:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdudits](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pdudits/32/101354_2.png) [@pdudits](https://discuss.elastic.co/u/pdudits)\
**Post date:** [March 23, 2017, 8:21am UTC](https://discuss.elastic.co/t/percentile-aggregation-for-nested-aggregations/79705/1 "2017-03-23T08:21:50Z")

</div>

Hello,

I'm trying to calculate percentile distribution of number of requests per user per hour. But it seems impossible to define a buckets\_path that would traverse into nested bucket aggregation.

The aggregation for the raw data looks like this:

```
{
  "size": 0,
  "query": { "bool": {
    "must": [
      { "exists": { "field": "remote_user" }}
      ]
    }
  },
  "aggs": {
    "users": {
      "terms" : {"field": "remote_user" },
      "aggs": {
        "time": {
          "date_histogram": {
            "field": "@timestamp",
            "interval": "1h",
            "time_zone": "Europe/Berlin",
            "min_doc_count": 0
          }
        }
      }
    }
  }
}

```

Since I do not care about particular user, the aggregation order could also be inverted. Nevertheless, There doesn't seem to be a way to build percentiles from the doc\_counts of the inner buckets. Other posts here suggest to build another pipeline aggregation on the inner level, and aggregate on that. However, percentiles are not associative, so they cannot be computed this way.

```
"reqs_per_hour": {
  "percentiles_bucket": {
    "buckets_path": "users>time"
  }
}

```

Results in

> buckets\_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram

---

<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:** [April 20, 2017, 8:22am UTC](https://discuss.elastic.co/t/percentile-aggregation-for-nested-aggregations/79705/2 "2017-04-20T08:22:03Z")

</div>

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