我正在使用vpc端点进行弹性搜索,以使用RestHighLevelClient索引我的文档。
我使用java高级rest客户端v6.2.2来连接Elasticsearch版本6.0
我无需任何身份验证即可访问我的群集端点 - https://vpc......us-east-1.es.amazonaws.com
代码如下:
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) {
}
}
}
例外:
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]
感谢任何输入。 谢谢!
答案 0 :(得分:0)
用以下内容替换HttpHost对象实例:
new HttpHost("vpc-had-webapps-logs-umrm7skxqc2n5z6wc5jx632que.us-east-1.es.amazonaws.com", 9200, "https")
就像在this example中一样。