# ScriptException: compilation of script [my_script] failed: too many dynamic script compilations within one minute

- **ID:** `elasticsearch/script-compilation-too-many-dynamic`
- **Domain:** elasticsearch
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.17.14 | active | — | — |
| 8.5.3 | active | — | — |
| 8.12.0 | active | — | — |

## Workarounds

1. **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 } }** (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 } }
   ```
2. **Increase the compilation rate limit temporarily: PUT /_cluster/settings { "transient": { "script.max_compilations_rate": "100/1m" } }** (75% success)
   ```
   Increase the compilation rate limit temporarily: PUT /_cluster/settings { "transient": { "script.max_compilations_rate": "100/1m" } }
   ```

## Dead Ends

- **** — Unlimited compilations can lead to high CPU usage, memory pressure, and potential denial of service. (85% fail)
- **** — This only delays the problem; if scripts are not cached, the rate will still be hit eventually with high load. (70% fail)
