spring-boot - 搜索时的Spring数据弹性搜索日期问题
问题描述
我正在使用 spring-boot-starter-parent 2.5.4 和 elasticsearch 7.12.1 并且基本上能够成功插入带有 createDate 作为字段但无法搜索的文档。
我有一个 Spring rest webservice,它包含按日期范围搜索的搜索功能,并包含下面的 json 请求:
{
"dateTo": "20210901T152702.620+04:00",
"dateFrom": "20200901T152702.620+04:00"
但是,当执行 createdDate 的搜索时,会显示以下错误:
021-09-01 15:45:18.149 WARN 19588 --- [nio-9088-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.ZonedDateTime` from String "20210901T152702.620+04:00": Failed to deserialize java.time.ZonedDateTime: (java.time.format.DateTimeParseException) Text '20210901T152702.620+04:00' could not be parsed at index 0; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.ZonedDateTime` from String "20210901T152702.620+04:00": Failed to deserialize java.time.ZonedDateTime: (java.time.format.DateTimeParseException) Text '20210901T152702.620+04:00' could not be parsed at index 0e
请在下面找到我的文档:
public class Logging {
@Id
private String id;
@Field(type = FieldType.Text, name = "username")
private String username;
@Field(type = FieldType.Date, format = DateFormat.basic_date_time)
private ZonedDateTime createdDate = ZonedDateTime.now();
}
我的请求如下所示:
public class LoggingSearchCriteria extends AbstractSearchRequest {
private ZonedDateTime dateTo;
private ZonedDateTime dateFrom;
}
知道为什么在执行搜索命令时出现此错误吗?
提前致谢