# Parent-child query speed

**URL:** <https://discuss.elastic.co/t/parent-child-query-speed/38207>\
**Category:** Elasticsearch\
**Created:** [December 31, 2015, 5:07am UTC](https://discuss.elastic.co/t/parent-child-query-speed/38207 "2015-12-31T05:07:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamilk](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@kamilk](https://discuss.elastic.co/u/kamilk)\
**Post date:** [December 31, 2015, 5:07am UTC](https://discuss.elastic.co/t/parent-child-query-speed/38207/1 "2015-12-31T05:07:47Z")

</div>

Hi,

I've got sme problems with Elasticsearch has\_child query speed. I know that many people report that it is slow, but for me the query to retrieve parents is more than 80 times slower than the same query on children. Moreover it got 2 times slower when I reindexed the data using Elasticsearch 2.1 (compared to 1.7).

There is around 37M child documents, and 32M parent documents in the index. On both of them the custom function\_score is used to compute the results. The typical use case is to create quite complicated query using nested documents on children then to wrap it in has\_child query, and then use maximal score of children to compute the score of returned parents.

The average time of has\_child query was around 600ms with Elasticsearch 1.7, and is around 1200ms with Elasticsearch 2.1 on the machine with 30GB of ram (ES has 16GB of heap).

Is there anything I can do to improve those speeds or should I just resign from using parent-child relationships? The slowdown stated in documentation (5-10x) would be just fine.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 2, 2016, 6:00am UTC](https://discuss.elastic.co/t/parent-child-query-speed/38207/2 "2016-01-02T06:00:24Z")

</div>

As you seem to have very few child child documents per parent, I would try flattening the structure through denormalisation and see how it performs without using parent-child relationships.

---

<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:27pm UTC](https://discuss.elastic.co/t/parent-child-query-speed/38207/3 "2017-07-05T23:27:30Z")

</div>


