# Circuit\_breaking\_exception: \[script\] Too many dynamic script compilations within, max: \[1000/5m\]

**URL:** <https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 3, 2023, 6:36am UTC](https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002 "2023-08-03T06:36:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zephery\_Wen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zephery_wen/32/124417_2.png) [@Zephery\_Wen](https://discuss.elastic.co/u/Zephery_Wen)\
**Post date:** [August 3, 2023, 6:36am UTC](https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002/1 "2023-08-03T06:36:13Z")

</div>

I created a stored script in elasticsearch

```json
GET _scripts/xxx-script
{
  "_id": "xxx-script",
  "found": true,
  "script": {
    "lang": "painless",
    "source": "ctx._source.a = params.a;ctx._source.b = params.b;ctx._source.c = params.c;ctx._source.d = params.d;ctx._source.e = params.@timestamp;"
  }
}

```

Then i try to save or update my data into a index, here is my code:

```java
Map<String, String> map = new HashMap<>();
map.put("es.mapping.id", "_id");
map.put(ConfigurationOptions.ES_WRITE_OPERATION, "upsert");

map.put(ConfigurationOptions.ES_UPDATE_SCRIPT_PARAMS, "a:a,b:b,c:c,d:d,@timestamp:for_update_time");
map.put(ConfigurationOptions.ES_UPDATE_SCRIPT_STORED, "xxx-script");
JavaEsSparkSQL.saveToEs(repartition, outputIndex, map);

```

It always reports this error

```plaintext
circuit_breaking_exception: [script] Too many dynamic script compilations within, max: [1000/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.context.update.max_compilations_rate] 

```

How to solve it?

Thank you

---

<div class="post-metadata">

**Author:** ![Zephery\_Wen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zephery_wen/32/124417_2.png) [@Zephery\_Wen](https://discuss.elastic.co/u/Zephery_Wen)\
**Post date:** [August 3, 2023, 11:45am UTC](https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002/3 "2023-08-03T11:45:07Z")

</div>

I've confirm only one script\_ in this cluster

```plaintext
GET _cluster/state/metadata?pretty&filter_path=**.stored_scripts

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 3, 2023, 2:25pm UTC](https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002/4 "2023-08-03T14:25:38Z")

</div>

Take a look at [this](https://www.elastic.co/guide/en/elasticsearch/reference/8.9/modules-scripting-using.html#script-stored-scripts) example and model yours after it with the syntax for the params see if that makes a difference ... right now it seems it is compiling every time

`source": "ctx._source.a = params['a'];...`

---

<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 31, 2023, 2:25pm UTC](https://discuss.elastic.co/t/circuit-breaking-exception-script-too-many-dynamic-script-compilations-within-max-1000-5m/340002/5 "2023-08-31T14:25:41Z")

</div>

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