# Client per request question

**URL:** <https://discuss.elastic.co/t/client-per-request-question/5506>\
**Category:** Elasticsearch\
**Created:** [October 3, 2011, 7:53pm UTC](https://discuss.elastic.co/t/client-per-request-question/5506 "2011-10-03T19:53:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@Neil1](https://discuss.elastic.co/u/Neil1)\
**Post date:** [October 3, 2011, 7:53pm UTC](https://discuss.elastic.co/t/client-per-request-question/5506/1 "2011-10-03T19:53:54Z")

</div>

Hi,

I'm using the java api and for searching I'd like to know whether I  
can use the same client for every search request that comes through,  
or do I need to create a new client for each request?

Namely, is the client thread safe for its given request?

Then how does this tie in with the OperationThreaded described here:

[http://www.elasticsearch.org/guide/reference/java-api/search.html](http://www.elasticsearch.org/guide/reference/java-api/search.html)

NO\_THREADS  
SINGLE\_THREAD  
THREAD\_PER\_SHARD

I'm not seeing how to set these fields in the GetRequestBuilder.

Also, what does the realtime method do in the GetRequestBuilder?

Thanks,

Neil

---

<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:** [October 3, 2011, 8:55pm UTC](https://discuss.elastic.co/t/client-per-request-question/5506/2 "2011-10-03T20:55:16Z")

</div>

You should use the same client for all requests, its thread safe. The  
operation threaded for search request controls how the search is executed on  
a node, and usually not really relevant for remote clients.

The realtime flag for get request controls if "realtime" get will be used or  
not (by default, realtime get is enabled, and you can get a document once  
indexed regardless of the refresh interval of the index or if it was  
refreshed or not).

On Mon, Oct 3, 2011 at 9:53 PM, Neil [neilmatthewlott@gmail.com](mailto:neilmatthewlott@gmail.com) wrote:

> Hi,
> 
> I'm using the java api and for searching I'd like to know whether I  
> can use the same client for every search request that comes through,  
> or do I need to create a new client for each request?
> 
> Namely, is the client thread safe for its given request?
> 
> Then how does this tie in with the OperationThreaded described here:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/search.html)
> 
> NO\_THREADS  
> SINGLE\_THREAD  
> THREAD\_PER\_SHARD
> 
> I'm not seeing how to set these fields in the GetRequestBuilder.
> 
> Also, what does the realtime method do in the GetRequestBuilder?
> 
> Thanks,
> 
> Neil

---

<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, 3:52am UTC](https://discuss.elastic.co/t/client-per-request-question/5506/3 "2017-07-06T03:52:57Z")

</div>


