【问题标题】:Connect Elastic Search using reverse proxied url through Java Code通过 Java 代码使用反向代理 url 连接 Elastic Search
【发布时间】:2020-07-07 02:59:21
【问题描述】:

需要有关通过 Java 使用反向代理 URL 设置 Elastic Search 的帮助。

在私有企业网络上运行的 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")));

错误:

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 的替代方法?

【问题讨论】:

  • 您可能需要检查 Elasticsearch 服务器日志,看看是否有任何关于服务器关闭连接原因的线索。如果是证书问题,您可能需要tell the client about the CA root certificate。如果服务器需要身份验证,您需要pass the credentials
  • 如果是证书问题,则可能无法连接到 Elasticsearch 服务器...在这种情况下,代理日志将是查看的地方...而代理的证书就是其中的一个你想要信任。

标签: java elasticsearch logstash spring-data-elasticsearch


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-11-06
    • 2014-05-20
    • 2021-05-07
    • 1970-01-01
    • 2020-08-28
    • 2019-09-05
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多