Elasticsearch-rest-high-level-client SearchRequest returns partial result

I have some java code as follows:

    SearchRequest searchRequest = new SearchRequest(index);
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    SearchResponse response = client.search(searchRequest,RequestOptions.DEFAULT);

    var hits = response.getHits();
    for(var hit : hits){

Expected number of docs is 36, Total hits is 36, but the list has only 10 actual docs as shown in the screenshot:

Is there some other setting required to fetch all 36?

Hi @Avinash_D_Silva,

by default a search returns only the top 10 hits. You can set that by something like:


However, notice that if you want all results out of a search, you may want to look at scroll search, which allows you to scroll through a large search result.

See also:

1 Like

Thank you @HenningAndersen
searchSourceBuilder.size(20) did the trick!

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