Elastic Pagination

Hello Guys,

I'm using elastic search with java. My elastic query is returning 103 results, which means that if I'm paging through them (with 25 results per page) I should have 4 pages: 4 full pages and 1 page with a 3 row result.
(using setFrom and setSize).

However, my last page is still returning 25 results. It's returning the very last result as expected, but also 22 results from the previous page. How do I disable this behavior and have it just return the single result as expected?

Could you share the code you use to page through the results?

here is my code,

 searchReq = ElasticConnection.getClient().prepareSearch(conn.getCoreName());
        searchReq.setTypes(conn.getType());
        
        
        searchReq.setQuery(search(order))
                 
                 .setFrom(pageNumber)
                 .setSize(25);


  SearchResponse searchResponse = searchReq.execute().actionGet();

That should get you the top 25, but how do you implement the paging?

Thank you Sir,

I found my error. I implemented paging wrong. So i fixed it.

Here is my code

          searchReq.setQuery(search(order))
            .setFrom(pageNumber*pageCount)
            .setSize(pageCount);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.