Hi Elasticsearch team and community,
I’m working on a app where I need to:
- Sort products primarily by a priority field (
priority
), descending. - But also interleave (round-robin) results from different groups, so that no two consecutive products come from the same group.
- Ideally, the interleaving respects the weighted priority of products (higher priority groups appear more frequently but results are still mixed).
- Support pagination (e.g., 24 results per page).
For example, if I have groups with priorities:
- GROUP A: 20
- GROUP B: 20
- GROUP C: 20
- GROUP D: 1
I want results like:
[GROUP A Product 1, GROUP B Product 1, GROUP C Product 1, GROUP A Product 2, GROUP B Product 2, ...]
I have explored:
- Sorting by
priority
— works but groups groups together, causing consecutive items from the same group.
Is there any native or recommended way to achieve this kind of weighted round-robin or interleaving within Elasticsearch’s query or sorting capabilities?
If not, are there best practices or patterns to implement this efficiently, maybe combining ES with application-side logic?
Thanks in advance!