elasticsearch
runtime_error
ai_generated
true
ScriptException: compilation of script [my_script] failed: too many dynamic script compilations within one minute
ID: elasticsearch/script-compilation-too-many-dynamic
80%Fix Rate
87%Confidence
1Evidence
2024-04-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.17.14 | active | — | — | — |
| 8.5.3 | active | — | — | — |
| 8.12.0 | active | — | — | — |
Root Cause
The cluster's script compilation rate exceeds the script.max_compilations_rate limit, typically due to generating unique scripts per query instead of using cached scripts.
generic中文
集群的脚本编译速率超过了 script.max_compilations_rate 限制,通常是因为每个查询生成唯一脚本而不是使用缓存脚本。
Official Documentation
https://www.elastic.co/guide/en/elasticsearch/reference/current/scripting.htmlWorkarounds
-
90% success Use stored scripts instead of inline scripts: POST _scripts/my_script { "script": { "lang": "painless", "source": "doc['field'].value * params.factor" } } then reference it in queries as "script": { "id": "my_script", "params": { "factor": 2 } }
Use stored scripts instead of inline scripts: POST _scripts/my_script { "script": { "lang": "painless", "source": "doc['field'].value * params.factor" } } then reference it in queries as "script": { "id": "my_script", "params": { "factor": 2 } } -
75% success Increase the compilation rate limit temporarily: PUT /_cluster/settings { "transient": { "script.max_compilations_rate": "100/1m" } }
Increase the compilation rate limit temporarily: PUT /_cluster/settings { "transient": { "script.max_compilations_rate": "100/1m" } }
中文步骤
使用存储脚本代替内联脚本:POST _scripts/my_script { "script": { "lang": "painless", "source": "doc['field'].value * params.factor" } } 然后在查询中引用为 "script": { "id": "my_script", "params": { "factor": 2 } }临时增加编译速率限制:PUT /_cluster/settings { "transient": { "script.max_compilations_rate": "100/1m" } }
Dead Ends
Common approaches that don't work:
-
85% fail
Unlimited compilations can lead to high CPU usage, memory pressure, and potential denial of service.
-
70% fail
This only delays the problem; if scripts are not cached, the rate will still be hit eventually with high load.