# Slow parent/child relationship queries

**URL:** <https://discuss.elastic.co/t/slow-parent-child-relationship-queries/15921>\
**Category:** Elasticsearch\
**Created:** [February 20, 2014, 10:56am UTC](https://discuss.elastic.co/t/slow-parent-child-relationship-queries/15921 "2014-02-20T10:56:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karol\_Gwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karol_gwaj/32/1324_2.png) [@Karol\_Gwaj](https://discuss.elastic.co/u/Karol_Gwaj)\
**Post date:** [February 20, 2014, 10:56am UTC](https://discuss.elastic.co/t/slow-parent-child-relationship-queries/15921/1 "2014-02-20T10:56:03Z")

</div>

any idea why query below is executing in around 5s:

POST //\_search  
{  
"query": {  
"has\_child": {  
"type": "",  
"query": {  
"has\_child": {  
"type": "\<CHILD\_SCORE\>",  
"query": {  
"range": {  
"score": {  
"gt" : 0  
}  
}  
}  
}  
}  
}  
}  
}

it is very simplified version of my production query, but it highlights the  
issue

context of my query:

- 6 node cluster
- index with 12 shards and 2 replicas
- 8m of parent documents
- 13m of child documents
- 13m of child\_score documents
- child and child\_score documents are related 1-1
- every parent can have up to 6 children
- 30GB heap size (20% used by id\_cache)

looks like every level of parent/child relationship is making the query run  
slower by the factor of 10  
(changing it to use filters instead of queries is not changing execution  
time significantly)

i tried to use top\_children query, but it is not really fitting my purpose  
(for my production query) as the final score of the query is computed on  
every level of parent child relationship

any suggestions what im doing wrong here (besides using parent/child  
relationships) ?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c9409f96-e6b1-4f11-b6ea-2afd9d5819ac%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c9409f96-e6b1-4f11-b6ea-2afd9d5819ac%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:48am UTC](https://discuss.elastic.co/t/slow-parent-child-relationship-queries/15921/2 "2017-07-06T01:48:47Z")

</div>


