ES插入date类型数据报错failed to parse field [case_date] of type [date]

ES插入date类型数据报错

mapping信息如下

{
  "mappings": {
    "_doc": {
      "properties": {
        "id": {
          "type": "integer"
        },
        "case_date": {
          "type": "date"
        }
      }
    }
  }
}

index创建完毕之后插入数据报错,信息如下:
{
“id”: 20001,
“case_date”: “2021-05-18 13:58:01”
}在这里插入图片描述

{
	"error": {
		"root_cause": [
			{
				"type": "mapper_parsing_exception",
				"reason": "failed to parse field [case_date] of type [date]"
			}
		],
		"type": "mapper_parsing_exception",
		"reason": "failed to parse field [case_date] of type [date]",
		"caused_by": {
			"type": "illegal_argument_exception",
			"reason": "Invalid format: "2021-05-18 13:58:01" is malformed at " 13:58:01""
		}
	},
	"status": 400
}

解决方法,修改mapping如下:

{
  "mappings": {
    "_doc": {
      "properties": {
        "id": {
          "type": "integer"
        },
        "case_date": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        }
      }
    }
  }
}

重新创建index之后再次插入数据成功
在这里插入图片描述
ES的日期类型表示格式可以是以下几种:
(1)日期格式的字符串,比如 “2018-01-13” 或 “2018-01-13 12:10:30”
(2)long类型的毫秒数( milliseconds-since-the-epoch,epoch就是指UNIX诞生的UTC时间1970年1月1日0时0分0秒)
(3)integer的秒数(seconds-since-the-epoch)

ElasticSearch 内部会将日期数据转换为UTC,并存储为milliseconds-since-the-epoch的long型整数。

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值