Java pagination for ElasticSearch

I am trying to use the elastic search module in the playback structure to search for books, and I have the following method for doing a search in the controller, which returns me a list of books based on 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 paginate the results. How do I do this using the Java API?

+3
source share
1 answer

In the documentation for the Elasticsearch module for Play:

Call ElasticSearch.query () and subsequently set the query parameters (for example, paging)

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

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

All Articles