elasticsearch
runtime_error
ai_generated
partial
OutOfMemoryError:Java 堆空间(字段缓存驱逐)在加载字段 [user.name] 的字段数据时
OutOfMemoryError: Java heap space (field cache eviction) while loading fielddata for field [user.name]
ID: elasticsearch/field-cache-eviction-oom
74%修复率
83%置信度
1证据数
2024-04-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Elasticsearch 7.10.0 | active | — | — | — |
| Elasticsearch 8.9.0 | active | — | — | — |
| Elasticsearch 8.14.0 | active | — | — | — |
根因分析
用于文本字段聚合的字段数据缓存消耗过多堆内存,导致在缓存驱逐或加载期间发生 OutOfMemoryError。
English
The fielddata cache for aggregations on text fields consumes excessive heap memory, leading to an OutOfMemoryError during cache eviction or loading.
官方文档
https://www.elastic.co/guide/en/elasticsearch/reference/current/circuit-breaker.html#fielddata-circuit-breaker解决方案
-
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}}}` -
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.
无效尝试
常见但无效的做法:
-
65% 失败
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.
-
75% 失败
This can cause severe performance degradation because every aggregation will reload fielddata from disk, leading to high latency and potential OOM from concurrent loads.