我正在使用 Java HighLevelRestClient 连接到我在 AWS 上托管的 elasticsearch 实例。我可以通过邮递员和浏览器对 URL 发出请求,但是当我使用客户端库时,我会收到
java.net.ConnectException:连接被拒绝。
(我目前不需要任何身份验证,因为这是一个小型公共测试实例)。这是我的代码:
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() { @覆盖 公共无效 onResponse(GetResponse documentFields) { 尝试 { elasticGetResponse[0] = restHighLevelClient.get(getRequest).toString(); } 捕捉(IOException e){ e.printStackTrace(); } } @覆盖 公共无效onFailure(异常e){ e.printStackTrace(); } });
请让我知道如何解决这个问题...谢谢!
更新:这是我的 restClientBuilder 代码:
MySSLHelper sslHelper = new MySSLHelper(SSLConfig.builder() .withKeyStoreProvider(myKeyStoreProvider) .withTrustStoreProvider(InternalTrustStoreProvider.INSTANCE) 。建造()); RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("MY_ELASTICSEARCH_ENDPOINT")).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() { @覆盖 公共 HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) { 返回 httpAsyncClientBuilder.setSSLContext(sslHelper.getContext()); } });