# Pipeline aggs with more than one level depth

**URL:** https://discuss.elastic.co/t/pipeline-aggs-with-more-than-one-level-depth/282502
**Category:** Elasticsearch
**Created:** [August 25, 2021, 3:02pm UTC](https://discuss.elastic.co/t/pipeline-aggs-with-more-than-one-level-depth/282502 "2021-08-25T15:02:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![caraboy](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@caraboy](https://discuss.elastic.co/u/caraboy)
#### Post date: [August 25, 2021, 3:02pm UTC](https://discuss.elastic.co/t/pipeline-aggs-with-more-than-one-level-depth/282502/1 "2021-08-25T15:02:20Z")

</div>

Hi everyone,  
I'm trying to make an `avg_bucket` agg that goes more than one level deep like this

```auto
...
  "aggs": {
    "group_by_implementation_waiting": {
      "terms": {
        "field": "implementation.keyword",
        "size": 100000,
        "order": {
          "_key": "asc"
        }
      },
      "aggs": {
        "group_by_date": {
          "date_histogram": {
            "field": "emission_date",
            "fixed_interval": "1d",
            "min_doc_count": 1
          },
          "aggs": {
            "group_by_section": {
              "terms": {
                "field": "event.data.section.keyword",
                "size": 100000,
                "order": {
                  "_key": "asc"
                }
              },
              "aggs": {
                "group_by_identifier_waiting": {
                  "terms": {
                    "field": "identifier.keyword",
                    "size": 1000000
                  },
                  "aggs": {
                    "max_date": {
                      "max": {
                        "field": "event.date"
                      }
                    },
                    "min_date": {
                      "min": {
                        "field": "event.date"
                      }
                    },
                    "datediff": {
                      "bucket_script": {
                        "buckets_path": {
                          "start_date": "min_date",
                          "end_date": "max_date"
                        },
                        "script": "(params.end_date - params.start_date)/1000"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "implementation_waiting_avg": {
      "avg_bucket": {
        "buckets_path": "group_by_implementation_waiting>group_by_date>group_by_section>group_by_identifier_waiting>datediff"
      }
    }
  }
}

```

but i'm getting an `"buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Object[]] at aggregation [group_by_date]"` and I DO understand why this is happening, I've seen the issue ([here](https://discuss.elastic.co/t/pipeline-aggregations-with-buckets-path-more-than-two/69454) and [here](https://github.com/elastic/elasticsearch/issues/25273) for example) but I want't to know if there is an easier and less expensive way to solve it than creating a bucket for each agg level or there is a way of reference a more than one level depp bucket.  
Either way, why isn't my `buckets_path` possible? Is it not reasonable? It seems to me.  
Thank you all.

---

<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: [September 22, 2021, 3:02pm UTC](https://discuss.elastic.co/t/pipeline-aggs-with-more-than-one-level-depth/282502/2 "2021-09-22T15:02:51Z")

</div>

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