# Java client initialization

**URL:** <https://discuss.elastic.co/t/java-client-initialization/17571>\
**Category:** Elasticsearch\
**Created:** [May 17, 2014, 12:29pm UTC](https://discuss.elastic.co/t/java-client-initialization/17571 "2014-05-17T12:29:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manish\_kumar](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@manish\_kumar](https://discuss.elastic.co/u/manish_kumar)\
**Post date:** [May 17, 2014, 12:29pm UTC](https://discuss.elastic.co/t/java-client-initialization/17571/1 "2014-05-17T12:29:30Z")

</div>

I am new to Elastic search. I wanted to know that i am using java client to  
access ES.

```
             Client client = new 

```

TransportClient().addTransportAddress(new  
InetSocketTransportAddress("127.0.0.1", 9300));

Should i initiated client everytime i execute query or just once?

If i start it just at the starting of application will i have to do  
something like refreshing client so that to get latest data?

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e8560ab7-e45b-4849-8ba6-f55a626028d6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e8560ab7-e45b-4849-8ba6-f55a626028d6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Gaurav\_gupta](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@Gaurav\_gupta](https://discuss.elastic.co/u/Gaurav_gupta)\
**Post date:** [May 17, 2014, 1:02pm UTC](https://discuss.elastic.co/t/java-client-initialization/17571/2 "2014-05-17T13:02:38Z")

</div>

I think you need to only initialize in once on application (JVM) launch.

You can alternatively use the JAVA client API :-  
Node node = nodeBuilder().node();  
Client client = node.client();

Refer :-

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks

On Saturday, May 17, 2014 5:59:30 PM UTC+5:30, manish kumar wrote:

> I am new to Elastic search. I wanted to know that i am using java client  
> to access ES.
> 
> ```
> Client client = new 
> 
> ```
> 
> TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("127.0.0.1", 9300));
> 
> Should i initiated client everytime i execute query or just once?
> 
> If i start it just at the starting of application will i have to do  
> something like refreshing client so that to get latest data?

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/41a19356-6967-493a-8cf9-69a3b035d4c8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/41a19356-6967-493a-8cf9-69a3b035d4c8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![manish\_kumar](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@manish\_kumar](https://discuss.elastic.co/u/manish_kumar)\
**Post date:** [May 17, 2014, 1:38pm UTC](https://discuss.elastic.co/t/java-client-initialization/17571/3 "2014-05-17T13:38:04Z")

</div>

nodeBuilder or TransportClient both should be initialized once.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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2ec08f7f-097b-4ef7-b34d-30c7f6ad7fa9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2ec08f7f-097b-4ef7-b34d-30c7f6ad7fa9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:28am UTC](https://discuss.elastic.co/t/java-client-initialization/17571/4 "2017-07-06T01:28:42Z")

</div>


