# Boosting based on a child document's field

**URL:** <https://discuss.elastic.co/t/boosting-based-on-a-child-documents-field/12076>\
**Category:** Elasticsearch\
**Created:** [May 22, 2013, 2:13pm UTC](https://discuss.elastic.co/t/boosting-based-on-a-child-documents-field/12076 "2013-05-22T14:13:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koikahin](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@koikahin](https://discuss.elastic.co/u/koikahin)\
**Post date:** [May 22, 2013, 2:13pm UTC](https://discuss.elastic.co/t/boosting-based-on-a-child-documents-field/12076/1 "2013-05-22T14:13:26Z")

</div>

Consider an index having the types 'primary' and 'meta', the latter being a  
child of the former:

curl -XPUT '[http://localhost:9200/idx/meta/\_mapping](http://localhost:9200/idx/meta/_mapping)' -d '  
{  
"meta" : {  
"\_parent": {"type":"primary"},  
"properties":{  
"rating" : {"type":"integer", "store":true},  
}  
}  
}  
'

It is a one to one mapping, so each primary document will have exactly one  
corresponding meta document. This is designed so as to decouple updates to  
the meta, which can be relatively much more frequent compared to primary.

Now, the area of interest for search here is the 'primary' type. So queries  
will be run on that. However, irrespective of the query run, I want to be  
able to boost each matching document based on it's 'meta' child's 'rating'  
field. E.g. if I a query matches two documents, pri1 and pri2, and the  
'rating' field for pri1's child 'meta1' is 5 and that of pri2's child  
'meta2' is 10, I want to boost pri1 and pri2 with 5 and 10 correspondingly.

I can achieve that with a query of the following form:  
{  
"query":{  
"bool": {  
"must": {  
  
},  
"must": {  
"has\_child": {  
"type":"meta",  
"query": {  
"custom\_score": {  
"query": {"match\_all": {}},  
"script": "\_score \* doc['rating'].value"  
}  
},  
"score\_type": "sum"  
}  
}  
}  
}  
}

The above works. However, I am concerned about the performance when it is  
done this way. For, let's say, a 100m documents, how would the performance  
of the above turn out to be? I am hoping that since both of these are under  
the must clause, the first one would run first, and the second one (for  
scoring) will be run on the returned results, but of course there can be no  
guarantee of that.

Is there a better way to achieve the same? The 'has\_child' filter doesn't  
seem to accept 'score\_type' (I was hoping it was missed during  
documentation) so I can't use the filter to do the boosting. I've tried  
using the 'has\_child' query within a 'query' filter ( 😉 ) hoping that that  
would somehow magically work, but that doesn't seem to be the case either...

Thanks in advance

--  
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:** ![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:35am UTC](https://discuss.elastic.co/t/boosting-based-on-a-child-documents-field/12076/2 "2017-07-06T02:35:24Z")

</div>


