Bromo Programmer
Bromo Programmer

Reputation: 670

Java Elasticsearch Highlevel REST Client lib on AWS Managed Elasticsearch

I use Java Elasticsearch Highlevel REST Client lib on AWS Managed Elasticsearch like below, and I got error.

public static void main(String[] args) throws Exception {
    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("https://search-xxxx-xxxxxxx.aws-region-x.es.amazonaws.com")));

    ClusterHealthRequest req = new ClusterHealthRequest();
    ClusterHealthResponse res =  client.cluster().health(req, RequestOptions.DEFAULT);
    System.out.println(res.toString());

    client.close();
}

The error are like:

Exception in thread "main" java.io.IOException: https://search-xxxx-xxxxxxx.aws-region-x.es.amazonaws.com
at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:793)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394)
at org.elasticsearch.client.ClusterClient.health(ClusterClient.java:118)
at ClusterHealthCheck.main(ClusterHealthCheck.java:15)
Caused by: java.net.UnknownHostException: https://search-xxxx-xxxxxxx.aws-region-x.es.amazonaws.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:664)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:635)
at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:474)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:295)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:377)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:129)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:214)

I use this code against my local Elasticsearch and everything fine. What happen?

Upvotes: 0

Views: 1379

Answers (2)

Hakan54
Hakan54

Reputation: 3861

I was getting the same exception. I have resolved it by changing the host a bit and adding additional parameters to the HttpHost object. It looks similar to the answer of Seetha, but that didn't work for me. Could you try the following:

public static void main(String[] args) throws Exception {
    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("search-xxxx-xxxxxxx.aws-region-x.es.amazonaws.com", 443, "https")));

    ClusterHealthRequest req = new ClusterHealthRequest();
    ClusterHealthResponse res =  client.cluster().health(req, RequestOptions.DEFAULT);
    System.out.println(res.toString());

    client.close();
}

Upvotes: 1

Seetha
Seetha

Reputation: 95

You are getting

java.net.UnknownHostException

I think you should create HttpHost as follows:

new HttpHost("xxxxxxxxx", portNumber, "https")

instead of new HttpHost("https://search-xxxx-xxxxxxx.aws-region-x.es.amazonaws.com")

Upvotes: 0

Related Questions