# Top\_children not returning results

**URL:** <https://discuss.elastic.co/t/top-children-not-returning-results/7328>\
**Category:** Elasticsearch\
**Created:** [April 14, 2012, 6:36am UTC](https://discuss.elastic.co/t/top-children-not-returning-results/7328 "2012-04-14T06:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slushi](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@slushi](https://discuss.elastic.co/u/slushi)\
**Post date:** [April 14, 2012, 6:36am UTC](https://discuss.elastic.co/t/top-children-not-returning-results/7328/1 "2012-04-14T06:36:59Z")

</div>

I am having an issue with the top\_children query sporadically not  
returning any results on 0.19.2. I have created a gist and linked it  
below. I tried debugging the code - I can't say I really understand  
what's going on but it looks like in QueryPhase.execute() the while  
loop executes twice due to a lack of results. After the first  
iteration, the parent doc is set in the context. Somehow during the  
second iteration, the result doc is actually the parent (I checked the  
doc id by using luke on the index) and the parentDocs map in the  
context map is empty because TopChildrenQuery.processResults recreates  
it on every call. Hopefully that makes sense and is helpful. 🙂

> <https://gist.github.com/kireet/2382459>

---

<div class="post-metadata">

**Author:** ![slushi](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@slushi](https://discuss.elastic.co/u/slushi)\
**Post date:** [April 17, 2012, 7:12pm UTC](https://discuss.elastic.co/t/top-children-not-returning-results/7328/2 "2012-04-17T19:12:02Z")

</div>

I went ahead and opened a new issue:

> <https://github.com/elastic/elasticsearch/issues/1870>
>
> I am facing an issue where a top\_children query is not returning results when th…e code must issue an incremental child query to try to get more results. I think this is clearly a bug b/c when I set the size such that the first query suffices, results are returned for the same query. I have created a gist to reproduce the problem, basically it just creates an index with a single parent doc and multiple child docs. Then it does 2 top\_children queries with identical queries but differing size, factor and incremental factor values. One returns results and the other doesn't. This is on 0.19.2
> 
> https://gist.github.com/2382459

On Saturday, April 14, 2012 2:36:59 AM UTC-4, slushi wrote:

> I am having an issue with the top\_children query sporadically not  
> returning any results on 0.19.2. I have created a gist and linked it  
> below. I tried debugging the code - I can't say I really understand  
> what's going on but it looks like in QueryPhase.execute() the while  
> loop executes twice due to a lack of results. After the first  
> iteration, the parent doc is set in the context. Somehow during the  
> second iteration, the result doc is actually the parent (I checked the  
> doc id by using luke on the index) and the parentDocs map in the  
> context map is empty because TopChildrenQuery.processResults recreates  
> it on every call. Hopefully that makes sense and is helpful. 🙂
> 
> [elastic search bug when running top\_children queries · GitHub](https://gist.github.com/2382459)

---

<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:32am UTC](https://discuss.elastic.co/t/top-children-not-returning-results/7328/3 "2017-07-06T03:32:09Z")

</div>


