gpt4 book ai didi

java - 通过 Java 代码使用反向代理 url 连接 Elastic Search

转载 作者:行者123 更新时间:2023-12-03 02:19:35 24 4
gpt4 key购买 nike

需要有关通过 Java 使用反向代理 URL 设置 Elasticsearch 的帮助。
在私有(private)企业网络上运行的 VM(localhost:9200) 中安装了 Elastic Search。我们为该 URL 启用了反向代理。在浏览器中粘贴 URL 时,工作正常。

https://demo-es.xyz.abc.com

{
"name" : "13abc1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "5u9dqlSBRSmpabcdefghij",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "12341234.......",
"build_date" : "2020-6-10T03:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
但我需要通过 Java 代码连接。我正在使用以下代码进行连接,但接收连接被拒绝。
public ElasticSearch(String host, int port, String protocol) throws IOException {
client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("demo-es.xyz.abc.com", 443)));
}
我也尝试过使用它但不工作
RestClient.builder(new HttpHost("demo-es.xyz.abc.com", 443, "https")));

Error:

org.apache.http.ConnectionClosedException: Connection is closed
at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:813)
[]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:248)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1611)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1581)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1551)
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1067)
at com.presto.banking.util.ElasticSearch.searchRecords(ElasticSearch.java:46)
at com.presto.banking.util.ElasticSearch.main(ElasticSearch.java:76)
Caused by: org.apache.http.ConnectionClosedException: Connection is closed
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:356)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:261)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
at java.lang.Thread.run(Thread.java:748)
是否有通过 Java Source 连接 Elastic Search 的替代方法?

最佳答案

如果你使用 Spring Data Elasticsearch 4.0,你可以配置 RestHighLevelClient 像 described in the documentation . This section详细描述了配置选项。

关于java - 通过 Java 代码使用反向代理 url 连接 Elastic Search,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62760423/

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