spring-data-elasticsearch,Spring Boot,spring Data Elasticsearch" /> spring-data-elasticsearch,Spring Boot,spring Data Elasticsearch" />

Spring boot Springframework数据Elasticsearch无法创建类java.time.ZonedDateTime的对象

Spring boot Springframework数据Elasticsearch无法创建类java.time.ZonedDateTime的对象,spring-boot,spring-data-elasticsearch,Spring Boot,spring Data Elasticsearch,我正在使用推荐的RestHightCLient和ElasticsearchRestTemplate。我正在尝试从elasticsearch检索ZonedDateTime,但spring数据elasticsearch似乎无法创建ZonedDateTime类的对象。下面的代码片段有什么问题吗?我需要添加哪些额外的配置 另外,如果我直接使用RestHighLevelClient而不使用ElasticsearchOperations,我需要做什么 @Bean @Override

我正在使用推荐的RestHightCLient和ElasticsearchRestTemplate。我正在尝试从elasticsearch检索ZonedDateTime,但spring数据elasticsearch似乎无法创建ZonedDateTime类的对象。下面的代码片段有什么问题吗?我需要添加哪些额外的配置

另外,如果我直接使用RestHighLevelClient而不使用ElasticsearchOperations,我需要做什么

    @Bean
    @Override
    public RestHighLevelClient elasticsearchClient() {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("content-type", "application/json");
        ClientConfiguration clientConfiguration = ClientConfiguration
                .builder()
                .connectedTo("localhost:9200")
                .build();
        return RestClients.create(clientConfiguration).rest();
    }

    @Bean(name = {"elasticsearchTemplate"})
    public ElasticsearchOperations elasticsearhTemplate() {
        return new ElasticsearchRestTemplate(elasticsearchClient());
    }

将您的模式更改为使用UUU而不是yyyy;这是Elasticsearch的变化导致的:

顺便说一句,你不需要

httpHeaders.add("content-type", "application/json");
Spring Data Elasticsearch不需要
@Json…
注释

public class XXClass {
    ....

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS Z")
    private ZonedDateTime created = ZonedDateTime.now();
}
httpHeaders.add("content-type", "application/json");