# Max Bucket Aggregation on subaggregation?

**URL:** https://discuss.elastic.co/t/max-bucket-aggregation-on-subaggregation/100130
**Category:** Elasticsearch
**Created:** [September 11, 2017, 8:22pm UTC](https://discuss.elastic.co/t/max-bucket-aggregation-on-subaggregation/100130 "2017-09-11T20:22:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AndreKR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrekr/32/6233_2.png) [@AndreKR](https://discuss.elastic.co/u/AndreKR)
#### Post date: [September 11, 2017, 8:22pm UTC](https://discuss.elastic.co/t/max-bucket-aggregation-on-subaggregation/100130/1 "2017-09-11T20:22:03Z")

</div>

Here I'm aggregating by tag and by time:

```
{
  "aggregations": {
    "tags": {
      "aggregations": {
        "volume": {
          "histogram": {
            "field": "timestamp",
            "interval": 7200000
          }
        }
      },
      "terms": {
        "field": "tag"
      }
    },
    "max_volume": {
      "max_bucket": {
        "buckets_path": "tags>volume>_count"
      }
    }
  }
}

```

Furthermore there is a pipeline aggregation with which I'm trying to get the highest `doc_count` that any single tag in any single interval has. However, I'm getting an error:

> buckets\_path must reference either a number value or a single value numeric metric aggregation, got: java.lang.Object

I found that I can get my desired number by having two pipeline aggregations:

```
{
  "aggregations": {
    "tags": {
      "aggregations": {
        "volume": {
          "histogram": {
            "field": "timestamp",
            "interval": 7200000
          }
        },
        "max_tag_volume": {
          "max_bucket": {
            "buckets_path": "volume>_count"
          }
        }
      },
      "terms": {
        "field": "tag"
      }
    },
    "max_volume": {
      "max_bucket": {
        "buckets_path": "tags>max_tag_volume"
      }
    }
  }
}

```

I that how it's supposed to work? I would have expected that it's called `buckets_path` because I can specify a path down the aggregation tree?

---

<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 9, 2017, 8:22pm UTC](https://discuss.elastic.co/t/max-bucket-aggregation-on-subaggregation/100130/2 "2017-10-09T20:22:29Z")

</div>

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