我有以下代码:
List<LawEntry> repealingLaw = findRepealingLawByDate(date);
界面如下:
public interface LawEntryRepository extends ElasticsearchRepository<LawEntry, String> {
public Page<LawEntry> findByLawNumberStartingWith(String LawNumber, Pageable pageable);
public List<LawEntry> findAllByRepealingTrueAndRepealingDateBetween(Date todayMin, Date todayMax);
我遇到以下异常:
Caused by: java.lang.IllegalArgumentException: Parse failure at index [0] of [Wed May 22 00:00:00 CEST 2019]
at org.elasticsearch.common.joda.DateMathParser.parseDateTime(DateMathParser.java:207)
... 25 common frames omitted
有人知道如何解决此问题吗?我怀疑这可能是一个映射问题,但是我在弹性搜索中没有发挥很多作用。
另请找到LawEntry的定义:
@Document(indexName = "law-index", type = "law-type") @Data @Builder @NoArgsConstructor @AllArgsConstructor
@Setting(settingPath = "/elastic/settings.json")
public static class LawEntry {
@Id private String id;
@Field(type = FieldType.Text, analyzer="nGram_analyzer", searchAnalyzer="whitespace_analyzer")
private String autocomplete;
private @Field(type = FieldType.Text, analyzer="nGram_analyzer", searchAnalyzer="whitespace_analyzer") String title;
private @Field(type = FieldType.Text, analyzer="nGram_analyzer", searchAnalyzer="whitespace_analyzer") String reference;
@Field(type = FieldType.Boolean, index = false) private boolean repealing= false;
@Field(type = FieldType.Date, index = false) private Date repealingDate;
@Field(type = FieldType.Date, index = false) private Date repealedDate;
@Field(type = FieldType.Date, index = false) private Date creationDate;
@Field(type = FieldType.Date, index = false) private Date lastUpdateDate;
}
我尝试再次更改代码,但出现异常。
更改:
@Field(type = FieldType.Date, index = false, format= org.springframework.data.elasticsearch.annotations.DateFormat.ordinal_date_time)
private Date repealingDate;
例外:
Caused by: java.lang.IllegalArgumentException: Invalid format: "1558519447840" is malformed at "7840"
at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
因此,发现执行一个特定查询时出现了问题。查询如下:
public interface DirectiveEntryRepository extends ElasticsearchRepository<DirectiveEntry, String> {
public List<DirectiveEntry> findAllByRepealingTrueAndRepealingDateBetween(Date todayMin, Date todayMax);