0

我们正在使用 Java Rest 高级客户端来调用 elasticsearch 节点。

现在我们添加了一个负载均衡器并启用了 SSL。我们无法使用 Rest 客户端访问负载均衡器 URL。它会引发错误并且无法找到任何解决方案,例如如何通过 Java API 调用负载均衡器 URL。

有人可以帮忙吗?

代码:

        RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("hostname")));
    SearchRequest searchRequest = new SearchRequest("testCollection");
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(QueryBuilders.queryStringQuery("test"));
    searchRequest.source(sourceBuilder);
    try {
        SearchResponse searchResponse=client.search(searchRequest);
        String response = searchResponse.toString();
        System.out.println("search response :"+ response);
    }
    catch (IOException e ) {
        e.printStackTrace();
    }
    finally {
        try {
            client.close();
        } catch (IOException e) {
            System.out.println("error while closing");
            e.printStackTrace();
        }
    }

错误:

 java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:197)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:451)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:505)
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120)
    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:588)`enter code here`
    at java.lang.Thread.run(Thread.java:748)

谢谢!

4

0 回答 0