How to resolve search context missing exception while passing scrollId to method

Below code used for get scroll Id.

CODE
SearchRequest searchRequest = new SearchRequest(INDEX);
	    searchRequest.types(TYPE);
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.query(QueryBuilders.matchAllQuery());
		searchSourceBuilder.size(2); 
		searchRequest.source(searchSourceBuilder);
		searchRequest.scroll(TimeValue.timeValueMinutes(5L)); 
		SearchResponse searchResponse = null;
		try {
			searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String scrollId = searchResponse.getScrollId(); 

This scroll Id I am passing to UI and again calling getAPI for next records. Below is code:

CODE

SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
		scrollRequest.scroll(new Scroll(TimeValue.timeValueMinutes(5L)));
		SearchResponse searchScrollResponse = null;
		try {
			searchScrollResponse = restHighLevelClient.scroll(scrollRequest, RequestOptions.DEFAULT);
		} catch (IOException e1) {
			e1.printStackTrace();
		}

Getting exception while executing restHighLevelClient.scroll(scrollRequest, RequestOptions.DEFAULT);

Please help how to pass scrollId for second and consecutive request.Preformatted text

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
I just updated your post myself but next time please format it.

The code looks good to me.

At least it seems similar to https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.5/java-rest-high-search-scroll.html

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