gpt4 book ai didi

ElasticSearch Java HighLevelRestClient 连接被拒绝

转载 作者:行者123 更新时间:2023-12-02 23:19:42 25 4
gpt4 key购买 nike

我正在使用 Java HighLevelRestClient 连接到我在 AWS 上托管的 elasticsearch 实例。我可以通过 postman 和浏览器对 URL 发出请求,但是当我使用客户端库时,我会收到

java.net.ConnectException: Connection Refused.



(我目前不需要任何身份验证,因为这是一个小型公共(public)测试实例)。这是我的代码:

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);

GetRequest getRequest = new GetRequest("some_index", "some_type","some_id");
final String[] elasticGetResponse = new String[1];

restHighLevelClient.getAsync(getRequest, new ActionListener() {

@覆盖
公共(public)无效 onResponse(GetResponse documentFields) {
尝试 {
elasticGetResponse[0] = restHighLevelClient.get(getRequest).toString();
}

捕捉(IOException e){
e.printStackTrace();
}

}

@覆盖
公共(public)无效onFailure(异常e){
e.printStackTrace();
}
});

请让我知道如何解决这个问题...谢谢!

更新:这是我的 restClientBuilder 代码:

MySSLHelper sslHelper = new MySSLHelper(SSLConfig.builder()
.withKeyStoreProvider(myKeyStoreProvider)
.withTrustStoreProvider(InternalTrustStoreProvider.INSTANCE)
。 build ());

RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("MY_ELASTICSEARCH_ENDPOINT")).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@覆盖
公共(public) HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
返回 httpAsyncClientBuilder.setSSLContext(sslHelper.getContext());
}
});

最佳答案

我遇到了同样的问题并解决了放置端口和协议(protocol)的问题,如本页所示:
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.0/java-rest-high-getting-started-initialization.html

我的代码保持这样:

RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchHost, 9200, "http")));

请尝试做这样的事情:
RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("MY_ELASTICSEARCH_ENDPOINT", "MY_ELASTICSEARCH_PORT", "MY_ELASTICSEARCH_PROTOCOL"))...

希望这可以帮助。

再见。

关于ElasticSearch Java HighLevelRestClient 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50847449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com