# OutOfMemoryError: Java heap space (field cache eviction) while loading fielddata for field [user.name]

- **ID:** `elasticsearch/field-cache-eviction-oom`
- **Domain:** elasticsearch
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 74%

## Root Cause

The fielddata cache for aggregations on text fields consumes excessive heap memory, leading to an OutOfMemoryError during cache eviction or loading.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Elasticsearch 7.10.0 | active | — | — |
| Elasticsearch 8.9.0 | active | — | — |
| Elasticsearch 8.14.0 | active | — | — |

## Workarounds

1. **Enable `eager_fielddata` on the field mapping to preload fielddata at index time, reducing peak memory usage during queries. Update mapping: `PUT my_index/_mapping {"properties": {"user.name": {"type": "text", "fielddata": true, "eager_fielddata": true}}}`** (80% success)
   ```
   Enable `eager_fielddata` on the field mapping to preload fielddata at index time, reducing peak memory usage during queries. Update mapping: `PUT my_index/_mapping {"properties": {"user.name": {"type": "text", "fielddata": true, "eager_fielddata": true}}}`
   ```
2. **Limit the fielddata cache size and set a circuit breaker. Configure in `elasticsearch.yml`: `indices.fielddata.cache.size: 20%` and `indices.breaker.fielddata.limit: 40%`. Then restart the node.** (76% success)
   ```
   Limit the fielddata cache size and set a circuit breaker. Configure in `elasticsearch.yml`: `indices.fielddata.cache.size: 20%` and `indices.breaker.fielddata.limit: 40%`. Then restart the node.
   ```

## Dead Ends

- **** — This only postpones the OOM error; large aggregations on high-cardinality text fields can still exhaust memory, and large heaps can cause longer GC pauses. (65% fail)
- **** — This can cause severe performance degradation because every aggregation will reload fielddata from disk, leading to high latency and potential OOM from concurrent loads. (75% fail)
