Bad Request when using scroll API

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:


scroll: SearchScroll{uri=/_search/scroll?scroll_id=<SCROLL_ID>&scroll=2m, method=GET}


{"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)
    JestResult result = jestClient.execute(search);

    List<MockDataModel> hits = result.getSourceAsObjectList(MockDataModel.class);

    int numberOfHits = result.getJsonObject().get(ElasticsearchConstants.HITS).getAsJsonObject()

    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);

Any advice on this one, is it because search scroll is deprecated?

Would Search After work with JestClient?

That's not right, scroll isn't deprecated? And even if it was, it should still work.

What's the actual error reported by Elasticsearch? Not just the response code, the body of the response will contain more details too.

Gotcha, was seeing here that it has been deprecated in 7.0.0 but that's good to know that it should still work.

And unfortunately the response I posted above is the entire response I'm getting, the message is null. What my try/catch is logging is a NullPointer because in my while loop I'm trying to get the scroll ID in the result. Other than that I've logged everything and there are no actual errors besides Bad Request.

I don't see anywhere on the page you linked that should give you this impression. It's "not recommended for deep pagination" since 7.10, because PIT is a better option for that, but it still has its uses.

I'm pretty sure Elasticsearch will be returning more information in the response body, but it might be getting lost in your client somewhere. I don't know this client very well so if you can't work out how to get at the body yourself you'll need to find a Jest client expert.

If you hover over "[7.0.0]" here it says "Deprecated in 7.0.0."

Ok thanks, I'll work on trying to get the response body.

Ah I see the confusion. Specifying the scroll ID in the URL (either in the path or as a query parameter) is deprecated, you should specify it in the body instead, but that's the only deprecated thing.

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