# What is the recommended way to retrieve documents in a parent child relationship

**URL:** https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263
**Category:** Elasticsearch
**Created:** [November 5, 2013, 12:01pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263 "2013-11-05T12:01:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ron\_Sher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ron_sher/32/4472_2.png) [@Ron\_Sher](https://discuss.elastic.co/u/Ron_Sher)
#### Post date: [November 5, 2013, 12:01pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263/1 "2013-11-05T12:01:40Z")

</div>

Hi,

Let's say I have 2 types - Parent & Child with a parent / child  
relationship.

I want to get data that is similar to nested documents, i.e. for each  
document I get from the parent I want to get all of its children as well.

What I thought of doing is to first query for the documents in the parent,  
get all their IDs and then query from the child documents all those that  
are children of the requested parents.  
I maintain a parent field in the child document and query for children  
whose parent field is any of the parents I got.

Hope I've made myself clear.

Is there a better way to achieve that?

Thanks  
Ron

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 5, 2013, 12:48pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263/2 "2013-11-05T12:48:20Z")

</div>

Not really answer but my thoughts.

First, parent/child in elasticsearch is built for that need. I don't see why you need to build something else yourself.

Then, the main question is to me: "do I REALLY need relation between documents in a NoSQL world?"  
It depends on your needs but I have often seen people trying to implement a Document oriented NoSQL solution with the same approach as relationnal database. So, before taking that decision, check that you really need it.

(Not saying that it's not a real need in your case).

My 2 cents.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 nov. 2013 à 13:01, Ron Sher [ron.sher@gmail.com](mailto:ron.sher@gmail.com) a écrit :

> Hi,
> 
> Let's say I have 2 types - Parent & Child with a parent / child relationship.
> 
> I want to get data that is similar to nested documents, i.e. for each document I get from the parent I want to get all of its children as well.
> 
> What I thought of doing is to first query for the documents in the parent, get all their IDs and then query from the child documents all those that are children of the requested parents.  
> I maintain a parent field in the child document and query for children whose parent field is any of the parents I got.
> 
> Hope I've made myself clear.
> 
> Is there a better way to achieve that?
> 
> ## Thanks Ron
> 
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ron\_Sher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ron_sher/32/4472_2.png) [@Ron\_Sher](https://discuss.elastic.co/u/Ron_Sher)
#### Post date: [November 5, 2013, 1:14pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263/3 "2013-11-05T13:14:32Z")

</div>

Thanks for your feedback.  
I can't really reveal the business case here, but assume that I do need it.  
We also thought about using nested documents (which answer the query need),  
but didn't use it since the child is updated in a much higher rate than the  
parent and we didn't want to update the parent each time.

On Tuesday, November 5, 2013 2:48:20 PM UTC+2, David Pilato wrote:

> Not really answer but my thoughts.
> 
> First, parent/child in elasticsearch is built for that need. I don't see  
> why you need to build something else yourself.
> 
> Then, the main question is to me: "do I REALLY need relation between  
> documents in a NoSQL world?"  
> It depends on your needs but I have often seen people trying to implement  
> a Document oriented NoSQL solution with the same approach as relationnal  
> database. So, before taking that decision, check that you really need it.
> 
> (Not saying that it's not a real need in your case).
> 
> My 2 cents.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 5 nov. 2013 à 13:01, Ron Sher \<[ron....@gmail.com](mailto:ron....@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi,
> 
> Let's say I have 2 types - Parent & Child with a parent / child  
> relationship.
> 
> I want to get data that is similar to nested documents, i.e. for each  
> document I get from the parent I want to get all of its children as well.
> 
> What I thought of doing is to first query for the documents in the parent,  
> get all their IDs and then query from the child documents all those that  
> are children of the requested parents.  
> I maintain a parent field in the child document and query for children  
> whose parent field is any of the parents I got.
> 
> Hope I've made myself clear.
> 
> Is there a better way to achieve that?
> 
> Thanks  
> Ron
> 
> --  
> 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:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![cmk1523](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cmk1523/32/6474_2.png) [@cmk1523](https://discuss.elastic.co/u/cmk1523)
#### Post date: [February 18, 2016, 2:54pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263/4 "2016-02-18T14:54:13Z")

</div>

I would like to know the answer as well.

I'm in the same boat. Nested document ingest was too slow and now we're using parent/child. I currently get all the parent IDs and then do a multi-search request for all the children for each of those parent IDs.

---

<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 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/what-is-the-recommended-way-to-retrieve-documents-in-a-parent-child-relationship/14263/5 "2017-07-05T23:15:14Z")

</div>


