# Initialize TransportClient in a web application

**URL:** <https://discuss.elastic.co/t/initialize-transportclient-in-a-web-application/4613>\
**Category:** Elasticsearch\
**Created:** [June 14, 2011, 8:15am UTC](https://discuss.elastic.co/t/initialize-transportclient-in-a-web-application/4613 "2011-06-14T08:15:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spico\_Florin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spico_florin/32/49309_2.png) [@Spico\_Florin](https://discuss.elastic.co/u/Spico_Florin)\
**Post date:** [June 14, 2011, 8:15am UTC](https://discuss.elastic.co/t/initialize-transportclient-in-a-web-application/4613/1 "2011-06-14T08:15:49Z")

</div>

Hello!  
We have a cluster with 10 Elastic Search nodes that we are using for  
indexing our data. In order to perform searching, we are using a web  
application(deployed on Tomcat web server) installed on a machine that  
will be remote from ES. Therefore, we are using TransportClient in  
order to connect to ElasticSearch.  
But in order to do that in the right way, we would like to ask you  
what is the best way to initialize this connection:

1. Adding all the ElasticSearch nodes to the TransportClient (using API)
2. In order to discover the ES network, what do you recommend :  
Unicast or Multicast?
3. Where in the web application we should do this connection to ES ?  
Can we use the ThreadLocal Pattern into a Singleton class and from  
there to create the connection? Or we can initialize this connection  
from ServletContextListener?

Thank you in advance.  
Kind regards,  
Florin

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 14, 2011, 8:54am UTC](https://discuss.elastic.co/t/initialize-transportclient-in-a-web-application/4613/2 "2011-06-14T08:54:57Z")

</div>

On Tuesday, June 14, 2011 at 11:15 AM, Spico Florin wrote:

> Hello!  
> We have a cluster with 10 Elastic Search nodes that we are using for  
> indexing our data. In order to perform searching, we are using a web  
> application(deployed on Tomcat web server) installed on a machine that  
> will be remote from ES. Therefore, we are using TransportClient in  
> order to connect to Elasticsearch.  
> But in order to do that in the right way, we would like to ask you  
> what is the best way to initialize this connection:
> 
> 1. Adding all the Elasticsearch nodes to the TransportClient (using API)  
> It is recommended to add as many addresses as you know to it. You can also enable sniffing so it will sniff the other nodes automatically.
> 2. In order to discover the ES network, what do you recommend :  
> Unicast or Multicast?  
> You mean for the cluster? Transport client always uses "unicast". As for the cluster, its up to you.
> 3. Where in the web application we should do this connection to ES ?  
> Can we use the ThreadLocal Pattern into a Singleton class and from  
> there to create the connection? Or we can initialize this connection  
> from ServletContextListener?  
> Up to you, as long as you don't create several client instances.
> 
> Thank you in advance.  
> Kind regards,  
> Florin

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:03am UTC](https://discuss.elastic.co/t/initialize-transportclient-in-a-web-application/4613/3 "2017-07-06T04:03:41Z")

</div>

Closed on July 6, 2017, 4:03am UTC


