Unknown host exception while using Java APIs to index documents (RestHighLevelClient)

I am using the vpc endpoint for elastic search to index my documents using RestHighLevelClient.

I am using java high level rest client v6.2.2 to connect Elasticsearch version 6.0

I am able to access my cluster endpoint without the need of any authentication - https://vpc......us-east-1.es.amazonaws.com

Code is as below:

          RestHighLevelClient client = null;

        try {
            Header[] headers = { new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")};

            RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("https://vpc...us-east-1.es.amazonaws.com", 9200, "https"));
            restClientBuilder.setMaxRetryTimeoutMillis(30); //Currently, set as default
            restClientBuilder.setDefaultHeaders(headers);

            client = new RestHighLevelClient(restClientBuilder);

            IndexRequest indexRequest = new IndexRequest(index, "doc", 1)
                    .source(documentJson, XContentType.JSON);


            indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

            IndexResponse indexResponse = client.index(indexRequest);

        }catch(Exception e){
  
        }finally {
            try {
                client.close();
            } catch (IOException e) {
        
            }
        }
    }

Exception:

Caused by: java.net.UnknownHostException: https://vpc-had-webapps-logs-umrm7skxqc2n5z6wc5jx632que.us-east-1.es.amazonaws.com/
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_45]
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907) ~[na:1.8.0_45]
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302) ~[na:1.8.0_45]
	at java.net.InetAddress.getAllByName0(InetAddress.java:1255) ~[na:1.8.0_45]
	at java.net.InetAddress.getAllByName(InetAddress.java:1171) ~[na:1.8.0_45]
	at java.net.InetAddress.getAllByName(InetAddress.java:1105) ~[na:1.8.0_45]
	at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.5.jar:4.5.5]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:637) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:608) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:474) ~[httpcore-nio-4.4.9.jar:4.4.9]
	at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280) ~[httpcore-nio-4.4.9.jar:4.4.9]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:268) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:377) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:129) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141) ~[httpasyncclient-4.1.3.jar:4.1.3]
	at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:346) ~[elasticsearch-rest-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:328) ~[elasticsearch-rest-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:221) ~[elasticsearch-rest-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:194) ~[elasticsearch-rest-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:488) ~[elasticsearch-rest-high-level-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:474) ~[elasticsearch-rest-high-level-client-6.2.2.jar:5.6.8]
	at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:335) ~[elasticsearch-rest-high-level-client-6.2.2.jar:5.6.8]

I changed the port to 443 as the default port for https but it gives connect exception there.

Appreciate any inputs.
thanks!

Worked with 443 and https as protocol

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.