3

I'm a newbie to Elasticsearch, I'm using Elasticsearch for my app. My app has the following code to interact with ES.

- Client (Singleton)

if(client==null) {
        client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(host,port.toInteger())) 
}

This client is used in throughout the app and destroyed on the shutdown of the app. I don't close the client anywhere else. Recently, I started facing "No Node Available" exception. I tried digging into that and found some people talking about closing the connection every time after any operation. So my question is, how does the Java client actually work? Does it create a connection with the cluster and keep it alive (till the timeout if specified) to be reused or every time it tends to create new connection?

jasonlam604
  • 1,456
  • 2
  • 16
  • 25
Darth Shekhar
  • 115
  • 3
  • 16
  • Please provide cluster details -- are you talking to a single node? How much memory is allocated to ES? Have you looked at the ES logs to see if it's logging anything? – Alcanzar Oct 14 '14 at 14:37
  • 1
    Never close the client! Let it handle all the connections for you. Yes, it keeps a pool of connections open, along with several thread pools, caches and data structures to be aware of the current topology of the cluster. – fps Mar 20 '17 at 02:59

0 Answers0