I am using the Java HighLevelRestClient to connect to my elastic instance hosted on AWS. I can make requests against the URL on postman and from my browser just fine, but when I use the client library I get a java.net.ConnectException: Connection Refused. (I don't currently need any authentication as this is a small public test instance).
Edit: I have set up the ElasticSearch [6.2] instance on the AWS console and am making requests against the domain that is created. I don't see any ports that are configured for my domain.
This is my code:
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<GetResponse>() {
@Override
public void onResponse(GetResponse documentFields) {
try {
elasticGetResponse[0] = restHighLevelClient.get(getRequest).toString();
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Exception e) {
e.printStackTrace();
}
});
I'm not sure what I'm doing incorrectly. All help is appreciated!
Update: I built the restClientBuilder with the following
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() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
return httpAsyncClientBuilder.setSSLContext(sslHelper.getContext());
}
});