# Filter results to a single child per parent

**URL:** <https://discuss.elastic.co/t/filter-results-to-a-single-child-per-parent/21411>\
**Category:** Elasticsearch\
**Created:** [December 28, 2014, 5:59am UTC](https://discuss.elastic.co/t/filter-results-to-a-single-child-per-parent/21411 "2014-12-28T05:59:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![simoami](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simoami/32/1021_2.png) [@simoami](https://discuss.elastic.co/u/simoami)\
**Post date:** [December 28, 2014, 5:59am UTC](https://discuss.elastic.co/t/filter-results-to-a-single-child-per-parent/21411/1 "2014-12-28T05:59:04Z")

</div>

Hello,

I have a product-\>offer relationship indexed using the parent / child model  
in ES. I'm currently querying offers directly which by default can return  
multiple offers per product. e.g.

offer 1 (\_score: 1.5, \_parent: 1)  
offer 2 (\_score: 1.4, \_parent: 5)  
offer 3 (\_score: 1.3, \_parent: 1)  
offer 4 (\_score: 1.3, \_parent: 7)

I have a use case where I need to only fetch the highest ranking offer per  
product. so offer 3 from the preview example would not be returned unless  
offer 1 didn't match.

offer 1 (\_score: 1.5, \_parent: 1)  
offer 2 (\_score: 1.4, \_parent: 5)  
offer 4 (\_score: 1.3, \_parent: 7)

This is similar to grouping by parent, where no 2 records will point to the  
same parent. I was wondering if there's a way to have this grouping using a  
custom query or maybe I should look at another approach.

Thank you

--  
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/b5376b44-ee36-4307-8769-7a30518e39a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b5376b44-ee36-4307-8769-7a30518e39a4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:41am UTC](https://discuss.elastic.co/t/filter-results-to-a-single-child-per-parent/21411/2 "2017-07-06T00:41:44Z")

</div>


