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!

User1203
  • 77
  • 2
  • 11
  • 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 (https://stackoverflow.com/help/mcve) – Michal May 29 '18 at 07:26
  • @Michal, Updated the question with code and error, can you please check? – User1203 May 29 '18 at 08:19
  • what about your SSL certificates? Have a look here https://stackoverflow.com/questions/47334476/using-elasticsearch-java-rest-api-with-self-signed-certificates – Michal May 29 '18 at 09:39
  • yes, added SSL to java and also tried. still getting same error. – User1203 Jul 21 '18 at 11:05

0 Answers0