# Difference of Parent to Child Documents and a Nested Document

**URL:** <https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839>\
**Category:** Elasticsearch\
**Created:** [August 23, 2012, 10:18pm UTC](https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839 "2012-08-23T22:18:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [August 23, 2012, 10:18pm UTC](https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839/1 "2012-08-23T22:18:14Z")

</div>

I can understand the different between a multi-value field that contains  
many objects and a Nested Document.  
The main problem solvable by nested objects is "cross object" matching, see  
[http://www.elasticsearch.org/guide/reference/mapping/nested-type.html](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)

But why would I use a nested object vs. a parent object & one or more  
child objects?

For query that includes the child, I can use a has\_child query (or filter)  
[http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query.html)  
For a query that includes a nested document I can use a nested\_ query  
[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
Both result in 1 document for the parent and 1 for each child.

Is one of the primary differences between nested object and a  
child/parent is that  
A nested type is defined/changed/deleted by indexing a new parent  
while a child document can have a different lifecycle than its parent?

My application of parent/child would definitely be a case where the  
children come along at different times after the parent is created.

-Paul

--

---

<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:** [August 24, 2012, 6:36am UTC](https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839/2 "2012-08-24T06:36:39Z")

</div>

On Thu, 2012-08-23 at 15:19 -0700, P. Hill wrote:

> I can understand the different between a multi-value field that contains  
> many objects and a Nested Document.  
> The main problem solvable by nested objects is "cross object" matching, see  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)
> 
> But why would I use a nested object vs. a parent object & one or more  
> child objects?
> 
> For query that includes the child, I can use a has\_child query (or filter)  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query.html)  
> For a query that includes a nested document I can use a nested\_ query  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
> Both result in 1 document for the parent and 1 for each child.
> 
> Is one of the primary differences between nested object and a  
> child/parent is that  
> A nested type is defined/changed/deleted by indexing a new parent  
> while a child document can have a different lifecycle than its parent?

Correct

> My application of parent/child would definitely be a case where the  
> children come along at different times after the parent is created.

It's also a question of the number of children.

I'd guess (not sure) that nested docs probably perform better than  
parent-child docs, but if you could have thousands of children, you will  
probably do better with parent-child.

clint

> -Paul

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 24, 2012, 8:20am UTC](https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839/3 "2012-08-24T08:20:19Z")

</div>

Hi Paul,

With nested objects you basically need to know your parent child  
relation upfront. You can't add a nested object after the main  
document is added. This isn't the case with parent child objects. So  
based on your requirements I would suggest that parent child type  
object is the way to go.

Martijn

On 24 August 2012 08:36, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:

> On Thu, 2012-08-23 at 15:19 -0700, P. Hill wrote:
> 
> > I can understand the different between a multi-value field that contains  
> > many objects and a Nested Document.  
> > The main problem solvable by nested objects is "cross object" matching, see  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)
> > 
> > But why would I use a nested object vs. a parent object & one or more  
> > child objects?
> > 
> > For query that includes the child, I can use a has\_child query (or filter)  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query.html)  
> > For a query that includes a nested document I can use a nested\_ query  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
> > Both result in 1 document for the parent and 1 for each child.
> > 
> > Is one of the primary differences between nested object and a  
> > child/parent is that  
> > A nested type is defined/changed/deleted by indexing a new parent  
> > while a child document can have a different lifecycle than its parent?
> 
> Correct
> 
> > My application of parent/child would definitely be a case where the  
> > children come along at different times after the parent is created.
> 
> It's also a question of the number of children.
> 
> I'd guess (not sure) that nested docs probably perform better than  
> parent-child docs, but if you could have thousands of children, you will  
> probably do better with parent-child.
> 
> clint
> 
> > -Paul
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<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, 3:15am UTC](https://discuss.elastic.co/t/difference-of-parent-to-child-documents-and-a-nested-document/8839/4 "2017-07-06T03:15:13Z")

</div>


