Combining queries while preserving order

Hi Elastic Community,

I have the use case, that I want to search blocks of data in order.

If we take products as an example a requirement could look like this:

Group1: First 5 products are products with the id 120, 121, 122, 123, 124
Group2: Then 10 products in the category "shoes".
Group3: Then all products in the band "nike".

I can easily solve this by running 3 queries one after the other and merging the results. The problem with this solution is, that I'd like to aggregate data over this results set. For example I could be interested in the distribution of prices of those products.

So preferably I'd like to make this work with one single query, that I can run my aggregations on.

I thought about using scoring tiers with additive boosts like so:
Group 1: +10_000
Group 2: +1_000
Group 3: +100
etc.

The problem with that is, that I can not find a way to limit the groups by n amount of products, within my boolean query. The size parameter only works on the entire result set.

Is there a way to limit single sub queries or does anyone have an idea how this can be solved otherwise?

Thanks a lot!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.