I'm switching from TransportClient
to RestHighLevelClient
in my app, which uses spring-data-elasticsearch
. When I try to save an entity with a field of type OffsetDateTime
, I get the following exeption:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [createdAt] of type [float]]]; nested: ElasticsearchException[Elasticsearch exception [type=json_parse_exception, reason=Current token (START_OBJECT) not numeric, can not use numeric value accessors
at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@2d7d44ce; line: 1, column: 35]]];] with root cause
org.elasticsearch.ElasticsearchException: Elasticsearch exception [type=json_parse_exception, reason=Current token (START_OBJECT) not numeric, can not use numeric value accessors
at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@2d7d44ce; line: 1, column: 35]]
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:509)
at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:420)
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:450)
at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:616)
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:169)
at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2050)
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:2026)
...
Here is my Elasticsearch config:
@Bean(destroyMethod = "close")
public RestHighLevelClient client() {
return new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchHost, elasticsearchPort)));
}
@Bean
public ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client) {
return new ElasticsearchRestTemplate(client);
}
And here is the simplified entity definition:
@Data
public class MyEntity {
@Field(type = FieldType.Date)
private OffsetDateTime createdAt;
}
What should I configure in order to be able to use fields of type OffsetDateTime
?