# Bad Request when using scroll API

**URL:** <https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702>\
**Category:** Elasticsearch\
**Created:** [February 27, 2021, 9:24pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702 "2021-02-27T21:24:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [February 27, 2021, 9:24pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/1 "2021-02-27T21:24:10Z")

</div>

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:

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

```

Response:

```auto
{"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:

```auto
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));
    }

```

---

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [March 1, 2021, 6:58pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/2 "2021-03-01T18:58:49Z")

</div>

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

Would Search After work with JestClient?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 1, 2021, 7:55pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/3 "2021-03-01T19:55:50Z")

</div>

> [@nara1](#):
>
> is it because search scroll is deprecated?

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.

---

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [March 1, 2021, 8:27pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/4 "2021-03-01T20:27:10Z")

</div>

Gotcha, was seeing [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/scroll-api.html) 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.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 1, 2021, 8:47pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/5 "2021-03-01T20:47:43Z")

</div>

> [@nara1](#):
>
> that it has been deprecated in 7.0.0

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.

> [@nara1](#):
>
> Other than that I've logged everything

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.

---

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [March 1, 2021, 8:53pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/6 "2021-03-01T20:53:21Z")

</div>

If you hover over "[7.0.0]" [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/scroll-api.html#scroll-api-request) it says "Deprecated in 7.0.0."

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

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 1, 2021, 10:19pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/7 "2021-03-01T22:19:33Z")

</div>

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.

---

<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:** [March 29, 2021, 10:20pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scroll-api/265702/8 "2021-03-29T22:20:13Z")

</div>

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