栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

compatible version of org.elasticsearch.client.RestHighLevelClient

compatible version of org.elasticsearch.client.RestHighLevelClient

一、异常现象:
springboot 整合elasticsearch 5.6.8版本。出现此异常,低版本es服务使用高版本es客户端连接

An attempt was made to call the method org.elasticsearch.client.RestHighLevelClient.(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

pom.xml

		
            org.elasticsearch
            elasticsearch
            5.6.8
        
        
            org.elasticsearch.client
            elasticsearch-rest-client
            5.6.8
        
        
            org.elasticsearch.client
            elasticsearch-rest-high-level-client
            5.6.8
            
                
                    elasticsearch
                    org.elasticsearch
                
                
                    elasticsearch-rest-client
                    org.elasticsearch.client
                
            
        

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

初始化方式:

@Slf4j
@Configuration
public class ElasticSearchConfig {

    @Value("${spring.elasticsearch.host}")
    private String host;

    @Value("${spring.elasticsearch.port}")
    private int port;

    @Value("${spring.elasticsearch.index}")
    private String indexName;

    @Value("${spring.elasticsearch.type}")
    private String type;

    @Value("${spring.elasticsearch.username}")
    private String username;

    @Value("${spring.elasticsearch.password}")
    private String password;

    @Value("${spring.elasticsearch.auth}")
    private Boolean auth;

    @Bean
    @Primary
    public RestHighLevelClient restHighLevelClient() {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
        RestClient restClient;
        if (auth) {
            restClient = RestClient.builder(new HttpHost(host, port))
                    .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).build();
        } else {
            restClient = RestClient.builder(new HttpHost(host, port)).build();
        }
        return new RestHighLevelClient(restClient);
    }
}

二、解决方案
原因是:Spring Boot将尝试自动配置elasticsearch,该搜索将在内部使用Elastic 6, RestHighLevelClient(org.elasticsearch.client.RestClientBuilder builder)创建弹性客户端.如果要连接到旧版本的elasticsearch,请排除elasticsearch自动配置,在配置类上添加改配置方式就可以正常启动了

@EnableAutoConfiguration(exclude={ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class})
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/487498.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号