# Scroll API for java api 2.3.5 Loss of data

**URL:** <https://discuss.elastic.co/t/scroll-api-for-java-api-2-3-5-loss-of-data/136793>\
**Category:** Elasticsearch\
**Created:** [June 21, 2018, 6:50am UTC](https://discuss.elastic.co/t/scroll-api-for-java-api-2-3-5-loss-of-data/136793 "2018-06-21T06:50:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [June 21, 2018, 6:50am UTC](https://discuss.elastic.co/t/scroll-api-for-java-api-2-3-5-loss-of-data/136793/1 "2018-06-21T06:50:22Z")

</div>

Hi !

I am practicing with the java api，When I use scroll to get the data, I get an error that causes

I can't get all the data

```
**log:**
[2018-06-21 11:30:21,059][DEBUG][action.search] [Kiwi Black] [15] Failed to execute query phase
RemoteTransportException[[Kiwi Black][127.0.0.1:9300][indices:data/read/search[phase/scan/scroll]]]; nested: SearchContextMissingException[No search context found for id [15]];
Caused by: SearchContextMissingException[No search context found for id [15]]
	at org.elasticsearch.search.SearchService.findContext(SearchService.java:613)
	at org.elasticsearch.search.SearchService.executeScan(SearchService.java:313)
	at org.elasticsearch.search.action.SearchServiceTransportAction$SearchScanScrollTransportHandler.messageReceived(SearchServiceTransportAction.java:433)
	at org.elasticsearch.search.action.SearchServiceTransportAction$SearchScanScrollTransportHandler.messageReceived(SearchServiceTransportAction.java:430)
	at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
	at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

```

**java code:**

```
SearchRequestBuilder searchRequestBuilder = 
					ESUtil1.getClient().prepareSearch(index).setTypes(type).setSearchType(SearchType.SCAN);
			
			BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
			
			boolQueryBuilder.must(QueryBuilders.termQuery("multi", "test"));
			
			searchRequestBuilder.setQuery(boolQueryBuilder);

			Double pagecount = 1000D;
			
			SearchResponse searchResponse = searchRequestBuilder.setSize(pagecount.intValue()).setScroll(new TimeValue(60000)).execute().actionGet();

			long total=searchResponse.getHits().totalHits();
			
			Double totalpagenum = Math.ceil(Double.valueOf(total)/Double.valueOf(pagecount));
			
			for(int i=0; i<totalpagenum; i++){
				
				searchResponse =ESUtil1.getClient().prepareSearchScroll(searchResponse.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
				
				SearchHit[] searchHists = searchResponse.getHits().getHits();
				
				for (SearchHit hit : searchHists) {
					
				}
			}
```

---

<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:** [July 19, 2018, 6:50am UTC](https://discuss.elastic.co/t/scroll-api-for-java-api-2-3-5-loss-of-data/136793/2 "2018-07-19T06:50:24Z")

</div>

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