Retrieve and Paginate Elasticsearch Results by Specific Categories

I have an Elasticsearch index that contains documents with company and subscription fields. The subscription field can have values like platinum, silver, and gold.

For every search by company name, I need to retrieve results in the following format:

  • 10 results per page
    • 5 companies with a platinum subscription
    • 3 companies with a silver subscription
    • 2 companies with a gold subscription

How can I achieve this in Elasticsearch? Is there a way to structure the query and pagination to meet these requirements?

Run 3 separate queries as a single request using the multi search API, each fetching the appropriate number of matches for one specific subscription level. The three queries will paginate separately, which makes for a rather simple solution that is easy to test and maintain.