# Using parent aggregation key in subaggregation

**URL:** <https://discuss.elastic.co/t/using-parent-aggregation-key-in-subaggregation/17153>\
**Category:** Elasticsearch\
**Created:** [April 23, 2014, 5:00pm UTC](https://discuss.elastic.co/t/using-parent-aggregation-key-in-subaggregation/17153 "2014-04-23T17:00:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rabin\_Acharya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabin_acharya/32/1624_2.png) [@Rabin\_Acharya](https://discuss.elastic.co/u/Rabin_Acharya)\
**Post date:** [April 23, 2014, 5:00pm UTC](https://discuss.elastic.co/t/using-parent-aggregation-key-in-subaggregation/17153/1 "2014-04-23T17:00:27Z")

</div>

I want to know if I can access parent key in subaggregation, as

{

> ```
> "size": 0, 
> "aggs":{
> "*agg1*":{
> "terms":{
> "field":"memberId"
> },
> "aggs":{
> "11":{
> "terms":{
> "field":"*agg1*._value"
>                        
> }
> }
> }
> }
> }
> 
> ```
> 
> }

The above script dont seems to be working, I want to know if any script  
exists..

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 24, 2014, 8:45pm UTC](https://discuss.elastic.co/t/using-parent-aggregation-key-in-subaggregation/17153/2 "2014-04-24T20:45:17Z")

</div>

Unfortunately, it is not possible. Aggregations can only aggregate values  
that are contained in your documents. The reason is that aggregations are  
computed on the fly, so the results of `agg1` are still partial while  
results of `11` are being built. The only exception to this rule is  
sorting: you can sort the buckets of an aggregation according to the value  
of a sub-aggregation[1]. It is possible because the sorting phase happens  
after all buckets have bee computed.

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wed, Apr 23, 2014 at 7:00 PM, Rabin Acharya [rbnacharya@gmail.com](mailto:rbnacharya@gmail.com) wrote:

> I want to know if I can access parent key in subaggregation, as
> 
> {
> 
> > ```
> > "size": 0,
> > "aggs":{
> > "*agg1*":{
> > "terms":{
> > "field":"memberId"
> > },
> > "aggs":{
> > "11":{
> > "terms":{
> > "field":"*agg1*._value"
> > 
> > }
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > }
> 
> The above script dont seems to be working, I want to know if any script  
> exists..
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb7eb444-55d7-4a1c-bbef-4834609c03a1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7\_7DxdhagKdxZh%3DBLXQv4C%2BY3ZQS2aQLp0ROK-7fxWAg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7_7DxdhagKdxZh%3DBLXQv4C%2BY3ZQS2aQLp0ROK-7fxWAg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:33am UTC](https://discuss.elastic.co/t/using-parent-aggregation-key-in-subaggregation/17153/3 "2017-07-06T01:33:40Z")

</div>


