I am newbie in elastic and I don't understand how should I work with transport 
client connections. Should I use singleton for Client, something like

class ElasticClientManager {
  private static Client client;
 
 public static Client getClient(){
    if (client==null) {
      Settings settings = ImmutableSettings.settingsBuilder()
                                .put("cluster.name", "elasticsearch")
                                .put("client.transport.sniff", true).build();

       client = new TransportClient(settings)
            .addTransportAddress(new 
InetSocketTransportAddress("localhost",9300));
    }
   return client;
 }
}

By other words - I create one client and keep the reference in it in singleton. 
Every time I need to query elastic I do

Client client = ElasticClientManager.getClient();
GetResponse getResponse = client.prepareGet(....).execute().actionGet();

Is such approach right? 

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/1426616386.538391541%40f217.i.mail.ru.
For more options, visit https://groups.google.com/d/optout.

Reply via email to