java localdatetime对应 elasticSearch 什么类型


问一下我用了spring-elasticSearch-data框架,但没找到LocalDateTime类型对应es里面是什么类型,就这里type = FieldType.Date 会报错,auto也会报错,有老哥怎么应该填什么吗

springboot2.3 elasticsearch-data 4.0.9

[org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDateTime]]

ES专家 @zhaoyang01 来看看。

不过,你还是把异常的堆栈信息复制出来啊。

假如换成type = FieldType.Date启动报错 ,假如是type = FieldType.Auto会运行报错

[org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDateTime]]

你在 @Field 上添加 pattern属性试试看

@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")


我查出来时间为null,尴尬 :sweat_smile:,我用的LocalDateTime的utc时间,其实也不想转换格式

你修改一下 format 试试看,例如
@Field (type = FieldType.Date, format = DateFormat.epoch_millis)

我对这个也不熟

恩,暂时多试试了



@Field(type = FieldType.Date, format = DateFormat.basic_date_time) 用这个format就可以了

1 个赞