gpt4 book ai didi

elasticsearch - 使用Java API索引文档时未知主机异常(RestHighLevelClient)Elasticsearch

转载 作者:行者123 更新时间:2023-12-03 00:39:48 25 4
gpt4 key购买 nike

我正在使用vpc端点进行 flex 搜索,以使用RestHighLevelClient索引我的文档。

我正在使用Java高级休息客户端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) {

}
}
}

异常(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]

感谢任何输入。
谢谢!

最佳答案

将HttpHost对象实例化替换为:

new HttpHost("vpc-had-webapps-logs-umrm7skxqc2n5z6wc5jx632que.us-east-1.es.amazonaws.com", 9200, "https")

就像 this example中一样。

关于elasticsearch - 使用Java API索引文档时未知主机异常(RestHighLevelClient)Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49318729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com