# Max\_open\_scroll\_context, scroll\_ids, and shards

**URL:** <https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872>\
**Category:** Elasticsearch\
**Created:** [October 30, 2020, 9:51pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872 "2020-10-30T21:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Cayanan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_cayanan/32/78185_2.png) [@Michael\_Cayanan](https://discuss.elastic.co/u/Michael_Cayanan)\
**Post date:** [October 30, 2020, 9:51pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872/1 "2020-10-30T21:51:01Z")

</div>

Hi. I'm making a query across several indices with 8 shards per index. To be specific it ends up being about 752 shards in total.

When I make a scroll query, I initially get that

`Trying to create too many scroll contexts`

error since I'm going over the 500 default limit. I'm making sure that we are deleting the scroll\_ids every time we finish the scroll functionality. So I increase the max\_open\_scroll\_context limit it to a larger number like `1500` and now the scroll query works fine and no longer errors out.

I guess my question is, is the number of shards equal to the number of max\_open\_scroll\_context ? It seems like ElasticSearch needs to open as many scroll contexts as there is shards. If that is true, why is that the case?

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [November 1, 2020, 2:51pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872/2 "2020-11-01T14:51:46Z")

</div>

Hi @Michael_Cayanan,

yes, it will need a search context per shard, but the limit is per node. I am guessing your setup is a single node setup? Using 8 shards per index, it sounds like you are planning to scale out the deployment? If not, you could likely benefit from having fewer shards per index.

Elasticsearch needs a search context per shard it searches. When using scrolls, Elasticsearch will in many cases need to keep those search contexts alive for the duration of the scroll. For non-scroll searches, the search context can be closed as soon as we know what the top hits of the query are.

---

<div class="post-metadata">

**Author:** ![Michael\_Cayanan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_cayanan/32/78185_2.png) [@Michael\_Cayanan](https://discuss.elastic.co/u/Michael_Cayanan)\
**Post date:** [November 2, 2020, 4:14pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872/3 "2020-11-02T16:14:22Z")

</div>

Hi @HenningAndersen. Thanks for the explanation on how scrolling works in relation to shards. Regarding my setup, I believe we do plan on scaling out if need be. But just curious, if we maintained a single node setup, how many shards per index would you recommend?

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [November 6, 2020, 1:39pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872/4 "2020-11-06T13:39:03Z")

</div>

1 primary shard (which is also default) is fine in most cases, in particular for single node setups. If you have multiple nodes and one index is more heavily ingested into or searched against, partitioning into multiple shards makes sense.

---

<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:** [December 4, 2020, 1:39pm UTC](https://discuss.elastic.co/t/max-open-scroll-context-scroll-ids-and-shards/253872/5 "2020-12-04T13:39:09Z")

</div>

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