# Query performance in parent/child approach

**URL:** https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325
**Category:** Elasticsearch
**Created:** [June 8, 2013, 8:08am UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325 "2013-06-08T08:08:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)
#### Post date: [June 8, 2013, 8:08am UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/1 "2013-06-08T08:08:39Z")

</div>

Hi All,

We are planning to index documents using parent/child appraoch.

I would like to know about the performance cost in case of parent/child  
query compare to normal query.

Thanks,  
Ankit

--  
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: ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)
#### Post date: [June 10, 2013, 5:22am UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/2 "2013-06-10T05:22:27Z")

</div>

Hi All,

any update ..

Thanks,  
Ankit

On Saturday, 8 June 2013 13:38:39 UTC+5:30, Ankit Jain wrote:

> Hi All,
> 
> We are planning to index documents using parent/child appraoch.
> 
> I would like to know about the performance cost in case of parent/child  
> query compare to normal query.
> 
> Thanks,  
> Ankit

--  
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: ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)
#### Post date: [June 11, 2013, 9:16pm UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/3 "2013-06-11T21:16:18Z")

</div>

Hi Ankit,

Performance wise, you'd probably get the best results out of "normal"  
queries. For "normal" queries you have to denormalize the data.  
Depending on the structure of your data, you're either going to lose some  
precision when you have multiple child objects per parent (in that case you  
need nested objects and nested queries).

In some cases nested or parent/child queries are a better fit for the  
problem, but that depends (on a lot of things). Nested queries would most  
likely also perform better than parent/child queries. Parent child queries  
also need more memory while the query is running, so if you're doing a lot  
of these queries, you might run into memory issues.

The exact performance cost would be very difficult to predict without  
further information. Could you provide more details of the structure of  
your data? That can tell us whether nested queries are needed.  
It's difficult to answer this question in a general case.

Jaap

On Monday, June 10, 2013 7:22:27 AM UTC+2, Ankit Jain wrote:

> Hi All,
> 
> any update ..
> 
> Thanks,  
> Ankit
> 
> On Saturday, 8 June 2013 13:38:39 UTC+5:30, Ankit Jain wrote:
> 
> > Hi All,
> > 
> > We are planning to index documents using parent/child appraoch.
> > 
> > I would like to know about the performance cost in case of parent/child  
> > query compare to normal query.
> > 
> > Thanks,  
> > Ankit

--  
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: ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)
#### Post date: [June 12, 2013, 8:07am UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/4 "2013-06-12T08:07:39Z")

</div>

Hi Jaap,

We have one child for each parent and also in our usecase, we have required  
to delete the child as well.

Thanks,  
Ankit

On Wednesday, 12 June 2013 02:46:18 UTC+5:30, Jaap Taal wrote:

> Hi Ankit,
> 
> Performance wise, you'd probably get the best results out of "normal"  
> queries. For "normal" queries you have to denormalize the data.  
> Depending on the structure of your data, you're either going to lose some  
> precision when you have multiple child objects per parent (in that case you  
> need nested objects and nested queries).
> 
> In some cases nested or parent/child queries are a better fit for the  
> problem, but that depends (on a lot of things). Nested queries would most  
> likely also perform better than parent/child queries. Parent child queries  
> also need more memory while the query is running, so if you're doing a lot  
> of these queries, you might run into memory issues.
> 
> The exact performance cost would be very difficult to predict without  
> further information. Could you provide more details of the structure of  
> your data? That can tell us whether nested queries are needed.  
> It's difficult to answer this question in a general case.
> 
> Jaap
> 
> On Monday, June 10, 2013 7:22:27 AM UTC+2, Ankit Jain wrote:
> 
> > Hi All,
> > 
> > any update ..
> > 
> > Thanks,  
> > Ankit
> > 
> > On Saturday, 8 June 2013 13:38:39 UTC+5:30, Ankit Jain wrote:
> > 
> > > Hi All,
> > > 
> > > We are planning to index documents using parent/child appraoch.
> > > 
> > > I would like to know about the performance cost in case of parent/child  
> > > query compare to normal query.
> > > 
> > > Thanks,  
> > > Ankit

--  
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: ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)
#### Post date: [June 12, 2013, 6:23pm UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/5 "2013-06-12T18:23:24Z")

</div>

I would denormalize and store both objects in 1 document. Parent child  
relations aren't for free.  
On Jun 12, 2013 10:07 AM, "Ankit Jain" [ankitjaincs06@gmail.com](mailto:ankitjaincs06@gmail.com) wrote:

> Hi Jaap,
> 
> We have one child for each parent and also in our usecase, we have  
> required to delete the child as well.
> 
> Thanks,  
> Ankit
> 
> On Wednesday, 12 June 2013 02:46:18 UTC+5:30, Jaap Taal wrote:
> 
> > Hi Ankit,
> > 
> > Performance wise, you'd probably get the best results out of "normal"  
> > queries. For "normal" queries you have to denormalize the data.  
> > Depending on the structure of your data, you're either going to lose some  
> > precision when you have multiple child objects per parent (in that case you  
> > need nested objects and nested queries).
> > 
> > In some cases nested or parent/child queries are a better fit for the  
> > problem, but that depends (on a lot of things). Nested queries would most  
> > likely also perform better than parent/child queries. Parent child queries  
> > also need more memory while the query is running, so if you're doing a lot  
> > of these queries, you might run into memory issues.
> > 
> > The exact performance cost would be very difficult to predict without  
> > further information. Could you provide more details of the structure of  
> > your data? That can tell us whether nested queries are needed.  
> > It's difficult to answer this question in a general case.
> > 
> > Jaap
> > 
> > On Monday, June 10, 2013 7:22:27 AM UTC+2, Ankit Jain wrote:
> > 
> > > Hi All,
> > > 
> > > any update ..
> > > 
> > > Thanks,  
> > > Ankit
> > > 
> > > On Saturday, 8 June 2013 13:38:39 UTC+5:30, Ankit Jain wrote:
> > > 
> > > > Hi All,
> > > > 
> > > > We are planning to index documents using parent/child appraoch.
> > > > 
> > > > I would like to know about the performance cost in case of parent/child  
> > > > query compare to normal query.
> > > > 
> > > > Thanks,  
> > > > Ankit
> > > > 
> > > > --  
> > > > 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/g-YoEBm04H8/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/g-YoEBm04H8/unsubscribe?hl=en-US)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, 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: ![bhupiss](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bhupiss](https://discuss.elastic.co/u/bhupiss)
#### Post date: [August 1, 2013, 4:14pm UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/6 "2013-08-01T16:14:27Z")

</div>

I am curious how would you denormailze a parent child relationship when the number of children elements are not fixed. For example, one user can have multiple orders. How would you represent such a relationship in json document.?

---

<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, 2:23am UTC](https://discuss.elastic.co/t/query-performance-in-parent-child-approach/12325/7 "2017-07-06T02:23:20Z")

</div>


