java - Elasticsearch Java客户端初始化失败

IT工具网 · · 101 次点击 · · 开始浏览    

我在尝试运行连接到Elasticsearch的应用程序时收到此错误消息。

An attempt was made to call the method org.elasticsearch.client.RestHighLevelClient.<init>(Lorg/elasticsearch/client/RestClientBuilder;)V but it does not exist. Its class, org.elasticsearch.client.RestHighLevelClient, is available from the following locations:

jar:file:/path/application/target/application-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/elasticsearch-rest-high-level-client-5.6.3.jar!/org/elasticsearch/client/RestHighLevelClient.class

It was loaded from the following location:

jar:file:/path/application/target/application-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/elasticsearch-rest-high-level-client-5.6.3.jar!/

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RestHighLevelClient

该应用程序的构建没有错误,并且我的maven存储库中只有一个版本的elasticsearch SDK。

这是我pom的相关部分:
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath />
    </parent>

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

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-client</artifactId>
        <version>5.6.3</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>5.6.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-client</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

这是我在运行应用程序时遇到的异常:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.client.RestHighLevelClient.<init>(Lorg/elasticsearch/client/RestClientBuilder;)V

这就是我初始化RestHighLevelClient的方式:
RestClientBuilder builder = RestClient
                .builder(new HttpHost(hostname, port, scheme));
builder.setMaxRetryTimeoutMillis(timeout);
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder.build());

最佳答案

Spring Boot将尝试自动配置Elasticsearch,该 flex 搜索将在内部使用Elastic 6
RestHighLevelClient(org.elasticsearch.client.RestClientBuilder builder)创建 flex 客户端。如果要连接到旧版本的elasticsearch,请排除elasticsearch自动配置。

@EnableAutoConfiguration(exclude={ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class})

本文来自:IT工具网

感谢作者:IT工具网

查看原文:java - Elasticsearch Java客户端初始化失败

101 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传