I'm using JestClient to execute scrolling in my service (I know JestClient is outdated but for various reasons we are stuck with it for now).
In my initial request, I do receive a scroll ID and my results successfully. When I try executing the second request, below, I get 400 Bad Request:
Request:
scroll: SearchScroll{uri=/_search/scroll?scroll_id=<SCROLL_ID>&scroll=2m, method=GET}
Response:
{"message":null}, isSucceeded: false, response code: 400, error message: 400 Bad Request
When I try in Kibana, I'm able to scroll successfully with the same URI pattern. I'm stumped why this isn't working, when my first request successfully executes. It's only the second request that the response is 400.
Here is the code:
final Search search = new Search.Builder(searchSourceBuilder.toString())
.addIndex(ElasticsearchConstants.INDEX_PREFIX + '*')
.setParameter(Parameters.SCROLL, ElasticsearchConstants.ES_SCROLL_KEEP_ALIVE_TIME)
.build();
JestResult result = jestClient.execute(search);
List<MockDataModel> hits = result.getSourceAsObjectList(MockDataModel.class);
int numberOfHits = result.getJsonObject().get(ElasticsearchConstants.HITS).getAsJsonObject()
.get(ElasticsearchConstants.TOTAL).getAsJsonObject().get(ElasticsearchConstants.VALUE).getAsInt();
while (hits.size() < numberOfHits) {
String scrollId = result.getJsonObject().get(ElasticsearchConstants.SCROLL_ID).getAsString();
SearchScroll scroll = new SearchScroll.Builder(scrollId, ElasticsearchConstants.ES_SCROLL_KEEP_ALIVE_TIME).build();
// This request is the one returning bad request
result = jestClient.execute(scroll);
hits.addAll(result.getSourceAsObjectList(MockDataModel.class));
}