Pagination

While searching, users can't view all the results at once. They like to see one batch at a time. Usually, a single batch contains 10 matched documents, as in Google search results, where each page contains 10 search results. This also gives us an advantage over the search engine as it need not send all the results back at once. The following is how we use pagination in Elasticsearch. Let's say that we are interested in seeing only five results at a time, then to get the first page, we have to use the following parameters:

  • size = 5 (defaults to 10).
  • from = 0, 5, 10, 15, 20 (defaults to 0). This depends on the page number you need.

Also, it should be noted that the total number of pages can be calculated from count/_size. Sample query for ...

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.