# Access child aggregations from parent

**URL:** <https://discuss.elastic.co/t/access-child-aggregations-from-parent/319607>\
**Category:** Elasticsearch\
**Created:** [November 23, 2022, 3:04am UTC](https://discuss.elastic.co/t/access-child-aggregations-from-parent/319607 "2022-11-23T03:04:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HasiAmarasena](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hasiamarasena/32/113668_2.png) [@HasiAmarasena](https://discuss.elastic.co/u/HasiAmarasena)\
**Post date:** [November 23, 2022, 3:04am UTC](https://discuss.elastic.co/t/access-child-aggregations-from-parent/319607/1 "2022-11-23T03:04:01Z")

</div>

I have below search

```auto
POST /MY_ID/_search?typed_keys=true
{
  "aggs": {
    
    "terms_agg": {
      "terms": {
        "field": "[RefNumber]"
      },
      "aggs": {
        "max_agg_startdate": {
          "max": {
            "field": "StartDate"
          }
        },
        "max_agg_enddate": {
          "max": {
            "field": "Enddate"
          }
        }
      }
    }
  },
...
...

```

I want to accesss buckets returned from Max aggregations max\_agg\_startdate & max\_agg\_enddate in upper level. Requirement is get the average difference between max\_agg\_startdate and max\_agg\_enddate. Lets say this calculation performs just above the "terms\_agg", how do I get access to max\_agg\_startdate & max\_agg\_enddate from that level?

Thanks

---

<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:** [December 21, 2022, 3:04am UTC](https://discuss.elastic.co/t/access-child-aggregations-from-parent/319607/2 "2022-12-21T03:04:03Z")

</div>

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