我使用java高级rest客户机从springboot应用程序连接到ElasticSearch
@Bean
public RestHighLevelClient createSimpleElasticClient() throws Exception{
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(properties.getElasticsearchHost(), properties.elasticsearchPort, "http")).setRequestConfigCallback(
new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(properties.getElasticsearchConnectTimeout()).setSocketTimeout(properties.getElasticsearchSocketTimeout()).setConnectionRequestTimeout(0);
}
}));
boolean ping = false;
try {
ping = client.ping(RequestOptions.DEFAULT);
} catch (IOException e) {
System.out.println(e);
}
if (!ping) {
throw new IllegalStateException("Fail to ping rest node");
}
return client;
}
我最初使用的是ip地址和端口(例如:elasticsearchhost=10.24.154.154和elasticsearchport=9200),这段代码运行良好。但是现在我想使用一个aws负载均衡器url。此新url具有https架构。但是当我们调用url时,它首先进入loadbalancer,然后它被重定向到elasticsearch,这只是http。所以我希望不要在这方面犯错误。但我不能继续。
在上面的代码中,我将这一行restclient.builder(new httphost(properties.getelasticsearchhost(),properties.elasticsearchport,“http”)编辑到这个restclient.builder(new httphost(properties.getelasticsearchhost()),其中getelasticsearchhost有一个url,例如:https://example.com
但我得到以下错误。javax.net.ssl.sslhandshakeexception:pkix路径生成失败:sun.security.provider.certpath.suncertpathbuilderexception:找不到请求目标的有效证书路径
它从client.ping(requestoptions.default)行抛出;
请协助
暂无答案!
目前还没有任何答案,快来回答吧!