Pagination with Java API for ElasticSearch

elasticsearch, java, playframework

Solution

In Elasticsearch module documentation for Play:

Call ElasticSearch.query() and subsequently set query parameters (e.g. paging)

So in your case, you want to retrieve j searchresults from i:

SearchResults<Book> searchResult =  ElasticSearch.query(QueryBuilders.queryString(search), Book.class).from(i).size(j).fetch();

Problem

I am trying to use elastic search module in the play framework for searching books and I have the following method to perform the search in the controller which returns me a list of books based upon the search string entered by the user ``` public static void bookList(String search){ SearchResults<Book> searchResult = ElasticSearch.search(QueryBuilders.queryString(search) , Book.class); List<Book> bookList = searchResult.objects ; render(bookList); } ``` Now I need to perform pagination on the results obtained . How do I go about doing that using the Java API ?

Original source