Explaining Pagination in ElasticSearch

Three Pagination Approaches with SQL and ElasticSearch Demonstration

Chunting Wu
Starbugs Weekly 星巴哥技術專欄

--

Photo by BENCE BOROS on Unsplash

Pagination is a common technique for web page presentation. When there is a lot of returned data, either to reduce the load on the backend or to improve the user experience, it is usually a good idea to limit the amount of presentation and keep the option to continue browsing.

Here’s a quick look at the most common appearance.

< [1] | 2 | 3 | 4 | ... >

The user can know the current page number, choose the previous or next page, or even jump directly to the specified page. There are three types of pagination approaches as follows.

  • Offset Pagination
  • Keyset Pagination
  • Cursor-based Pagination

But this article is to introduce ElasticSearch pagination, so I will briefly describe these three.

Offset Pagination

This is the most common pagination pattern, and let’s represent it in SQL.

SELECT *
FROM table_name
LIMIT 10 OFFSET 20;

Suppose there are 10 records on one page, then we can get the result of the third page by this command. Use LIMIT to limit the number of records per page and…

--

--