Filter results to a single child per parent

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b5376b44-ee36-4307-8769-7a30518e39a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.