Skip to main content

Pagination

Elasticsearch uses from and size for search pages and _count for totals. These requests fetch page two with ten records:

POST /user_info/_search {"query":{"match_all":{}},"sort":[{"uid":"asc"}],"from":10,"size":10}
POST /user_info/_count {"query":{"match_all":{}}}

Map uid as keyword and ensure unique values in the application.

dbVisitor Usage

Add a Page argument to a Mapper method. The entity mapping is shown in Entity Mapping.

@Query("""
POST /user_info/_search
{"query":{"match_all":{}},"sort":[{"uid":"asc"}]}
""")
List<UserInfo> findPage(Page page);
Page page = new PageObject(1, 10);
List<UserInfo> rows = mapper.findPage(page);

Page numbering starts at zero. For ordinary searches, Page overrides from/size and uses _count when a total is required.

composite aggregations page result buckets through after_key. The Page total counts buckets, not documents. An exact total requires traversing all buckets; see Aggregations.

Notes

Deep pages of ordinary searches are subject to the server result window. The driver does not switch to search_after or scroll. queryForList reads only this search response, not the entire index.

Counts and page reads are separate requests; concurrent writes can change their results. See 9.5 Pagination for the common API.