Enabling Pagination using spring-data-elasticsearch

Hello!

I've integrated Spring-elastic-data into Spring Boot Project to achieve the Pagination functionality in ES.

Previously I was using query and response into List as below,

SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

List<ProductsESDocument> productsDocument = new ArrayList<>();
   for (SearchHit hit : searchResponse.getHits()) {
   productsESDocument = objectMapper.convertValue(hit.getSourceAsMap(),   ProductsESDocument.class);
         productsDocument.add(productsESDocument);     
}

Can anybody please guide me on how to achieve the pagination instead of List?

TIA

That's probably a question you should ask on spring data forums IMHO.

Since, this is related to the Elasticsearch I had posted here. Otherwise in relational database already implemented.

So here's an elasticsearch answer:

You can use:

  • the size and from parameters to display by default up to 10000 records to your users. If you want to change this limit, you can change index.max_result_window setting but be aware of the consequences (ie memory).
  • the search after feature to do deep pagination.
  • the Scroll API if you want to extract a resultset to be consumed by another tool later.