Hi, You are correct that you should not create a new client for every connection, but rather re-use a single client.
Note that all the client methods support being called asynchronously by passing in a response listener, or returning a future. Which is to say, if you are submitting several queries at once, you need not wait for each to return before submitting the next. - Andrew > On Mar 17, 2015, at 11:19 AM, Александр Свиридов <[email protected]> wrote: > > 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] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/1426616386.538391541%40f217.i.mail.ru > > <https://groups.google.com/d/msgid/elasticsearch/1426616386.538391541%40f217.i.mail.ru?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- 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/D0A19724-7A49-4828-B9D1-5FD67401830E%40elastic.co. For more options, visit https://groups.google.com/d/optout.
