# Choosing Parent/Child vs Nested Document

**URL:** <https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742>\
**Category:** Elasticsearch\
**Created:** [February 18, 2012, 8:31am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742 "2012-02-18T08:31:43Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathis/32/2989_2.png) [@sathis](https://discuss.elastic.co/u/sathis)\
**Post date:** [February 18, 2012, 8:31am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/1 "2012-02-18T08:31:43Z")

</div>

I searched through this forum and ES wiki but wasn't able to find  
proper details.So i'm posting here. I will list some scenarios for  
choosing Parent/Child over Nested Document model and vice versa. Feel  
free to add new points or correct the existing ones.

Nested Document :

```
      1. If you need better performance.In nested documents always

```

parent, child will reside in the same shard i.e nearby physical  
locations.  
2. If you want to get both child documents and parent in a  
single query (I'm not sure whether it is supported by Parent/Child).

Parent / Child :

```
      1. If you want to avoid data duplication. For many-to-many

```

relationships you have to embed same sub-documents if you use Nested  
documents model. This can be avoided using parent/child relationship.

Thanks & Regards  
Sathis

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 20, 2012, 12:58pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/2 "2012-02-20T12:58:04Z")

</div>

Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.

On Saturday, February 18, 2012 at 10:31 AM, sathis wrote:

> I searched through this forum and ES wiki but wasn't able to find  
> proper details.So i'm posting here. I will list some scenarios for  
> choosing Parent/Child over Nested Document model and vice versa. Feel  
> free to add new points or correct the existing ones.
> 
> Nested Document :
> 
> 1. If you need better performance.In nested documents always  
> parent, child will reside in the same shard i.e nearby physical  
> locations.
> 2. If you want to get both child documents and parent in a  
> single query (I'm not sure whether it is supported by Parent/Child).
> 
> Parent / Child :
> 
> 1. If you want to avoid data duplication. For many-to-many  
> relationships you have to embed same sub-documents if you use Nested  
> documents model. This can be avoided using parent/child relationship.
> 
> Thanks & Regards  
> Sathis

---

<div class="post-metadata">

**Author:** ![sathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathis/32/2989_2.png) [@sathis](https://discuss.elastic.co/u/sathis)\
**Post date:** [February 20, 2012, 4:49pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/3 "2012-02-20T16:49:52Z")

</div>

Thanks Shay for clarifying this.You are doing a wonderful job to open  
source community. If you tag some issues as junior job, it will help  
new developers like me to get involved.

On Feb 20, 5:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.
> 
> On Saturday, February 18, 2012 at 10:31 AM, sathis wrote:
> 
> > I searched through this forum and ES wiki but wasn't able to find  
> > proper details.So i'm posting here. I will list some scenarios for  
> > choosing Parent/Child over Nested Document model and vice versa. Feel  
> > free to add new points or correct the existing ones.
> 
> > Nested Document :
> 
> > 1. If you need better performance.In nested documents always  
> > parent, child will reside in the same shard i.e nearby physical  
> > locations.
> > 2. If you want to get both child documents and parent in a  
> > single query (I'm not sure whether it is supported by Parent/Child).
> 
> > Parent / Child :
> 
> > 1. If you want to avoid data duplication. For many-to-many  
> > relationships you have to embed same sub-documents if you use Nested  
> > documents model. This can be avoided using parent/child relationship.
> 
> > Thanks & Regards  
> > Sathis

---

<div class="post-metadata">

**Author:** ![karmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karmi/32/44951_2.png) [@karmi](https://discuss.elastic.co/u/karmi)\
**Post date:** [February 28, 2012, 10:37am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/4 "2012-02-28T10:37:19Z")

</div>

Shay, do I understand correctly, that the update API [http://  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)] enables to  
append "nested" documents to the "main" document, such as adding a tag  
or comment to an article, without requiring to send the full document  
over the wire? (And also without potential conflicts with concurrent  
updates?)

Karel

On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.

---

<div class="post-metadata">

**Author:** ![haarts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/haarts/32/2972_2.png) [@haarts](https://discuss.elastic.co/u/haarts)\
**Post date:** [February 28, 2012, 11:18am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/5 "2012-02-28T11:18:54Z")

</div>

I'm not Shay (not by a long shot) but I do know the answer to that one!  
Your assumption is correct. An update allows you to append stuff to the  
document without sending it over the wire entirely. It also handles  
conflicts (see retry\_on\_conflict argument). But the entire document _is_  
reindexed which can be rather expensive. Adding tags probably wouldn't be a  
problem. Added (hundreds of) comments to a blog post is a problem.

Harm

On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:

> Shay, do I understand correctly, that the update API [http://  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)] enables to  
> append "nested" documents to the "main" document, such as adding a tag  
> or comment to an article, without requiring to send the full document  
> over the wire? (And also without potential conflicts with concurrent  
> updates?)
> 
> Karel
> 
> On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Both parent/child or nested documents will have the relevant data reside  
> > in the same shard. The main difference is that nested are faster compared  
> > to parent/child, but, nested docs require reindexing the parent with all  
> > its children, while parent child allows to reindex / add / delete specific  
> > children.

On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:

> Shay, do I understand correctly, that the update API [http://  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)] enables to  
> append "nested" documents to the "main" document, such as adding a tag  
> or comment to an article, without requiring to send the full document  
> over the wire? (And also without potential conflicts with concurrent  
> updates?)
> 
> Karel
> 
> On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Both parent/child or nested documents will have the relevant data reside  
> > in the same shard. The main difference is that nested are faster compared  
> > to parent/child, but, nested docs require reindexing the parent with all  
> > its children, while parent child allows to reindex / add / delete specific  
> > children.

On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:

> Shay, do I understand correctly, that the update API [http://  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)] enables to  
> append "nested" documents to the "main" document, such as adding a tag  
> or comment to an article, without requiring to send the full document  
> over the wire? (And also without potential conflicts with concurrent  
> updates?)
> 
> Karel
> 
> On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Both parent/child or nested documents will have the relevant data reside  
> > in the same shard. The main difference is that nested are faster compared  
> > to parent/child, but, nested docs require reindexing the parent with all  
> > its children, while parent child allows to reindex / add / delete specific  
> > children.

On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:

> Shay, do I understand correctly, that the update API [http://  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html)] enables to  
> append "nested" documents to the "main" document, such as adding a tag  
> or comment to an article, without requiring to send the full document  
> over the wire? (And also without potential conflicts with concurrent  
> updates?)
> 
> Karel
> 
> On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Both parent/child or nested documents will have the relevant data reside  
> > in the same shard. The main difference is that nested are faster compared  
> > to parent/child, but, nested docs require reindexing the parent with all  
> > its children, while parent child allows to reindex / add / delete specific  
> > children.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 29, 2012, 1:55pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/6 "2012-02-29T13:55:38Z")

</div>

++Harm

On Tuesday, February 28, 2012 at 1:18 PM, haarts wrote:

> I'm not Shay (not by a long shot) but I do know the answer to that one!  
> Your assumption is correct. An update allows you to append stuff to the document without sending it over the wire entirely. It also handles conflicts (see retry\_on\_conflict argument). But the entire document _is_ reindexed which can be rather expensive. Adding tags probably wouldn't be a problem. Added (hundreds of) comments to a blog post is a problem.
> 
> Harm
> 
> On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:
> 
> > Shay, do I understand correctly, that the update API [http://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html) ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html))] enables to  
> > append "nested" documents to the "main" document, such as adding a tag  
> > or comment to an article, without requiring to send the full document  
> > over the wire? (And also without potential conflicts with concurrent  
> > updates?)
> > 
> > Karel
> > 
> > On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.
> 
> On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:
> 
> > Shay, do I understand correctly, that the update API [http://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html) ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html))] enables to  
> > append "nested" documents to the "main" document, such as adding a tag  
> > or comment to an article, without requiring to send the full document  
> > over the wire? (And also without potential conflicts with concurrent  
> > updates?)
> > 
> > Karel
> > 
> > On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.
> 
> On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:
> 
> > Shay, do I understand correctly, that the update API [http://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html) ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html))] enables to  
> > append "nested" documents to the "main" document, such as adding a tag  
> > or comment to an article, without requiring to send the full document  
> > over the wire? (And also without potential conflicts with concurrent  
> > updates?)
> > 
> > Karel
> > 
> > On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.
> 
> On Tuesday, 28 February 2012 11:37:19 UTC+1, Karel Minařík wrote:
> 
> > Shay, do I understand correctly, that the update API [http://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html) ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/update.html))] enables to  
> > append "nested" documents to the "main" document, such as adding a tag  
> > or comment to an article, without requiring to send the full document  
> > over the wire? (And also without potential conflicts with concurrent  
> > updates?)
> > 
> > Karel
> > 
> > On Feb 20, 1:58 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Both parent/child or nested documents will have the relevant data reside in the same shard. The main difference is that nested are faster compared to parent/child, but, nested docs require reindexing the parent with all its children, while parent child allows to reindex / add / delete specific children.

---

<div class="post-metadata">

**Author:** ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)\
**Post date:** [January 18, 2013, 12:28pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/7 "2013-01-18T12:28:45Z")

</div>

I'm curious as to why nested is faster compared to parent/child since my  
understanding is that nested is implemented similarly to parent/child. That  
is, they both store nested/children documents independently. Any insight  
would be greatly appreciated.

On Monday, 20 February 2012 07:58:04 UTC-5, kimchy wrote:

> Both parent/child or nested documents will have the relevant data reside  
> in the same shard. The main difference is that nested are faster compared  
> to parent/child, but, nested docs require reindexing the parent with all  
> its children, while parent child allows to reindex / add / delete specific  
> children.
> 
> On Saturday, February 18, 2012 at 10:31 AM, sathis wrote:
> 
> I searched through this forum and ES wiki but wasn't able to find  
> proper details.So i'm posting here. I will list some scenarios for  
> choosing Parent/Child over Nested Document model and vice versa. Feel  
> free to add new points or correct the existing ones.
> 
> Nested Document :
> 
> 1. If you need better performance.In nested documents always  
> parent, child will reside in the same shard i.e nearby physical  
> locations.
> 2. If you want to get both child documents and parent in a  
> single query (I'm not sure whether it is supported by Parent/Child).
> 
> Parent / Child :
> 
> 1. If you want to avoid data duplication. For many-to-many  
> relationships you have to embed same sub-documents if you use Nested  
> documents model. This can be avoided using parent/child relationship.
> 
> Thanks & Regards  
> Sathis

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 18, 2013, 12:42pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/8 "2013-01-18T12:42:57Z")

</div>

On Fri, 2013-01-18 at 04:28 -0800, btiernay wrote:

> I'm curious as to why nested is faster compared to parent/child since  
> my understanding is that nested is implemented similarly to  
> parent/child. That is, they both store nested/children documents  
> independently. Any insight would be greatly appreciated.

Parents and children are top-level completely separate docs which are  
stored on the same shard.

Nested docs are independent docs, but not visible on the top level. As I  
understand it, the root doc and its nested docs are written in an  
efficient format (block indexing) which improves performance.

clint

--

---

<div class="post-metadata">

**Author:** ![Jayant\_Kerai](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@Jayant\_Kerai](https://discuss.elastic.co/u/Jayant_Kerai)\
**Post date:** [January 31, 2013, 10:25am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/9 "2013-01-31T10:25:28Z")

</div>

I have a related question.

I want to index files (using something like Tika) but I also have a DB  
holding custom meta data against each file (like the owner, tags, etc).  
I would want to do a partial update to the meta data but don't want ES to  
do a full re-index of the content.

If I have a parent document that holds all the DB meta data and have a  
child document which holds the content from Tika, then I want to do a  
partial update on the parent (i.e. add some new tags), am I right to assume  
that the content document (the child) will not change or be re-indexed  
under the hood when using parent/child setup?

I know that using nested documents would require an re-index of everything.

On Friday, 18 January 2013 12:42:57 UTC, Clinton Gormley wrote:

> On Fri, 2013-01-18 at 04:28 -0800, btiernay wrote:
> 
> > I'm curious as to why nested is faster compared to parent/child since  
> > my understanding is that nested is implemented similarly to  
> > parent/child. That is, they both store nested/children documents  
> > independently. Any insight would be greatly appreciated.
> 
> Parents and children are top-level completely separate docs which are  
> stored on the same shard.
> 
> Nested docs are independent docs, but not visible on the top level. As I  
> understand it, the root doc and its nested docs are written in an  
> efficient format (block indexing) which improves performance.
> 
> clint

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 31, 2013, 10:34am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/10 "2013-01-31T10:34:41Z")

</div>

> If I have a parent document that holds all the DB meta data and have a  
> child document which holds the content from Tika, then I want to do a  
> partial update on the parent (i.e. add some new tags), am I right to  
> assume that the content document (the child) will not change or be  
> re-indexed under the hood when using parent/child setup?

Correct. The parent and child docs are completely separate.

clint

--  
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:** ![Jayant\_Kerai](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@Jayant\_Kerai](https://discuss.elastic.co/u/Jayant_Kerai)\
**Post date:** [January 31, 2013, 10:54am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/11 "2013-01-31T10:54:49Z")

</div>

Excellent. Thanks Clint.

On Thursday, 31 January 2013 10:34:41 UTC, Clinton Gormley wrote:

> > If I have a parent document that holds all the DB meta data and have a  
> > child document which holds the content from Tika, then I want to do a  
> > partial update on the parent (i.e. add some new tags), am I right to  
> > assume that the content document (the child) will not change or be  
> > re-indexed under the hood when using parent/child setup?
> 
> Correct. The parent and child docs are completely separate.
> 
> clint

--  
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:** ![amjayee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amjayee/32/76367_2.png) [@amjayee](https://discuss.elastic.co/u/amjayee)\
**Post date:** [May 5, 2017, 9:02am UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/12 "2017-05-05T09:02:55Z")

</div>

> [@btiernay](#):
>
> similarly to parent/child

Nested is faster than Parent -Child because internally nested documents are stored in the same Lucene block and hence the data is available locally but in case of Parent-Child the data is in the same Shard but not necessarily in the same Lucene block

---

<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, 10:00pm UTC](https://discuss.elastic.co/t/choosing-parent-child-vs-nested-document/6742/13 "2017-07-05T22:00:33Z")

</div>


