# 内存溢出：Java堆空间：无法为字段[user.id]分配字段数据

- **ID:** `elasticsearch/field-cache-too-large`
- **领域:** elasticsearch
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 72%

## 根因

高基数字段（例如user.id）的字段数据缓存消耗过多堆内存，触发内存溢出错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.17.0 | active | — | — |
| 8.10.0 | active | — | — |
| 8.12.1 | active | — | — |

## 解决方案

1. ```
   设置字段数据断路器限制：PUT _cluster/settings { "persistent": { "indices.breaker.fielddata.limit": "30%" } }，同时设置字段数据缓存大小：PUT _cluster/settings { "persistent": { "indices.fielddata.cache.size": "20%" } }
   ```
2. ```
   使用doc_values代替fielddata：重新索引字段并启用doc_values: true；对于keyword字段，doc_values默认启用，因此避免在没有doc_values的text字段上进行聚合
   ```

## 无效尝试

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