You need to enable JavaScript to run this app. Elasticsearch 7.10.1 日期解析强制要求秒级3位小数问题排查与解决
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch 7.10.1 日期解析强制要求秒级3位小数问题排查与解决

Elasticsearch 7.10.1 日期解析异常问题排查与解决

问题现象

当前使用的Elasticsearch版本为7.10.1,对应索引的utcTime字段date类型映射配置如下:

"utcTime": {
  "type": "date",
  "format": "strict_date_optional_time_nanos"
}

部分文档可正常写入,例如utcTime字段为3位秒级小数的时间值:

"utcTime": "2021-02-17T09:50:13.173Z"
"utcTime": "2021-02-17T09:51:44.158Z"

但秒级小数为2位的时间值写入时会被拒绝,抛出如下解析异常:

"utcTime": "2021-02-17T09:51:45.07Z"

illegal_argument_exception: failed to parse date field [2021-02-17T09:51:45.07Z] with format [yyyy-MM-dd''T''HH:mm:ss.SSSXX]

业务侧使用Newtonsoft.Json.NET序列化时间,原本预期固定输出3位秒级小数,但实际配置未生效,需要实现Elasticsearch端支持秒级小数位数在0到3位之间的任意ISO格式时间。

根因定位

排查确认问题与上述索引映射配置无关,异常触发点为ingest管道的date_index_name处理器。
未配置日期格式参数的原始管道配置如下:

PUT _ingest/pipeline/test_reroute_pipeline
{
  "description" : "Route documents to another index",
  "processors" : [
    {
      "date_index_name": {
        "field": "utcTime",
        "date_rounding": "d",
        "index_name_prefix": "rerouted-"
      }
    }
  ]
}

该处理器未显式声明date_formats参数时,会自动记住首次接收到的日期格式作为全局校验规则:如果首次接收的时间为2位小数,后续所有请求都会强制要求2位小数格式;如果首次为3位小数,后续就强制要求3位小数格式,这是格式校验不通过的核心原因。

解决方案

在date_index_name处理器中显式指定支持任意小数位的ISO8601日期格式,修改后的管道配置如下:

PUT _ingest/pipeline/test_reroute_pipeline
{
  "description" : "Route documents to another index",
  "processors" : [
    {
      "date_index_name": {
        "field": "utcTime",
        "date_rounding": "d",
        "index_name_prefix": "rerouted-",
        "date_formats": ["ISO8601"]
      }
    }
  ]
}

配置生效后,即可正常解析秒级小数位数在0到3位之间的时间值,异常问题彻底解决。

内容的提问来源于stack exchange,提问作者aspyct

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.03 19:15:02