# "nested" aggregation for parent/child relations?

**URL:** <https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598>\
**Category:** Elasticsearch\
**Created:** [May 19, 2014, 5:03pm UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598 "2014-05-19T17:03:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jad/32/1553_2.png) [@Jad](https://discuss.elastic.co/u/Jad)\
**Post date:** [May 19, 2014, 5:03pm UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598/1 "2014-05-19T17:03:07Z")

</div>

Hi,

Does anyone know if it is possible to do aggregations that are similar to  
the "nested" aggregation but for parent/child relationships? I have the  
following example:

parent doc:  
{  
"\_id": "123456",  
"name": "I am the parent"  
}

child1:  
{  
"\_parent": "123456",  
"country": "Germany"  
}

child2:  
{  
"\_parent": "123456",  
"language": "German"  
}

I would like to execute a terms aggregation by language and a terms  
sub-aggregation by country. Is that possible? I've done it with nested  
relationships instead of parent/child, but we update this data often, and  
nested relationships are harder to insert.

Many thanks!

Jad.

--  
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/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%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:** [May 20, 2014, 7:19am UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598/2 "2014-05-20T07:19:14Z")

</div>

Hi Jad,

This is a feature that we are considering but parent/child joins are  
typically much more expensive to do than nested (block) joins so we still  
need to figure out if we can expose such an aggregation with a reasonable  
cost.

On Mon, May 19, 2014 at 7:03 PM, Jad [jnaous@gmail.com](mailto:jnaous@gmail.com) wrote:

> Hi,
> 
> Does anyone know if it is possible to do aggregations that are similar to  
> the "nested" aggregation but for parent/child relationships? I have the  
> following example:
> 
> parent doc:  
> {  
> "\_id": "123456",  
> "name": "I am the parent"  
> }
> 
> child1:  
> {  
> "\_parent": "123456",  
> "country": "Germany"  
> }
> 
> child2:  
> {  
> "\_parent": "123456",  
> "language": "German"  
> }
> 
> I would like to execute a terms aggregation by language and a terms  
> sub-aggregation by country. Is that possible? I've done it with nested  
> relationships instead of parent/child, but we update this data often, and  
> nested relationships are harder to insert.
> 
> Many thanks!
> 
> Jad.
> 
> --  
> 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/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%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/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o\_ooT-4VwgV06Tg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o_ooT-4VwgV06Tg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jad/32/1553_2.png) [@Jad](https://discuss.elastic.co/u/Jad)\
**Post date:** [May 20, 2014, 2:04pm UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598/3 "2014-05-20T14:04:00Z")

</div>

Thanks, Adrien!  
On May 20, 2014 12:19 AM, "Adrien Grand" [adrien.grand@elasticsearch.com](mailto:adrien.grand@elasticsearch.com)  
wrote:

> Hi Jad,
> 
> This is a feature that we are considering but parent/child joins are  
> typically much more expensive to do than nested (block) joins so we still  
> need to figure out if we can expose such an aggregation with a reasonable  
> cost.
> 
> On Mon, May 19, 2014 at 7:03 PM, Jad [jnaous@gmail.com](mailto:jnaous@gmail.com) wrote:
> 
> > Hi,
> > 
> > Does anyone know if it is possible to do aggregations that are similar to  
> > the "nested" aggregation but for parent/child relationships? I have the  
> > following example:
> > 
> > parent doc:  
> > {  
> > "\_id": "123456",  
> > "name": "I am the parent"  
> > }
> > 
> > child1:  
> > {  
> > "\_parent": "123456",  
> > "country": "Germany"  
> > }
> > 
> > child2:  
> > {  
> > "\_parent": "123456",  
> > "language": "German"  
> > }
> > 
> > I would like to execute a terms aggregation by language and a terms  
> > sub-aggregation by country. Is that possible? I've done it with nested  
> > relationships instead of parent/child, but we update this data often, and  
> > nested relationships are harder to insert.
> > 
> > Many thanks!
> > 
> > Jad.
> > 
> > --  
> > 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/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/Ojd2ZyEMV3I/unsubscribe](https://groups.google.com/d/topic/elasticsearch/Ojd2ZyEMV3I/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o\_ooT-4VwgV06Tg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o_ooT-4VwgV06Tg%40mail.gmail.com)[https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o\_ooT-4VwgV06Tg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o_ooT-4VwgV06Tg%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAET%3DrD%3Dxr7epNSw8apkz4vm-Gk09rBm\_\_mOHj3v%2BvPDAk\_o2iQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAET%3DrD%3Dxr7epNSw8apkz4vm-Gk09rBm__mOHj3v%2BvPDAk_o2iQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Peter\_Pohar](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@Peter\_Pohar](https://discuss.elastic.co/u/Peter_Pohar)\
**Post date:** [January 6, 2015, 7:51am UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598/4 "2015-01-06T07:51:13Z")

</div>

Hey guys,

I'm interested in similar architecture. I have company -\> employee -\>  
availability structure. Any update on grandchild aggregation?  
While on 2nd level I get data, on 3rd level I'm always getting doc\_count 0.  
Or is this completely different issue?

Best,  
Pete

On Tuesday, 20 May 2014 16:04:00 UTC+2, Jad wrote:

> Thanks, Adrien!  
> On May 20, 2014 12:19 AM, "Adrien Grand" \<[adrien...@elasticsearch.com](mailto:adrien...@elasticsearch.com)  
> \<javascript:\>\> wrote:
> 
> > Hi Jad,
> > 
> > This is a feature that we are considering but parent/child joins are  
> > typically much more expensive to do than nested (block) joins so we still  
> > need to figure out if we can expose such an aggregation with a reasonable  
> > cost.
> > 
> > On Mon, May 19, 2014 at 7:03 PM, Jad \<[jna...@gmail.com](mailto:jna...@gmail.com) \<javascript:\>\>  
> > wrote:
> > 
> > > Hi,
> > > 
> > > Does anyone know if it is possible to do aggregations that are similar  
> > > to the "nested" aggregation but for parent/child relationships? I have the  
> > > following example:
> > > 
> > > parent doc:  
> > > {  
> > > "\_id": "123456",  
> > > "name": "I am the parent"  
> > > }
> > > 
> > > child1:  
> > > {  
> > > "\_parent": "123456",  
> > > "country": "Germany"  
> > > }
> > > 
> > > child2:  
> > > {  
> > > "\_parent": "123456",  
> > > "language": "German"  
> > > }
> > > 
> > > I would like to execute a terms aggregation by language and a terms  
> > > sub-aggregation by country. Is that possible? I've done it with nested  
> > > relationships instead of parent/child, but we update this data often, and  
> > > nested relationships are harder to insert.
> > > 
> > > Many thanks!
> > > 
> > > Jad.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/587022cc-cedd-48e9-b6ba-4cef8c996432%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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/Ojd2ZyEMV3I/unsubscribe](https://groups.google.com/d/topic/elasticsearch/Ojd2ZyEMV3I/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o\_ooT-4VwgV06Tg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o_ooT-4VwgV06Tg%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o\_ooT-4VwgV06Tg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7qcke7DbXwwDAE100pQ2AkA6796E5o_ooT-4VwgV06Tg%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/b4b71907-cf4b-4bc5-89a5-0f9cb8da03d0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b4b71907-cf4b-4bc5-89a5-0f9cb8da03d0%40googlegroups.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, 12:40am UTC](https://discuss.elastic.co/t/nested-aggregation-for-parent-child-relations/17598/5 "2017-07-06T00:40:35Z")

</div>


