【发布时间】:2020-07-26 16:19:27
【问题描述】:
拥有这个 SearchQuery:
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(QueryBuilders.rangeQuery("updateTime").gte(LocalDate.now())).build();
final List<ActivityValue> listOf = elasticsearchTemplate.queryForList(searchQuery, ActivityValue.class);
使用实体 ActivityValue:
@Document(indexName = "tracking1", type = "activity")
public class ActivityValue {
@Id
private String id;
@Field(type = FieldType.Date, index = false, store = true, format = DateFormat.custom, pattern = "yyyy-MM-dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate updateTime;
@Field(type = FieldType.Object, includeInParent = true)
private Vendor vendor;
@Field(type = FieldType.Object, includeInParent = true)
private QCriteria quality;
public ActivityValue() {
}
//setter and getter
}
如果我运行查询并尝试接收列表,则会出现以下异常:
caused by: java.io.IOException: can not write type [class java.time.LocalDate]
实体之前存储的实际日期为 LocalDate。 我不确定查询弹性搜索和解决此错误的最佳/最简单方法是什么。有人可以帮忙吗?
【问题讨论】:
-
是的,
localDate.toString()似乎解决了上述异常。如果@tn-nguyen 也解决了您的问题,则应该接受它作为答案。
标签: spring elasticsearch