elasticsearch
data_error
ai_generated
true
映射解析异常:无法解析文档 ID 'doc123' 中类型为 [date] 的字段 [created_at]。字段值预览:'2024-13-01'
MapperParsingException: failed to parse field [created_at] of type [date] in document with id 'doc123'. Preview of field's value: '2024-13-01'
ID: elasticsearch/mapping-conflict-on-date-format
90%修复率
87%置信度
1证据数
2024-09-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| elasticsearch 7.17 | active | — | — | — |
| elasticsearch 8.11 | active | — | — | — |
| elasticsearch 8.12 | active | — | — | — |
根因分析
字段值与映射中定义的预期日期格式不匹配,例如无效月份或时间戳模式不匹配。
English
The field value does not match the expected date format defined in the mapping, such as an invalid month or a mismatched timestamp pattern.
官方文档
https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html解决方案
-
更新索引映射以接受多种日期格式:PUT /my_index/_mapping { "properties": { "created_at": { "type": "date", "format": "yyyy-MM-dd||yyyy/MM/dd||epoch_millis" } } } -
使用摄取管道在索引前预处理日期字段:PUT _ingest/pipeline/date_fix { "description": "修复日期格式", "processors": [ { "date": { "field": "created_at", "target_field": "created_at", "formats": [ "yyyy-MM-dd" ], "timezone": "UTC", "locale": "en" } } ] } -
使用脚本重新索引数据以转换日期:POST _reindex { "source": { "index": "my_index" }, "dest": { "index": "my_index_new" }, "script": { "source": "if (ctx._source.created_at == '2024-13-01') { ctx._source.created_at = '2024-01-01' }" } }
无效尝试
常见但无效的做法:
-
70% 失败
Converting date to text loses date-related query capabilities (e.g., range queries, date histograms) and may break existing queries.
-
60% 失败
This only masks the issue; malformed dates are stored as null, leading to data loss and unexpected query results.
-
65% 失败
If the incoming data uses a different format (e.g., 'yyyy/MM/dd'), it will still fail after re-creation.