# Implementing Search After to fetch hits greater than 10000

**URL:** https://discuss.elastic.co/t/implementing-search-after-to-fetch-hits-greater-than-10000/309913
**Category:** Elasticsearch
**Created:** [July 18, 2022, 2:09pm UTC](https://discuss.elastic.co/t/implementing-search-after-to-fetch-hits-greater-than-10000/309913 "2022-07-18T14:09:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Namita\_Jaokar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/namita_jaokar/32/104106_2.png) [@Namita\_Jaokar](https://discuss.elastic.co/u/Namita_Jaokar)
#### Post date: [July 18, 2022, 2:09pm UTC](https://discuss.elastic.co/t/implementing-search-after-to-fetch-hits-greater-than-10000/309913/1 "2022-07-18T14:09:04Z")

</div>

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 ,

```auto
 searchResponse = client.search(searchRequest,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

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [July 18, 2022, 2:59pm UTC](https://discuss.elastic.co/t/implementing-search-after-to-fetch-hits-greater-than-10000/309913/2 "2022-07-18T14:59:18Z")

</div>

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](https://gist.github.com/andreluiz1987/9710c1f30a8c6d7ff35b59be5704e542).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 15, 2022, 2:59pm UTC](https://discuss.elastic.co/t/implementing-search-after-to-fetch-hits-greater-than-10000/309913/3 "2022-08-15T14:59:32Z")

</div>

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