Data pagination
We have seen that for any query, Elasticsearch by default returns only the top 10 documents after scoring and sorting them. However, they are not always enough to serve the purpose. A user always needs more and more data either to render on a page or to process in the backend. Let's see how we can do this.
Pagination with scoring
In the previous chapters, we discussed how Elasticsearch offers the from
and to
parameters to be passed with search requests. So, you always have an option to either increase the size
parameter to load more results from Elasticsearch or send another query with the changed from
and size
values to get more data.
This pagination approach makes sense when you have to fetch a limited number of documents from Elasticsearch. As this approach is too costly and can kill Elasticsearch if you are hitting a request, for example, where from
= 100000
and size
= 100010
to get 10 documents, which have less score than those 1 lac
documents in the index.