# Retrieve and Paginate Elasticsearch Results by Specific Categories

**URL:** <https://discuss.elastic.co/t/retrieve-and-paginate-elasticsearch-results-by-specific-categories/360531>\
**Category:** Elasticsearch\
**Created:** [May 30, 2024, 5:40am UTC](https://discuss.elastic.co/t/retrieve-and-paginate-elasticsearch-results-by-specific-categories/360531 "2024-05-30T05:40:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh03](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rajesh03](https://discuss.elastic.co/u/Rajesh03)\
**Post date:** [May 30, 2024, 5:40am UTC](https://discuss.elastic.co/t/retrieve-and-paginate-elasticsearch-results-by-specific-categories/360531/1 "2024-05-30T05:40:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 30, 2024, 6:09am UTC](https://discuss.elastic.co/t/retrieve-and-paginate-elasticsearch-results-by-specific-categories/360531/2 "2024-05-30T06:09:11Z")

</div>

Run 3 separate queries as a single request using the [multi search API](https://www.elastic.co/guide/en/elasticsearch/reference/8.13/search-multi-search.html), 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.
