0

We are using Java Rest high-level client to call elasticsearch nodes.

Now we have added a load balancer and enabled SSL. We are not able to access the load balancer URL with Rest client. It throws an error and not able to find any solution like how to call load balancer URL through Java API.

Can someone please help on this?

Code:

        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();
        }
    }

Error:

 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)

Thanks!

4
  • Load balancer URL is not special in any way. The issues can be, amongst other things, due to invalid certificates. Please post your code and the exception. Also see How to create a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve) Commented May 29, 2018 at 7:26
  • @Michal, Updated the question with code and error, can you please check? Commented May 29, 2018 at 8:19
  • what about your SSL certificates? Have a look here stackoverflow.com/questions/47334476/… Commented May 29, 2018 at 9:39
  • yes, added SSL to java and also tried. still getting same error. Commented Jul 21, 2018 at 11:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.