# ElasticsearchException: [script_cache] eviction triggered, current heap usage [92%], max cache size [10000]

- **ID:** `elasticsearch/script-cache-eviction-memory-pressure`
- **Domain:** elasticsearch
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

The script cache is full and heap memory usage is high, causing Elasticsearch to evict compiled scripts to free memory, which degrades performance.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.17.14 | active | — | — |
| 8.11.0 | active | — | — |
| 8.14.0 | active | — | — |

## Workarounds

1. **Increase the script cache size in elasticsearch.yml: script.cache.max_size: 20000 and restart nodes, or use dynamic setting: PUT _cluster/settings { "transient": { "script.cache.max_size": "20000" } }** (80% success)
   ```
   Increase the script cache size in elasticsearch.yml: script.cache.max_size: 20000 and restart nodes, or use dynamic setting: PUT _cluster/settings { "transient": { "script.cache.max_size": "20000" } }
   ```
2. **Reduce script variety by parameterizing inline scripts: use stored scripts or parameters instead of generating unique script sources per query, e.g., { "script": { "id": "my_script", "params": { "factor": 2 } } }** (90% success)
   ```
   Reduce script variety by parameterizing inline scripts: use stored scripts or parameters instead of generating unique script sources per query, e.g., { "script": { "id": "my_script", "params": { "factor": 2 } } }
   ```

## Dead Ends

- **** — Larger heap may delay eviction but does not fix the root cause of too many unique scripts being compiled; cache still fills up (60% fail)
- **** — Disabling the cache forces recompilation on every script execution, causing severe performance degradation and potential OOM (90% fail)
