【问题标题】:spring-data-elasticsearch latest version throws NullPointer exception with Elasticsearch 8.1 versionspring-data-elasticsearch 最新版本使用 Elasticsearch 8.1 版本抛出 NullPointer 异常
【发布时间】:2022-07-24 20:18:40
【问题描述】:
Planning to use elasticsearch 8.1 version and use 'org.springframework.boot:spring-boot-starter-data-elasticsearch' in

我们的项目。 Repository.save() 引发以下异常。
java.lang.NullPointerException:空 在 java.base/java.util.Objects.requireNonNull(Objects.java:221) 在 org.elasticsearch.action.DocWriteResponse.(DocWriteResponse.java:116) 在 org.elasticsearch.action.index.IndexResponse.(IndexResponse.java:43)

The same code with Elasticsearch 7.15.2 works fine.

I see the supported matrix  here https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.requirements
Where to see the road map of Spring boot elasticsearch data plugin? When Do we get the plugin support for the 8.1 version of

弹性搜索? 提前致谢

【问题讨论】:

    标签: spring-data-elasticsearch


    【解决方案1】:

    添加以下标头解决了该问题。

    Accept: "application/vnd.elasticsearch+json;compatible-with=7"
    Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
    

    【讨论】:

      【解决方案2】:

      最好更改用于创建客户端的代码

      package com.search.elasticsearchapp.config;
      
      import org.apache.http.Header;
      import org.apache.http.HttpHost;
      import org.apache.http.auth.AuthScope;
      import org.apache.http.auth.UsernamePasswordCredentials;
      import org.apache.http.client.CredentialsProvider;
      import org.apache.http.impl.client.BasicCredentialsProvider;
      import org.apache.http.message.BasicHeader;
      import org.elasticsearch.client.RestClient;
      import org.elasticsearch.client.RestClientBuilder;
      import org.elasticsearch.client.RestHighLevelClient;
      import org.springframework.beans.factory.annotation.Value;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
      import org.springframework.http.HttpHeaders;
      
      @Configuration
      @EnableElasticsearchRepositories(basePackages = "*")
      public class TestClient {
      
          @Value("${elasticsearch.host}")
          private String host;
      
          @Value("${elasticsearch.port}")
          private int port;
      
          @Value("${elasticsearch.protocol}")
          private String protocol;
      
          @Value("${elasticsearch.username}")
          private String userName;
      
          @Value("${elasticsearch.password}")
          private String password;
      
          @Bean(destroyMethod = "close")
          public RestHighLevelClient restClient() {
      
              final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
              credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
      
              RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, protocol))
                      .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
                      .setDefaultHeaders(compatibilityHeaders());
      
              return new RestHighLevelClient(builder);
          }
      
          private Header[] compatibilityHeaders() {
              return new Header[]{new BasicHeader(HttpHeaders.ACCEPT, "application/vnd.elasticsearch+json;compatible-with=7"), new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.elasticsearch+json;compatible-with=7")};
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-27
        • 2016-07-02
        • 1970-01-01
        • 2021-04-05
        • 1970-01-01
        • 2022-01-05
        相关资源
        最近更新 更多