[英]How to solve the Elasticsearch failing when searching by LocalDate.MAX?
我正在使用 Spring 数据 Elasticsearch 搜索2010-01-01
和LocalDate.MAX
之间的内容,但失败:
nested: ElasticsearchException[Elasticsearch exception [type=arithmetic_exception, reason=long overflow]]
有springDataElasticsearchRepository.findByAgeBetween(startLocalDate, endLocalDate)
。
Elasticsearch 接受的最大日期是多少,否则应如何避免此错误?
Elasticsearch 将日期存储为长值,表示自纪元以来的毫秒数。 如果您运行以下代码
public static void main(String[] args) {
long maxLong = Long.MAX_VALUE;
Instant instant = Instant.ofEpochMilli(maxLong);
ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC"));
LocalDate localDate = LocalDate.from(zonedDateTime);
System.out.println(localDate);
}
你会得到
+292278994-08-17
作为可表示的最大日期。 最大LocalDate
值为
+999999999-12-31
使用springDataElasticsearchRepository.findByAgeBetween(Optional<LocalDate> startLocalDate, Optional<LocalDate> endLocalDate)
可以避免引起麻烦的LocalDate.MIN
和LocalDate.MAX
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.