# Boosting based on child documents value

**URL:** <https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853>\
**Category:** Elasticsearch\
**Created:** [July 13, 2011, 10:56pm UTC](https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853 "2011-07-13T22:56:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cengiz\_Han](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cengiz_han/32/3166_2.png) [@Cengiz\_Han](https://discuss.elastic.co/u/Cengiz_Han)\
**Post date:** [July 13, 2011, 10:56pm UTC](https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853/1 "2011-07-13T22:56:15Z")

</div>

Hi all,  
I just started to use ElasticSearch and I found parent/child document  
feature very powerful over other search server options.

I can successfully create parent/child docs relation with below sample  
and I can query over existence of a child document value.  
But I want to boost parent document based on a child item value.

For example I want to boost "product" by viewcount value from child  
object. As I understand I need to use custom\_score but I couldn't find  
an example for this kind of requirement.

thanks

curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
curl -XPUT '[http://localhost:9200/test/product/1](http://localhost:9200/test/product/1)' -d  
'{"name" :"product1", "price":10}'  
curl -XPUT '[http://localhost:9200/test/product/2](http://localhost:9200/test/product/2)' -d '{"name" :  
"product2", "price":11}'  
curl -XPUT '[http://localhost:9200/test/product/3](http://localhost:9200/test/product/3)' -d  
'{"name" :"product3", "price":8 }'

curl -XPUT '[http://localhost:9200/test/product\_extra/\_mapping](http://localhost:9200/test/product_extra/_mapping)' -d  
'{"child" : { "\_parent" : {"type" : "product" } }}'  
curl -XPUT '[http://localhost:9200/test/product\_extra/1?parent=1](http://localhost:9200/test/product_extra/1?parent=1)' -d  
'{ "tag" : "games", "viewcount" : 100 }'  
curl -XPUT '[http://localhost:9200/test/product\_extra/2?parent=2](http://localhost:9200/test/product_extra/2?parent=2)' -d  
'{ "tag" : "office", "viewcount" : 10 }'

curl -XGET '[http://localhost:9200/test/product/\_search](http://localhost:9200/test/product/_search)?  
pretty=1&search\_type=dfs\_query\_then\_fetch' -d '{  
"query":{  
"bool":{  
"must":[  
{  
"has\_child":{  
"type":"product\_extra",  
"query":{  
"query\_string":{  
"query":"games"  
}  
}  
}  
}  
]  
}  
}  
}'

---

<div class="post-metadata">

**Author:** ![Cengiz\_Han](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cengiz_han/32/3166_2.png) [@Cengiz\_Han](https://discuss.elastic.co/u/Cengiz_Han)\
**Post date:** [July 15, 2011, 5:36am UTC](https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853/2 "2011-07-15T05:36:54Z")

</div>

any help or resource would be appreciated. Can anyone help me on this?

Thanks

On Jul 13, 2011, at 4:56 PM, Cengiz Han [cengiz@cengizhan.com](mailto:cengiz@cengizhan.com) wrote:

> Hi all,  
> I just started to use Elasticsearch and I found parent/child document  
> feature very powerful over other search server options.
> 
> I can successfully create parent/child docs relation with below sample  
> and I can query over existence of a child document value.  
> But I want to boost parent document based on a child item value.
> 
> For example I want to boost "product" by viewcount value from child  
> object. As I understand I need to use custom\_score but I couldn't find  
> an example for this kind of requirement.
> 
> thanks
> 
> curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
> curl -XPUT '[http://localhost:9200/test/product/1](http://localhost:9200/test/product/1)' -d  
> '{"name" :"product1", "price":10}'  
> curl -XPUT '[http://localhost:9200/test/product/2](http://localhost:9200/test/product/2)' -d '{"name" :  
> "product2", "price":11}'  
> curl -XPUT '[http://localhost:9200/test/product/3](http://localhost:9200/test/product/3)' -d  
> '{"name" :"product3", "price":8 }'
> 
> curl -XPUT '[http://localhost:9200/test/product\_extra/\_mapping](http://localhost:9200/test/product_extra/_mapping)' -d  
> '{"child" : { "\_parent" : {"type" : "product" } }}'  
> curl -XPUT '[http://localhost:9200/test/product\_extra/1?parent=1](http://localhost:9200/test/product_extra/1?parent=1)' -d  
> '{ "tag" : "games", "viewcount" : 100 }'  
> curl -XPUT '[http://localhost:9200/test/product\_extra/2?parent=2](http://localhost:9200/test/product_extra/2?parent=2)' -d  
> '{ "tag" : "office", "viewcount" : 10 }'
> 
> curl -XGET '[http://localhost:9200/test/product/\_search](http://localhost:9200/test/product/_search)?  
> pretty=1&search\_type=dfs\_query\_then\_fetch' -d '{  
> "query":{  
> "bool":{  
> "must":[  
> {  
> "has\_child":{  
> "type":"product\_extra",  
> "query":{  
> "query\_string":{  
> "query":"games"  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }'

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 15, 2011, 5:39am UTC](https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853/3 "2011-07-15T05:39:31Z")

</div>

The only option you have is using the top\_children option, which has a custom score query within it running on the child documents.

The nested support in master (upcoming 0.17) makes it simpler and more performant (but requires the nested docs to be part of the json indexed).

On Friday, July 15, 2011 at 8:36 AM, Cengiz Han wrote:

> any help or resource would be appreciated. Can anyone help me on this?
> 
> Thanks
> 
> On Jul 13, 2011, at 4:56 PM, Cengiz Han \<[cengiz@cengizhan.com](mailto:cengiz@cengizhan.com) ([mailto:cengiz@cengizhan.com](mailto:cengiz@cengizhan.com))\> wrote:
> 
> > Hi all,  
> > I just started to use Elasticsearch and I found parent/child document  
> > feature very powerful over other search server options.
> > 
> > I can successfully create parent/child docs relation with below sample  
> > and I can query over existence of a child document value.  
> > But I want to boost parent document based on a child item value.
> > 
> > For example I want to boost "product" by viewcount value from child  
> > object. As I understand I need to use custom\_score but I couldn't find  
> > an example for this kind of requirement.
> > 
> > thanks
> > 
> > curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
> > curl -XPUT '[http://localhost:9200/test/product/1](http://localhost:9200/test/product/1)' -d  
> > '{"name" :"product1", "price":10}'  
> > curl -XPUT '[http://localhost:9200/test/product/2](http://localhost:9200/test/product/2)' -d '{"name" :  
> > "product2", "price":11}'  
> > curl -XPUT '[http://localhost:9200/test/product/3](http://localhost:9200/test/product/3)' -d  
> > '{"name" :"product3", "price":8 }'
> > 
> > curl -XPUT '[http://localhost:9200/test/product\_extra/\_mapping](http://localhost:9200/test/product_extra/_mapping)' -d  
> > '{"child" : { "\_parent" : {"type" : "product" } }}'  
> > curl -XPUT '[http://localhost:9200/test/product\_extra/1?parent=1](http://localhost:9200/test/product_extra/1?parent=1)' -d  
> > '{ "tag" : "games", "viewcount" : 100 }'  
> > curl -XPUT '[http://localhost:9200/test/product\_extra/2?parent=2](http://localhost:9200/test/product_extra/2?parent=2)' -d  
> > '{ "tag" : "office", "viewcount" : 10 }'
> > 
> > curl -XGET '[http://localhost:9200/test/product/\_search](http://localhost:9200/test/product/_search)?  
> > pretty=1&search\_type=dfs\_query\_then\_fetch' -d '{  
> > "query":{  
> > "bool":{  
> > "must":[  
> > {  
> > "has\_child":{  
> > ""type":"product\_extra",  
> > "query":{  
> > "query\_string":{  
> > ""query":"games"  
> > }  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }'

---

<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, 4:00am UTC](https://discuss.elastic.co/t/boosting-based-on-child-documents-value/4853/4 "2017-07-06T04:00:33Z")

</div>


