# Scrolling API Seems Inconsistent

**URL:** <https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 2, 2025, 5:14pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763 "2025-05-02T17:14:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moose](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Moose](https://discuss.elastic.co/u/Moose)\
**Post date:** [May 2, 2025, 5:14pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/1 "2025-05-02T17:14:36Z")

</div>

I'm using the .NET NEST client in my Azure function to retrieve data from our Elastic account. Some of the `SearchAsync` requests I make exceed the 10,000 search result limit and as such I have to use the `ScrollAsync` request after it to get the rest. I've noticed that sometimes the `ScrollAsync` request doesn't return the results that it should be. The request is successful with a 200 code but just returns 0 documents instead of the 2,000 more that it should be. I'd say this happens maybe like 20% of the time.

Has anyone else experienced this? Any recommendations or suggestions? I'm happy to provide code snippets if it'd be helpful. Thanks.

---

<div class="post-metadata">

**Author:** ![Rafa\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafa_silva/32/147814_2.png) [@Rafa\_Silva](https://discuss.elastic.co/u/Rafa_Silva)\
**Post date:** [May 3, 2025, 3:28am UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/2 "2025-05-03T03:28:21Z")

</div>

Yeah, this kind of issue with ScrollAsync in Elasticsearch does happen, and it can be tricky to catch. A few things that might be causing it:

Scroll expiration – If there’s too much time between scroll requests (like more than 1 minute), Elasticsearch drops the scroll context and just returns nothing.

Reusing the scroll ID – If you’re using the same ElasticClient for multiple scrolls or doing them in parallel, that can break the scroll session.

Delays in Azure Functions – Cold starts or unexpected delays can let the scroll expire before the next request is made.

Other client operations in between – If the client is used for something else between scroll calls, that can also interfere and clear the scroll context.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [May 3, 2025, 10:57am UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/3 "2025-05-03T10:57:37Z")

</div>

Hi @Moose,

I don't think this is a issue with the Elasticsearch .NET client. An expired scroll timeout would be my guess as well (hard to tell without server side logs).

> Reusing the same `ElasticClient` instance across scrolls or multiple scrolls in parallel can invalidate the scroll.

It is **highly recommended** to reuse a single instance of the client! The Elasticsearch .NET client is stateless. Parallel requests using the same instance is absolutely no problem at all.

> If other operations are executed on the same client between scrolls, it can clear the scroll context.

This is **not correct** either.

---

<div class="post-metadata">

**Author:** ![Moose](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Moose](https://discuss.elastic.co/u/Moose)\
**Post date:** [May 5, 2025, 5:05am UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/4 "2025-05-05T05:05:51Z")

</div>

Hi @Rafa_Silva and @flobernd thank you for the replies.

I do not think the scroll context is expiring. I'm using `.Scroll(10)` in my `SearchAsync` request so it should be staying for 10 minutes. I am also using `ClearScrollAsync` after my `SearchAsync` request **or** after my `ScrollAsync` request (if scrolling was needed) to ensure that the context isn't kept open needlessly.

In regards to your second point, I **am** using the same `ElasticClient` for all requests so there may be something going on there. @flobernd says the opposite though so I'm not certain. I can give it a try and see what happens at the least.

Regarding the point about Azure functions. I probably should have specified that I'm experiencing this while still doing local testing in Visual Studio. The end goal of this program is an Azure function but I haven't gotten that far yet, sorry for misguiding.

> [@Rafa\_Silva](#):
>
> Immediately call the next `ScrollAsync` without delay.

Fortunately I am doing that. I have an if conditional between the `SearchAsync` and `ScrollAsync` requests that determines if the latter is required, so there should be no meaningful delay between them. The entire `SearchAsync` and follow up `ScrollAsync` requests takes like 30 seconds right now.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [May 5, 2025, 7:48am UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/5 "2025-05-05T07:48:01Z")

</div>

> [@Moose](#):
>
> In regards to your second point, I **am** using the same `ElasticClient` for all requests so there may be something going on there. @flobernd says the opposite though so I'm not certain. I can give it a try and see what happens at the least.

Since I'm the current maintainer of the .NET client, I can definitely guarantee you that there is no context preserved on client-side and that using different client instances for each request will do nothing besides lowering your performance and increasing your resource consumption 😅

> [@Moose](#):
>
> I do not think the scroll context is expiring. I'm using `.Scroll(10)` in my `SearchAsync` request so it should be staying for 10 minutes.

The value specifies the amount of milliseconds, not minutes 😅

You can use `.Scroll(Timespan.FromMinutes(10))` instead to get the desired result.

---

<div class="post-metadata">

**Author:** ![Moose](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Moose](https://discuss.elastic.co/u/Moose)\
**Post date:** [May 5, 2025, 5:14pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/6 "2025-05-05T17:14:31Z")

</div>

> [@flobernd](#):
>
> The value specifies the amount of milliseconds, not minutes

Oh wow, that could certainly be the problem. Let me try changing it to actual minutes then haha. I've found the documentation for this NEST client very difficult to find so a lot of this I've had to go off of on my own. So I didn't realize that was for milliseconds. The intellisense in Visual Studio doesn't specify, it just says "Time".

---

<div class="post-metadata">

**Author:** ![Rafa\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafa_silva/32/147814_2.png) [@Rafa\_Silva](https://discuss.elastic.co/u/Rafa_Silva)\
**Post date:** [May 5, 2025, 8:23pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/7 "2025-05-05T20:23:31Z")

</div>

Good observation, since it is in milliseconds it may indeed be causing the problem. Test it and let us know the result, I hope everything works for you

---

<div class="post-metadata">

**Author:** ![Moose](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Moose](https://discuss.elastic.co/u/Moose)\
**Post date:** [May 6, 2025, 5:04am UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/8 "2025-05-06T05:04:27Z")

</div>

I'll be keeping an eye on it during my testing over the next week or so and will report back on my results.

---

<div class="post-metadata">

**Author:** ![Moose](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Moose](https://discuss.elastic.co/u/Moose)\
**Post date:** [May 13, 2025, 5:13pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/9 "2025-05-13T17:13:36Z")

</div>

@flobernd @Rafa_Silva I haven't had a ton of time to test out my app as much as I wanted to since my last message on here, but so far so good. I do think the mistaken timeout was probably my issue. I'll post again later when I've had more time to confirm this.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [May 13, 2025, 6:15pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/10 "2025-05-13T18:15:13Z")

</div>

Thanks for reporting back here!

---

<div class="post-metadata">

**Author:** ![Rafa\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafa_silva/32/147814_2.png) [@Rafa\_Silva](https://discuss.elastic.co/u/Rafa_Silva)\
**Post date:** [May 14, 2025, 10:03pm UTC](https://discuss.elastic.co/t/scrolling-api-seems-inconsistent/377763/11 "2025-05-14T22:03:10Z")

</div>

Thanks for the report, I hope it really solved your problem
