Varying result size per in calls

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?

Hi Malik,

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

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:

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

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:

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.

1 Like

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.

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