将Elasticsearch从5.6.8更新到6.2.3

时间:2018-10-15 09:28:20

标签: spring elasticsearch

我正在尝试将Elasticsearch从5.6.8更新为6.2.3,但是我收到错误消息:

org.springframework.beans.factory.BeanCreationException:在类路径资源[com / viamedici / infinitygate / elasticSearch / ElasticSearchClient.class]中创建名称为“ client”的bean时出错:通过工厂方法实例化Bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.elasticsearch.client.Client]:工厂方法“ client”抛出了异常;嵌套的异常是java.lang.NoSuchFieldError:共享。

这就是我添加的pom.xml:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>

    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.2.3</version>
    </dependency>

    <dependency>
         <groupId>org.elasticsearch.client</groupId>
          <artifactId>transport</artifactId>
          <version>6.2.3</version>
    </dependency>

我的配置客户端如下:

@Bean
public Client client()  {
    boolean b = Boolean.parseBoolean(transportSniff);
    String host = clusterNodes.split(":")[0];
    Integer port = Integer.parseInt(clusterNodes.split(":")[1]);
    Settings settings = Settings.builder()
            .put("client.transport.sniff", b)
            .put("cluster.name", clusterName)
            .build();
    TransportClient transportClient = new PreBuiltTransportClient(settings);
    try {
        transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
    } catch (UnknownHostException e) {
        ErrorHandlingController.logger.error("Host/port problem", e);
    }
    INSTANCE = (Client) transportClient;
    return transportClient;
}          

}

您有什么想法吗? 谢谢

1 个答案:

答案 0 :(得分:1)

请删除:

 <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>6.2.3</version>
</dependency>

<dependency>
     <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>6.2.3</version>
</dependency>

并添加application.properties

spring.data.elasticsearch.cluster-nodes=localhost:9300

还请删除trasport客户Bean定义

@Bean Client client() {

它将尝试创建连接,并且将失败。如果您使用Docker启动Elasticsearch,则可以检查此存储库。 https://github.com/adinafometescu/tutorials/tree/master/spring-elasticsearch

我遇到了与您描述的问题相同的问题(在版本迁移过程中),现在一切正常。