Closed
Description
Spring Data Elasticsearch version: 4.3.1
Java version: 11
The following exception is thrown when using Criteria.exists() on fields that are using a property converter (i.e. LocalDateTime).
java.lang.IllegalArgumentException: EXISTS has no value
at org.springframework.util.Assert.isTrue(Assert.java:121)
at org.springframework.data.elasticsearch.core.query.Criteria$CriteriaEntry.getValue(Criteria.java:999)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.lambda$updateCriteria$1(MappingElasticsearchConverter.java:1259)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateCriteria(MappingElasticsearchConverter.java:1258)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateCriteriaQuery(MappingElasticsearchConverter.java:1193)
at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateQuery(MappingElasticsearchConverter.java:1139)
at org.springframework.data.elasticsearch.core.RequestFactory.searchRequest(RequestFactory.java:901)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.search(ElasticsearchRestTemplate.java:316)
at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate.search(AbstractElasticsearchTemplate.java:410)
I think this happens because MappingElasticsearchConverter does not check if the values should be converted or not.
This is an example of how to reproduce the error:
@Document(indexName = "foo")
public class Foo {
@Field(name = "id", type = FieldType.Long)
private Long id;
@Field(name = "createdAt", type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
private LocalDateTime createdAt;
}
This query fails Criteria.where("createdAt").exists()
while this one works. Criteria.where("id").exists()
.