# Getting "too many scroll contexts" when re-indexing

**URL:** <https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065>\
**Category:** Elasticsearch\
**Tags:** reindex\
**Created:** [July 19, 2021, 1:11pm UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065 "2021-07-19T13:11:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![malsioufi](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@malsioufi](https://discuss.elastic.co/u/malsioufi)\
**Post date:** [July 19, 2021, 1:11pm UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065/1 "2021-07-19T13:11:26Z")

</div>

Hi,

I have a task where I need to sort by the field "\_id" I knew that I should not use this field for sorting and that instead it is better to add an extra field the has the same value as \_id and then I can use that field for sorting. In order to achieve that I am trying to reindex my data.

```auto
POST _reindex?refresh
{
  "source": {
    "index": "my_original_index"
  },
  "dest": {
    "index": "my_new_index"
  },
  "script": {
    "source": "ctx._source.document_id = ctx._id"
  }
}

```

However, when I try to run the previous code I got the following error:  
`Trying to create too many scroll contexts. Must be less than or equal to: [500]. This limit can be set by changing the [search.max_open_scroll_context] setting.`

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 19, 2021, 1:54pm UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065/2 "2021-07-19T13:54:42Z")

</div>

Are you using scroll searches in your regular operations already? Or is that index consisting of a lot of shards?

---

<div class="post-metadata">

**Author:** ![malsioufi](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@malsioufi](https://discuss.elastic.co/u/malsioufi)\
**Post date:** [July 19, 2021, 5:23pm UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065/3 "2021-07-19T17:23:25Z")

</div>

The index has 5 shards.  
The index is used as a data source for a React application that is built with Reactivesearch and I think they do use scroll searches to get the data.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 20, 2021, 8:47am UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065/4 "2021-07-20T08:47:46Z")

</div>

then there are probably a lot of scroll searches going on in parallel. Scroll searches are not supposed to be used by applications with many parallel queries.

In order to fix this, you could swithc those queries to use a single PointInTime reader and then update that one regularly, like every minute or thirty seconds. See [Point in time API | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.13/point-in-time.html)

---

<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:** [August 17, 2021, 8:48am UTC](https://discuss.elastic.co/t/getting-too-many-scroll-contexts-when-re-indexing/279065/5 "2021-08-17T08:48:19Z")

</div>

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