遇到的问题: 

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [updateTime] of type [date] in document with id '57'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [updateTime] of type [date] in document with id '57'","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: "2025-03-13T07:57:53.000Z" is malformed at "T07:57:53.000Z""}},"status":400}
at org.elasticsearch.client.RestClientSyncResponseListener.get(RestClient.java:936) at org.elasticsearch.client.RestClient.performRequest(RestClient.java:233) at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1764) ... 98 common frames omitted Caused by: org.elasticsearch.client.ResponseException: method [POST], host [http://127.0.0.1:9200], URI [/wk_single_make/_doc/57/_update?doc_as_upsert=true&timeout=1m], status line [HTTP/1.1 400 Bad Request] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [updateTime] of type [date] in document with id '57'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [updateTime] of type [date] in document with id '57'","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: \"2025-03-13T07:57:53.000Z\" is malformed at \"T07:57:53.000Z\""}},"status":400} at org.elasticsearch.client.RestClient1.completed(RestClient.java:552)

遇到的问题:

错误信息显示,日期字段updateTime的格式是"2025-03-13T07:57:53.000Z",但Elasticsearch的映射期望的是"yyyy-MM-dd HH:mm:ss"格式,导致解析失败 

 

简单的理解就是就是时间格式不准确:
于是我更新了一下我的时间格式在es里面:

解决方案:

可能会出现,索引已经存在的错误那样的话,删掉即可。

 # 2. 创建新索引,并定义映射
PUT /wk_single_make
{
  "mappings": {
    "_doc": {
      "properties": {
        "updateTime": {
          "type": "date",
          "format": "strict_date_optional_time||yyyy-MM-dd HH:mm:ss"
        },
        "createTime": {
          "type": "date",
          "format": "strict_date_optional_time||yyyy-MM-dd HH:mm:ss"
        }
      }
    }
  }
}

 这样就好了。

 

同时我也更新了一下实体类让其格式一致:

 

 

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐