# Varying result size per in calls

**URL:** <https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [March 4, 2021, 2:55pm UTC](https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255 "2021-03-04T14:55:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![malik\_aditya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/malik_aditya/32/45618_2.png) [@malik\_aditya](https://discuss.elastic.co/u/malik_aditya)\
**Post date:** [March 4, 2021, 2:55pm UTC](https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255/1 "2021-03-04T14:55:34Z")

</div>

I am using AppSearch and the requirement is to fetch varying result sizes per call. Like on first call I need three records and on each successive calls I need 6 records. I checked documentation and there is no facility similar to elasticsearch's "from & size". Is there any way to accomplish it directly via AppSearch API?

---

<div class="post-metadata">

**Author:** ![Irina\_Truong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irina_truong/32/112040_2.png) [@Irina\_Truong](https://discuss.elastic.co/u/Irina_Truong)\
**Post date:** [March 4, 2021, 5:55pm UTC](https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255/2 "2021-03-04T17:55:11Z")

</div>

Hi Malik,

You do have the ability to vary `page.size` and `page.current` when querying vis Search API:

> **[Search guide | Elastic App Search Documentation \[7.11\] | Elastic](https://www.elastic.co/guide/en/app-search/current/search-guide.html#search-guide-paginate)**

However, to achieve exactly what you're asking may not be very straightforward, because `page.current` is not the same as variable offset. In your case, if you want 3 records first, and then 6 on each subsequent request, you may have to do something odd, like:

1. Request 6 records every time, but first time, your application would display the "head" of 3, and keep the "tail" of 3 to tuck on top of page 2. Then, the "tail" of every page would be treated the same, and tucked on top of next page. I have a headache just thinking about it.
2. You could try using `multi_search` endpoint to achieve this:

> **[Multi search API | Elastic App Search Documentation \[7.11\] | Elastic](https://www.elastic.co/guide/en/app-search/current/multi-search.html)**

In your first query, you'd request 1 page of size 3:

```auto
curl -s -X GET 'https://localhost/api/as/v1/engines/national-parks-demo/multi_search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxxxxx' \
-d '{
  "queries": [
    {"query": "park", "page": {"size": 3, "current": 1}}
  ]
}'

```

In your subsequent query, you'd request page 2 and 3 of size 3:

```auto
curl -s -X GET 'https://localhost/api/as/v1/engines/national-parks-demo/multi_search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxxxxx' \
-d '{
  "queries": [
    {"query": "park", "page": {"size": 3, "current": 2}},
    {"query": "park", "page": {"size": 3, "current": 3}}
  ]
}'

```

and so on. You'd have to concatenate results from these 2 queries for display.

I hope this helps! The requirement to display records in this manner is pretty unusual. I would advise, if possible, to just stick with regular pagination, with all pages being of the same size.

---

<div class="post-metadata">

**Author:** ![malik\_aditya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/malik_aditya/32/45618_2.png) [@malik\_aditya](https://discuss.elastic.co/u/malik_aditya)\
**Post date:** [March 15, 2021, 8:58am UTC](https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255/3 "2021-03-15T08:58:19Z")

</div>

Thanks for the help. I believe Multi\_search could help with this use-case. Totally agree that a regular pagination is the best approach and will try to see if the requirements could be updated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 12, 2021, 8:59am UTC](https://discuss.elastic.co/t/varying-result-size-per-in-calls/266255/4 "2021-04-12T08:59:03Z")

</div>

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