# IllegalArgumentException: 索引 [logs-2025] 中类型为 [keyword] 的字段 [user.name] 长度为 [32768]，超过了最大允许长度 32766

- **ID:** `elasticsearch/field-length-exceeds-keyword-limit`
- **领域:** elasticsearch
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

文档中的关键字字段值超过了 32766 字节的限制，导致索引被拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.10.0 | active | — | — |
| 8.10.0 | active | — | — |
| 8.13.0 | active | — | — |

## 解决方案

1. ```
   将字段类型更改为 `text` 并添加 `keyword` 子字段用于精确匹配：`PUT my_index/_mapping { "properties": { "user.name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }`。
   ```
2. ```
   在应用程序级别截断字段值，确保其小于 32766 字节后再索引。
   ```
3. ```
   使用带有 `ignore_above` 设置的 `keyword` 字段，设置值小于 32766 以跳过索引长值。
   ```

## 无效尝试

- **** — `ignore_above` truncates the field, it does not increase the keyword length limit. (80% 失败率)
- **** — Removing `ignore_above` does not change the hard byte limit for keyword fields. (90% 失败率)
- **** — Reindexing without addressing the field type will still reject large values. (85% 失败率)
