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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html

解决方案

  1. 更新索引映射以接受多种日期格式:PUT /my_index/_mapping { "properties": { "created_at": { "type": "date", "format": "yyyy-MM-dd||yyyy/MM/dd||epoch_millis" } } }
  2. 使用摄取管道在索引前预处理日期字段:PUT _ingest/pipeline/date_fix { "description": "修复日期格式", "processors": [ { "date": { "field": "created_at", "target_field": "created_at", "formats": [ "yyyy-MM-dd" ], "timezone": "UTC", "locale": "en" } } ] }
  3. 使用脚本重新索引数据以转换日期: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' }" } }

无效尝试

常见但无效的做法:

  1. 70% 失败

    Converting date to text loses date-related query capabilities (e.g., range queries, date histograms) and may break existing queries.

  2. 60% 失败

    This only masks the issue; malformed dates are stored as null, leading to data loss and unexpected query results.

  3. 65% 失败

    If the incoming data uses a different format (e.g., 'yyyy/MM/dd'), it will still fail after re-creation.