# Elastic search search connection

**URL:** https://discuss.elastic.co/t/elastic-search-search-connection/10452
**Category:** Elasticsearch
**Created:** [January 22, 2013, 4:08pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452 "2013-01-22T16:08:46Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 22, 2013, 4:08pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/1 "2013-01-22T16:08:46Z")

</div>

Hi,

I'm using the below code to get a client connection to run a ES query using  
the Java API.  
However this expensive object creation takes too much of time and and i'm  
not sure if this object is thread-safe. If it isn't thread-safe then should  
i be using a connection pool for client objects or is there another way to  
get and cache connections?

_Settings settings = ImmutableSettings.settingsBuilder()_

- .put("cluster.name", "XXXXX")\*
- .put("client.transport.sniff", true)\*
- .put("node.client", true)\*
- .put("client.transport.ping\_timeout","10s").build();\*
- 
  - 

- Client client = new TransportClient(settings).addTransportAddress(new  
InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));\*
- SearchRequestBuilder srb = client.prepareSearch(domainName)\*
- 

```
   .setSearchType(SearchType.QUERY_AND_FETCH)*

```

- 

```
   .setQuery(query);*

```

- 
- 
- 
- 

Thanks,  
John

--

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 22, 2013, 4:16pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/2 "2013-01-22T16:16:31Z")

</div>

Yes. It's threadsafe. Use one and only one Client in your JVM.

Are you using Spring BTW?

Le 22 janvier 2013 à 17:08, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :

> Hi,
> 
> I'm using the below code to get a client connection to run a ES query using  
> the Java API.  
> However this expensive object creation takes too much of time and and i'm not  
> sure if this object is thread-safe. If it isn't thread-safe then should i be  
> using a connection pool for client objects or is there another way to get and  
> cache connections?
> 
> Settings settings = ImmutableSettings.settingsBuilder()  
> .put("cluster.name", "XXXXX")  
> .put("client.transport.sniff", true)  
> .put("node.client", true)  
> .put("client.transport.ping\_timeout","10s").build();
> 
> Client client = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));  
> SearchRequestBuilder srb = client.prepareSearch(domainName)  
> .setSearchType(SearchType.QUERY\_AND\_FETCH)  
> .setQuery(query);
> 
> Thanks,  
> John
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

### Author: ![Shairon\_Toledo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shairon_toledo/32/2490_2.png) [@Shairon\_Toledo](https://discuss.elastic.co/u/Shairon_Toledo)
#### Post date: [January 22, 2013, 4:24pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/3 "2013-01-22T16:24:56Z")

</div>

Is not missing shoot the request builder with

..setQuery(query).execute().actionGet();

On Tue, Jan 22, 2013 at 2:16 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> \*\*  
> Yes. It's threadsafe. Use one and only one Client in your JVM.
> 
> Are you using Spring BTW?
> 
> Le 22 janvier 2013 à 17:08, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :
> 
> Hi,
> 
> I'm using the below code to get a client connection to run a ES query  
> using the Java API.  
> However this expensive object creation takes too much of time and and i'm  
> not sure if this object is thread-safe. If it isn't thread-safe then should  
> i be using a connection pool for client objects or is there another way to  
> get and cache connections?
> 
> _Settings settings = ImmutableSettings.settingsBuilder()_
> 
> - .put("cluster.name", "XXXXX")\*
> 
> - .put("client.transport.sniff", true)\*
> 
> - .put("node.client", true)\*
> 
> - .put("client.transport.ping\_timeout","10s").build();\*
> 
> - Client client = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));\*
> 
> - SearchRequestBuilder srb = client.prepareSearch(domainName)\*
> 
> - 
> 
> ```
> .setSearchType(SearchType.QUERY_AND_FETCH)*
> 
> ```
> 
> - 
> 
> ```
> .setQuery(query);*
> 
> ```
> 
> - 
> - 
> 
> - 
> - 
> 
> Thanks,  
> John
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --

--

Shairon Toledo

> **[Microsoft Developer News | C++,C# & .NET Framework & More | CodeGuru](http://hashcode.me)**
>
> 您是否想要找关于幸运飞行艇 官方开奖历史记录 168飞艇全国统一开奖数据 还有幸运飞行艇官方开奖现场直播 幸运168飞艇全天精准稳定计划 这里都能一一提供。CodeGuru is where developers come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and more related to programming in areas including C++,...

--

---

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 22, 2013, 6:05pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/4 "2013-01-22T18:05:38Z")

</div>

Thanks David. Yes i'm using Spring along with ANTLR.

On Tuesday, January 22, 2013 10:16:31 AM UTC-6, David Pilato wrote:

> Yes. It's threadsafe. Use one and only one Client in your JVM.
> 
> Are you using Spring BTW?
> 
> Le 22 janvier 2013 à 17:08, john \<[john2...@gmail.com](mailto:john2...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi,
> 
> I'm using the below code to get a client connection to run a ES query  
> using the Java API.  
> However this expensive object creation takes too much of time and and i'm  
> not sure if this object is thread-safe. If it isn't thread-safe then should  
> i be using a connection pool for client objects or is there another way to  
> get and cache connections?
> 
> _Settings settings = ImmutableSettings.settingsBuilder()_
> 
> - .put("cluster.name", "XXXXX")\*
> 
> - .put("client.transport.sniff", true)\*
> 
> - .put("node.client", true)\*
> 
> - .put("client.transport.ping\_timeout","10s").build();\*
> 
> - Client client = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));\*
> 
> - SearchRequestBuilder srb = client.prepareSearch(domainName)\*
> 
> - 
> 
> ```
> .setSearchType(SearchType.QUERY_AND_FETCH)* 
> 
> ```
> 
> - 
> 
> ```
> .setQuery(query);* 
> 
> ```
> 
> - 
> - 
> 
> - 
> - 
> 
> Thanks,  
> John
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 22, 2013, 6:08pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/5 "2013-01-22T18:08:16Z")

</div>

Shairon, i'm calling the execute().actionget() on the search request  
builder.

On Tuesday, January 22, 2013 10:24:56 AM UTC-6, Shairon Toledo wrote:

> Is not missing shoot the request builder with
> 
> ..setQuery(query).execute().actionGet();
> 
> On Tue, Jan 22, 2013 at 2:16 PM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)\<javascript:\>
> 
> > wrote:
> 
> > \*\*  
> > Yes. It's threadsafe. Use one and only one Client in your JVM.
> > 
> > Are you using Spring BTW?
> > 
> > Le 22 janvier 2013 à 17:08, john \<[john2...@gmail.com](mailto:john2...@gmail.com) \<javascript:\>\> a  
> > écrit :
> > 
> > Hi,
> > 
> > I'm using the below code to get a client connection to run a ES query  
> > using the Java API.  
> > However this expensive object creation takes too much of time and and  
> > i'm not sure if this object is thread-safe. If it isn't thread-safe then  
> > should i be using a connection pool for client objects or is there another  
> > way to get and cache connections?
> > 
> > _Settings settings = ImmutableSettings.settingsBuilder()_
> > 
> > - .put("cluster.name", "XXXXX")\*
> > 
> > - .put("client.transport.sniff", true)\*
> > 
> > - .put("node.client", true)\*
> > 
> > - .put("client.transport.ping\_timeout","10s").build();\*
> > 
> > - Client client = new TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));\*
> > 
> > - SearchRequestBuilder srb = client.prepareSearch(domainName)\*
> > 
> > - 
> > 
> > ```
> > .setSearchType(SearchType.QUERY_AND_FETCH)* 
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .setQuery(query);* 
> > 
> > ```
> > 
> > - 
> > - 
> > 
> > - 
> > - 
> > 
> > Thanks,  
> > John
> > 
> > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > --
> 
> --
> 
> Shairon Toledo  
> [http://hashcode.me](http://hashcode.me)

--

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 22, 2013, 6:24pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/6 "2013-01-22T18:24:30Z")

</div>

Did you at the elasticsearch spring factory project?

Just inject your client bean in your classes... Et voila... 😉

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 22 janv. 2013 à 19:05, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :

> Thanks David. Yes i'm using Spring along with ANTLR.
> 
> On Tuesday, January 22, 2013 10:16:31 AM UTC-6, David Pilato wrote:
> 
> > Yes. It's threadsafe. Use one and only one Client in your JVM.
> > 
> > Are you using Spring BTW?
> > 
> > Le 22 janvier 2013 à 17:08, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > 
> > > Hi,
> > > 
> > > I'm using the below code to get a client connection to run a ES query using the Java API.  
> > > However this expensive object creation takes too much of time and and i'm not sure if this object is thread-safe. If it isn't thread-safe then should i be using a connection pool for client objects or is there another way to get and cache connections?
> > > 
> > > Settings settings = ImmutableSettings.settingsBuilder()  
> > > .put("cluster.name", "XXXXX")  
> > > .put("client.transport.sniff", true)  
> > > .put("node.client", true)  
> > > .put("client.transport.ping\_timeout","10s").build();
> > > 
> > > Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));  
> > > SearchRequestBuilder srb = client.prepareSearch(domainName)  
> > > .setSearchType(SearchType.QUERY\_AND\_FETCH)  
> > > .setQuery(query);
> > > 
> > > Thanks,  
> > > John
> > > 
> > > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs  
> > --

--

---

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 30, 2013, 9:36pm UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/7 "2013-01-30T21:36:12Z")

</div>

Yea, will do tht. Thanks.

On Tuesday, 22 January 2013 12:24:30 UTC-6, David Pilato wrote:

> Did you at the elasticsearch spring factory project?
> 
> Just inject your client bean in your classes... Et voila... 😉
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 22 janv. 2013 à 19:05, john \<[john2...@gmail.com](mailto:john2...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Thanks David. Yes i'm using Spring along with ANTLR.
> 
> On Tuesday, January 22, 2013 10:16:31 AM UTC-6, David Pilato wrote:
> 
> > Yes. It's threadsafe. Use one and only one Client in your JVM.
> > 
> > Are you using Spring BTW?
> > 
> > Le 22 janvier 2013 à 17:08, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > 
> > Hi,
> > 
> > I'm using the below code to get a client connection to run a ES query  
> > using the Java API.  
> > However this expensive object creation takes too much of time and and  
> > i'm not sure if this object is thread-safe. If it isn't thread-safe then  
> > should i be using a connection pool for client objects or is there another  
> > way to get and cache connections?
> > 
> > _Settings settings = ImmutableSettings.settingsBuilder()_
> > 
> > - .put("cluster.name", "XXXXX")\*
> > 
> > - .put("client.transport.sniff", true)\*
> > 
> > - .put("node.client", true)\*
> > 
> > - .put("client.transport.ping\_timeout","10s").build();\*
> > 
> > - Client client = new TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9300));\*
> > 
> > - SearchRequestBuilder srb = client.prepareSearch(domainName)\*
> > 
> > - 
> > 
> > ```
> > .setSearchType(SearchType.QUERY_AND_FETCH)* 
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .setQuery(query);* 
> > 
> > ```
> > 
> > - 
> > - 
> > 
> > - 
> > - 
> > 
> > Thanks,  
> > John
> > 
> > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:53am UTC](https://discuss.elastic.co/t/elastic-search-search-connection/10452/8 "2017-07-06T02:53:53Z")

</div>


