代码之家  ›  专栏  ›  技术社区  ›  Prakash26790

通过Java代码使用反向代理url连接弹性搜索

  •  0
  • Prakash26790  · 技术社区  · 4 年前

    需要关于通过Java使用反向代理URL设置弹性搜索的帮助。

    在虚拟机(localhost:9200)中安装了弹性搜索,该虚拟机运行在私有公司网络上。我们为该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源代码连接弹性搜索?

    0 回复  |  直到 4 年前
        1
  •  0
  •   Abacus    4 年前

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