Implementing Search After to fetch hits greater than 10000

Hi team,

I am using elasticsearch in java to query hits that are greater than maximum default of 10000.
For the same I came across using search after along with sort. I tried the query by sorting it on the basis of @timestamp. I was able to fetch the values in kibana dev tools for the same.
However, I need to implement the same in java. My requirement is to fetch those 10k plus records by implementing search after but Was not able to find any examples of how I can proceed with implementing the same.
I have tried below ,

 searchResponse =,org.elasticsearch.client.RequestOptions.DEFAULT);					searchAfterArr=searchResponse.getHits().getAt(index).getSortValues();

But unable to proceed further with providing the searchAfterArr result to my querybuilder which uses SearchSourceBuilder.

Can you please guide me with implementing search after in java for size>10000 hits. Or a basic implementation of searchAfter with java. Or any other approach to get all the hits from a the datastreams , with total hits being greater than 10k

Thanks & Regards,
Namita Jaokar

Hi @Namita_Jaokar

I have a simple example of how to use search after with java high level client, maybe can help you.
You can see here.

1 Like

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