irpas技术客

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

irpas 7669

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型整数。


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #To #Parse #field #case_date #of #type #date