# Unkown script compilations for template-context in script-cache

**URL:** <https://discuss.elastic.co/t/unkown-script-compilations-for-template-context-in-script-cache/325707>\
**Category:** Elasticsearch\
**Created:** [February 16, 2023, 9:43am UTC](https://discuss.elastic.co/t/unkown-script-compilations-for-template-context-in-script-cache/325707 "2023-02-16T09:43:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Hans](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@The\_Hans](https://discuss.elastic.co/u/The_Hans)\
**Post date:** [February 16, 2023, 9:43am UTC](https://discuss.elastic.co/t/unkown-script-compilations-for-template-context-in-script-cache/325707/1 "2023-02-16T09:43:02Z")

</div>

Hi,

from time to time we are facing a 'circuit\_breaking\_exception' caused by 'Too many dynamic script compilations within, max: [75/5m]'

We only use 2 score\_scripts to re-rank the score of documents. These 2 scripts using parameters and ist seems they are not causing the above problem.

When we look into the script-cache:

```auto
GET /_nodes/stats?metric=script&filter_path=nodes.*.script.*
{
  "nodes" : {
    "_4Z2Cur6Qem_yiz11wzN3Q" : {
      "script" : {
        "compilations" : 985845,
        "cache_evictions" : 985699,
        "compilation_limit_triggered" : 1778
      }
    },
    "pt9TnJkLQEexDLlKkx_vpQ" : {
      "script" : {
        "compilations" : 1029367,
        "cache_evictions" : 1029250,
        "compilation_limit_triggered" : 2239
      }
    },
    "MsGjak10Q3i3AVKWv8QzHA" : {
      "script" : {
        "compilations" : 818710,
        "cache_evictions" : 818594,
        "compilation_limit_triggered" : 2009
      }
    }
  }
}

```

There are a lot of compilations happening and the compilation limit is reached quite often...  
The compilations are increasing constantly little by little, but sometimes quite fast.

When we look into the cache a little bit deeper:

```auto
GET /_nodes/stats?metric=script_cache
"script_cache" : {
        "sum" : {
          "compilations" : 985845,
          "cache_evictions" : 985699,
          "compilation_limit_triggered" : 1778
        },
        "contexts" : [
          ...
          {
            "context" : "score",
            "compilations" : 2,
            "cache_evictions" : 0,
            "compilation_limit_triggered" : 0
          },
          ...
          {
            "context" : "template",
            "compilations" : 985822,
            "cache_evictions" : 985722,
            "compilation_limit_triggered" : 1778
          },
          ...

```

You can see, the 2 score\_scripts are only compiled twice. The problem part seems to be the template-context.

Our question would be:  
What is the template-context in the script\_cache and what features, technologies, plugins etc.. is contributing to the template-context. We want to get a better understand what is going on behind the scenes, maybe we are using some feature that we are not aware off and we could fix the problem be deactivating it...

Many thanks,

Hans

---

<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:** [March 16, 2023, 9:43am UTC](https://discuss.elastic.co/t/unkown-script-compilations-for-template-context-in-script-cache/325707/2 "2023-03-16T09:43:06Z")

</div>

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