首页 > 解决方案 > 使用默认格式的 Elasticsearch 日期解析问题

问题描述

我的es版本是7.5.1

映射是:

"dynamic": "strict",
    "properties"{
     ...
    "memberDOB": {
    "type": "date"
    }
    ...
 }

根据此链接,https ://www.elastic.co/guide/en/elasticsearch/reference/current/date.html它说:

可以自定义日期格式,但如果未指定格式,则使用默认格式: "strict_date_optional_time||epoch_millis"

在将数据写入 es 时,纪元中的 memberDOB 值为 -3715200000,即 '1969-11-19',我遇到了这个问题: MapperParsingException [failed to parse field [memberDOB] of type [date] in document with id 'ACX03:xcxcxcxcxcxcxcxcxcxc '。字段值预览:'-3715200000']; 嵌套:NotSerializableExceptionWrapper [date_time_exception:年份的无效值(有效值-999999999 - 999999999):-3715200000]

从提到的例外情况来看,似乎纪元日期被视为 yyyy-mm-dd 格式。

我还更新了新索引中的格式"format":"strict_date_optional_time||epoch_millis"并尝试写入,但仍然出现相同的错误。

但是当我将格式更新为 时"format":"epoch_millis",它可以工作。

有人可以解释为什么会发生这种情况或我在这里缺少什么(默认格式)?

标签: javaelasticsearch

解决方案


推荐阅读