Trying to connect opensearch [AWS] via JavaClient and followed this blog. We don't have ssl authentication enabled in AWS for this demo.
public void connect(){
try {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("es_cluster_username", "es_password"));
RestClient restClient = RestClient.builder(new HttpHost("es-demo-cluster", 9200, "https"))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).build();
OpenSearchTransport transport = new RestClientTransport(restClient, jacksonJsonpMapper);
OpenSearchClient openSearchClient = new OpenSearchClient(transport);
boolean isConneted = openSearchClient.ping().value();
if (isConneted) {
log.info("ES connected ");
} else {
log.error("ES NOT connected");
}
} catch (Exception e) {
log.error("Failed to connect to ES ");
}
}
But getting Timeout exception here :
> java.net.ConnectException: Timeout connecting to [host:9200]
at org.opensearch.client.RestClient.extractAndWrapCause(RestClient.java:953)
at org.opensearch.client.RestClient.performRequest(RestClient.java:332)
at org.opensearch.client.RestClient.performRequest(RestClient.java:320)
at org.opensearch.client.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:142)
dependencies :
<dependency>
<groupId>org.opensearch.client</groupId>
<artifactId>opensearch-rest-client</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.opensearch.client</groupId>
<artifactId>opensearch-java</artifactId>
<version>2.3.0</version>
</dependency>
Our ES service is hosted in AWS and the demo endpoint[es-demo-cluster] is public. Able to do curl "es_endpoint[es-demo-cluster]" but connecting via Java client is throwing an exception. Can someone help with this?