# Too many dynamic script compilations

**URL:** <https://discuss.elastic.co/t/too-many-dynamic-script-compilations/270932>\
**Category:** Kibana\
**Created:** [April 22, 2021, 7:47am UTC](https://discuss.elastic.co/t/too-many-dynamic-script-compilations/270932 "2021-04-22T07:47:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elk11](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@elk11](https://discuss.elastic.co/u/elk11)\
**Post date:** [April 22, 2021, 7:47am UTC](https://discuss.elastic.co/t/too-many-dynamic-script-compilations/270932/1 "2021-04-22T07:47:08Z")

</div>

Elasticsearch and Kibana version: 7.3.1  
Number of nodes: 5

In our documents we have a nested fields and since we wanted to create visualizations using those nested fields, we created scripted fields in Kibana management UI using painless. We have around _ **150** _ scripted fields in that particular index pattern.

Most of those scripted fields are similar like below:

```auto
    if (!doc['key.nestedKey'].empty) {
        return params['_source']['key']['nestedKey']
    }
    return null

```

And we have increased `max_compilation_rate` to `1000/1m`.

So with all the above configuration, sometimes when filtering on a scripted field from Kibana discover, we get following error:

`Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"circuit_breaking_exception","reason":"[script] Too many dynamic script compilations within, max: [1000/1m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting","bytes_wanted":0,"bytes_limit":0,"durability":"TRANSIENT"},`

So I wanted to get some recommendation on how to approach this issue. When previously we had hit this issue, we just increased the limit. But I guess there's a better way to handle this.

We are also seeing occasional `x of y shards failed` while doing some Kibana searches. Nothing stands out in elasticsearch logs. Not sure if this is related to same problem.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [April 22, 2021, 2:59pm UTC](https://discuss.elastic.co/t/too-many-dynamic-script-compilations/270932/2 "2021-04-22T14:59:04Z")

</div>

The main recommendation is to convert those scripted fields into actual fields. There isn't really another way to make them suited for production.  
Depending on how much data you have, reindex might be a good solution.  
But if you have a lot of data, but only query recent data, ingest pipelines to do the processing needed on your fields before ingest is the best solution.

---

<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:** [May 20, 2021, 2:59pm UTC](https://discuss.elastic.co/t/too-many-dynamic-script-compilations/270932/3 "2021-05-20T14:59:44Z")

</div>

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