# OutOfMemoryError: Java heap space: failed to allocate field data for field [user.id]

- **ID:** `elasticsearch/field-cache-too-large`
- **Domain:** elasticsearch
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 72%

## Root Cause

The fielddata cache for a high-cardinality field (e.g., user.id) consumes too much heap memory, triggering an OutOfMemoryError.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.17.0 | active | — | — |
| 8.10.0 | active | — | — |
| 8.12.1 | active | — | — |

## Workarounds

1. **Set a fielddata circuit breaker limit: PUT _cluster/settings { "persistent": { "indices.breaker.fielddata.limit": "30%" } } and also set fielddata cache size: PUT _cluster/settings { "persistent": { "indices.fielddata.cache.size": "20%" } }** (85% success)
   ```
   Set a fielddata circuit breaker limit: PUT _cluster/settings { "persistent": { "indices.breaker.fielddata.limit": "30%" } } and also set fielddata cache size: PUT _cluster/settings { "persistent": { "indices.fielddata.cache.size": "20%" } }
   ```
2. **Use doc_values instead of fielddata by reindexing the field with doc_values: true; for keyword fields, doc_values is enabled by default, so avoid aggregating on text fields without doc_values** (90% success)
   ```
   Use doc_values instead of fielddata by reindexing the field with doc_values: true; for keyword fields, doc_values is enabled by default, so avoid aggregating on text fields without doc_values
   ```

## Dead Ends

- **** — Larger heap may postpone OOM but fielddata can grow unbounded; eventually OOM recurs (75% fail)
- **** — Disabling fielddata breaks aggregations and sorting on that field; queries that depend on it will fail (80% fail)
