Hi Elasticsearch community,
I’m implementing a search feature where items belong to groups, and some groups are marked as premium. I want search results to:
-
Show all items from premium groups first, then non-premium items.
-
Interleave items across premium groups in a round-robin fashion, e.g.:
group1 → item1
group2 → item1
group3 → item1
group1 → item2
group2 → item2
...
-
Filters may be applied (e.g., ranges, categories).
-
Supports pagination (size=24, for example)
I’ve explored:
-
Pre-computing a rank within each group — breaks when filters are applied and remove items.
-
terms
agg by group and then atop_hits
for each group - not exactly what i want too and does not support pagination. Also, i don’t have a fixed amount of premium groups or items.
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? However, the application-side logic can not have an impact in application performance.
Thanks in advance!