Filter results to a single child per parent


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
To view this discussion on the web visit
For more options, visit