# AWS Elastic Search update\_by\_query : Trying to create too many scroll contexts

**URL:** <https://discuss.elastic.co/t/aws-elastic-search-update-by-query-trying-to-create-too-many-scroll-contexts/344745>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 10, 2023, 1:48pm UTC](https://discuss.elastic.co/t/aws-elastic-search-update-by-query-trying-to-create-too-many-scroll-contexts/344745 "2023-10-10T13:48:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitpandoh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankitpandoh/32/125219_2.png) [@ankitpandoh](https://discuss.elastic.co/u/ankitpandoh)\
**Post date:** [October 10, 2023, 1:48pm UTC](https://discuss.elastic.co/t/aws-elastic-search-update-by-query-trying-to-create-too-many-scroll-contexts/344745/1 "2023-10-10T13:48:53Z")

</div>

I am getting below exception while running the update\_by\_query. We have been issuing this request to through Rest API (from our code) to OpensearchCluster in AWS.  
Initially it seems ok, but when we have a sudden burst of request somewhere around 21k, we started getting this exception.  
We have 2 indices and We are using 5 shards and 2 replica per index in OpenSearch.

```auto
org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException: 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.

```

The sample query looks like below

```auto
POST /<index-name>/_update_by_query
{
  "script": {
    "inline":"""
     ctx._source['customers.name'] = params.name;
      """,
    "lang": "painless",
    "params":{
      "name": "ankit gupta"
    }
  },
  "query": {
    "term": {
      "customers.handle.keyword": "date_user01"
    }
  }
}

```

1. Are we getting this exception because we overwhelmed the Opensearch with http requests? We can not use bulk api as an option, as we are updating documents in the indexes whenever there is an event occurred.
2. Should we use scroll parameter in the term request?
3. How should we handle it when we have such large number of events happening across the application? What are the best practices to solve such use cases?

---

<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:** [October 10, 2023, 1:48pm UTC](https://discuss.elastic.co/t/aws-elastic-search-update-by-query-trying-to-create-too-many-scroll-contexts/344745/2 "2023-10-10T13:48:53Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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:** [November 7, 2023, 1:49pm UTC](https://discuss.elastic.co/t/aws-elastic-search-update-by-query-trying-to-create-too-many-scroll-contexts/344745/3 "2023-11-07T13:49:09Z")

</div>

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