Elasticsearch java 客户端初始化失败

编程入门 行业动态 更新时间:2024-10-10 15:20:22
本文介绍了Elasticsearch java 客户端初始化失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm getting this error message while trying to run an application which connects to 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.

The application builds without errors and only one version of elasticsearch SDK exists in my maven repository.

这是我的 pom 的相关部分:

This is the relevant portion of my 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>

这是我在运行应用程序时遇到的异常:

This is the exception that I get while running the application:

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 的方式:

This is how I'm initializing the RestHighLevelClient:

RestClientBuilder builder = RestClient .builder(new HttpHost(hostname, port, scheme)); builder.setMaxRetryTimeoutMillis(timeout); RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder.build());

推荐答案

Spring boot 会尝试自动配置 elasticsearch,它会在内部使用 elastic 6RestHighLevelClient(org.elasticsearch.client.RestClientBuilder builder) 来创建弹性客户端.如果您想连接到旧版本的 elasticsearch,请排除 elasticsearch 自动配置.

Spring boot will try to autoconfigure elasticsearch which will internally use elastic 6 RestHighLevelClient(org.elasticsearch.client.RestClientBuilder builder) to create the elastic client. If you want to connect to an older version of elasticsearch please exclude elasticsearch autoconfiguration.

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

更多推荐

Elasticsearch java 客户端初始化失败

本文发布于:2023-11-16 14:48:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   客户端   Elasticsearch   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!