# Re: Counts of children in parent/child data

**URL:** <https://discuss.elastic.co/t/re-counts-of-children-in-parent-child-data/15703>\
**Category:** Elasticsearch\
**Created:** [February 10, 2014, 6:48pm UTC](https://discuss.elastic.co/t/re-counts-of-children-in-parent-child-data/15703 "2014-02-10T18:48:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 10, 2014, 6:48pm UTC](https://discuss.elastic.co/t/re-counts-of-children-in-parent-child-data/15703/1 "2014-02-10T18:48:47Z")

</div>

James,

Sounds like you want to query the parents and then score/rank them by the  
sum of the userScore values of their corresponding children. You can try  
something like this:

POST [http://localhost:9200/](http://localhost:9200/)/\_search  
{  
"query": {  
"has\_child": {  
"type": "",  
"score\_type": "sum",  
"query": {  
"function\_score": {  
"script\_score": {  
"script": "doc['.userScore'].value"  
},  
"boost\_mode": "replace"  
}  
}  
}  
}  
}

--  
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/5b1fc5b0-16c0-42f2-90de-9169f3cb6e64%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5b1fc5b0-16c0-42f2-90de-9169f3cb6e64%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:51am UTC](https://discuss.elastic.co/t/re-counts-of-children-in-parent-child-data/15703/2 "2017-07-06T01:51:24Z")

</div>


