# Top\_children with custom score

**URL:** https://discuss.elastic.co/t/top-children-with-custom-score/8399
**Category:** Elasticsearch
**Created:** [July 12, 2012, 3:10pm UTC](https://discuss.elastic.co/t/top-children-with-custom-score/8399 "2012-07-12T15:10:15Z")
**Posts on this page:** 4
**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: [July 12, 2012, 3:10pm UTC](https://discuss.elastic.co/t/top-children-with-custom-score/8399/1 "2012-07-12T15:10:15Z")

</div>

I had a top\_children query with a custom score subquery that was working  
fine in 19.4 but has broken when I upgraded to .8.

Here is the gist:

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

It seems like it's trying to find the child field in the parent's mapping  
instead of the child mapping? The error (cm is child mapping, pm is parent  
mapping):  
{  
"error" : "SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], total failure; shardFailures  
{[N2r-dwPcTVq1Ujf0cE2\_gQ][tcbug][0]:  
QueryPhaseExecutionException[[tcbug][0]:  
query[filtered(score\_child[cm/pm](filtered(custom score  
(cid:c1,function=script[doc['cval'].value], params  
[null]))-\>cache(\_type:cm)))-\>cache(\_type:pm)],from[0],size[2]: Query Failed  
[Failed to execute child query [score\_child[cm/pm](filtered(custom score  
(cid:c1,function=script[doc['cval'].value], params  
[null]))-\>cache(\_type:cm))]]]; nested: CompileException[[Error: No field  
found for [cval] in mapping with types [pm]]\n[Near : {...  
doc['cval'].value ....}]\n ^\n[Line: 1, Column: 1]]; nested:  
ElasticSearchIllegalArgumentException[No field found for [cval] in mapping  
with types [_pm_]]; }]",  
"status" : 500  
}

I already upgraded, is it possible to safely downgrade to 0.19.4 using the  
same index files or do I have to rebuild?

---

<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: [July 18, 2012, 9:52am UTC](https://discuss.elastic.co/t/top-children-with-custom-score/8399/2 "2012-07-18T09:52:10Z")

</div>

Hi Slushi,

The reason that the error occurs, is that in the last curl command in  
your bash script  
([http://localhost:9200/tcbug/pm/\_search?fields=\*&pretty=true](http://localhost:9200/tcbug/pm/_search?fields=*&pretty=true) ...) is  
targeted to the pm index only. If you target your request to both  
types the error doesn't occur:  
[http://localhost:9200/tcbug/pm,cm/\_search?fields=\*&pretty=true](http://localhost:9200/tcbug/pm,cm/_search?fields=*&pretty=true)

This isn't caused by the top children query, but by a recent change  
([better type based inference when using scripts · elastic/elasticsearch@efe85f3 · GitHub](https://github.com/elasticsearch/elasticsearch/commit/efe85f322a073313d35f7261bfbe04baa3235de1))  
to scripting. Because of this change only field values can be resolved  
that are mapped in the requested types.

Martijn

On 12 July 2012 17:10, slushi [kireetreddy@gmail.com](mailto:kireetreddy@gmail.com) wrote:

> I had a top\_children query with a custom score subquery that was working  
> fine in 19.4 but has broken when I upgraded to .8.
> 
> Here is the gist:  
> [top children scoring bug · GitHub](https://gist.github.com/3098693)
> 
> It seems like it's trying to find the child field in the parent's mapping  
> instead of the child mapping? The error (cm is child mapping, pm is parent  
> mapping):  
> {  
> "error" : "SearchPhaseExecutionException[Failed to execute phase  
> [query\_fetch], total failure; shardFailures  
> {[N2r-dwPcTVq1Ujf0cE2\_gQ][tcbug][0]:  
> QueryPhaseExecutionException[[tcbug][0]:  
> query[filtered(score\_child[cm/pm](filtered(custom score  
> (cid:c1,function=script[doc['cval'].value], params  
> [null]))-\>cache(\_type:cm)))-\>cache(\_type:pm)],from[0],size[2]: Query Failed  
> [Failed to execute child query [score\_child[cm/pm](filtered(custom score  
> (cid:c1,function=script[doc['cval'].value], params  
> [null]))-\>cache(\_type:cm))]]]; nested: CompileException[[Error: No field  
> found for [cval] in mapping with types [pm]]\n[Near : {... doc['cval'].value  
> ....}]\n ^\n[Line: 1, Column: 1]]; nested:  
> ElasticSearchIllegalArgumentException[No field found for [cval] in mapping  
> with types [pm]]; }]",  
> "status" : 500  
> }
> 
> I already upgraded, is it possible to safely downgrade to 0.19.4 using the  
> same index files or do I have to rebuild?

--  
Met vriendelijke groet,

Martijn van Groningen

---

<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: [August 14, 2012, 4:32pm UTC](https://discuss.elastic.co/t/top-children-with-custom-score/8399/3 "2012-08-14T16:32:19Z")

</div>

That did the trick. Thanks, would have never figured that out on my own.

On Wednesday, July 18, 2012 5:52:10 AM UTC-4, Martijn wrote:

> Hi Slushi,
> 
> The reason that the error occurs, is that in the last curl command in  
> your bash script  
> ([http://localhost:9200/tcbug/pm/\_search?fields=\*&pretty=true](http://localhost:9200/tcbug/pm/_search?fields=*&pretty=true) ...) is  
> targeted to the pm index only. If you target your request to both  
> types the error doesn't occur:  
> [http://localhost:9200/tcbug/pm,cm/\_search?fields=\*&pretty=true](http://localhost:9200/tcbug/pm,cm/_search?fields=*&pretty=true)
> 
> This isn't caused by the top children query, but by a recent change  
> (  
> [better type based inference when using scripts · elastic/elasticsearch@efe85f3 · GitHub](https://github.com/elasticsearch/elasticsearch/commit/efe85f322a073313d35f7261bfbe04baa3235de1))
> 
> to scripting. Because of this change only field values can be resolved  
> that are mapped in the requested types.
> 
> Martijn
> 
> On 12 July 2012 17:10, slushi \<[kiree...@gmail.com](mailto:kiree...@gmail.com) \<javascript:\>\> wrote:
> 
> > I had a top\_children query with a custom score subquery that was working  
> > fine in 19.4 but has broken when I upgraded to .8.
> > 
> > Here is the gist:  
> > [top children scoring bug · GitHub](https://gist.github.com/3098693)
> > 
> > It seems like it's trying to find the child field in the parent's  
> > mapping  
> > instead of the child mapping? The error (cm is child mapping, pm is  
> > parent  
> > mapping):  
> > {  
> > "error" : "SearchPhaseExecutionException[Failed to execute phase  
> > [query\_fetch], total failure; shardFailures  
> > {[N2r-dwPcTVq1Ujf0cE2\_gQ][tcbug][0]:  
> > QueryPhaseExecutionException[[tcbug][0]:  
> > query[filtered(score\_child[cm/pm](filtered(custom score  
> > (cid:c1,function=script[doc['cval'].value], params  
> > [null]))-\>cache(\_type:cm)))-\>cache(\_type:pm)],from[0],size[2]: Query  
> > Failed  
> > [Failed to execute child query [score\_child[cm/pm](filtered(custom score  
> > (cid:c1,function=script[doc['cval'].value], params  
> > [null]))-\>cache(\_type:cm))]]]; nested: CompileException[[Error: No field  
> > found for [cval] in mapping with types [pm]]\n[Near : {...  
> > doc['cval'].value  
> > ....}]\n ^\n[Line: 1, Column: 1]]; nested:  
> > ElasticSearchIllegalArgumentException[No field found for [cval] in  
> > mapping  
> > with types [pm]]; }]",  
> > "status" : 500  
> > }
> > 
> > I already upgraded, is it possible to safely downgrade to 0.19.4 using  
> > the  
> > same index files or do I have to rebuild?
> 
> --  
> 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:16am UTC](https://discuss.elastic.co/t/top-children-with-custom-score/8399/4 "2017-07-06T03:16:25Z")

</div>


