AWS Managed Elasticsearch上的Java Elasticsearch高级REST客户端库

时间:2019-10-10 16:31:49

标签: java elasticsearch amazon-elasticsearch

我在 AWS Managed Elasticsearch 上使用 Java Elasticsearch Highest REST Client lib ,如下所示。

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();
}

错误类似:

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)

我将此代码用于我的本地Elasticsearch,一切正常。会发生什么事?

2 个答案:

答案 0 :(得分:0)

您将获得

  

java.net.UnknownHostException

我认为您应该按如下方式创建HttpHost:

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

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

答案 1 :(得分:0)

我遇到了同样的异常。我已通过稍微更改主机并将其他参数添加到HttpHost对象来解决了该问题。它看起来与Seetha的答案相似,但这对我不起作用。您可以尝试以下方法吗?

function func(): typeof func { ... }