# setTimeout() of SearchRequestBuilder not working

**URL:** <https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611>\
**Category:** Elasticsearch\
**Created:** [April 17, 2013, 9:27am UTC](https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611 "2013-04-17T09:27:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [April 17, 2013, 9:27am UTC](https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611/1 "2013-04-17T09:27:01Z")

</div>

Hi,

I have a query on method setTimeout() of SearchRequestBuilder. We have set a timeout value of 1 milliseconds while creating SearchRequestBuilder to execute the query. When we get the SearchResponse object and extract total time taken by executing the method getTookInMillis() of SearchResponse class, the total time comes as 100 milliseconds. That means query should have timed out as we have set time out value of 1 milliseconds earlier, still we are getting the result. It means that timeout value set in SearchRequestBuilder is not working.

When we check the docs for SearchRequestBuilder, it says that setTimeout() method allow us to set 'an optional timeout to control how long search is allowed to take'.

Can you please suggest if we are interpreting or doing something wrong!

Thanks.

---

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [April 17, 2013, 7:08pm UTC](https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611/2 "2013-04-17T19:08:32Z")

</div>

This happens to me too; see this;

> <https://github.com/elastic/elasticsearch/issues/2520>
>
> I have seen many issues related to that, but nobody seems to have found an answe…r to this one, so I'm opening a new issue.
> 
> This is what I'm doing in the Java API for search;
> https://gist.github.com/4444788
> 
> And even if I put a 2 sec timeout, I have often requests that take more than 5 and even 10 seconds that does not time out. But sometime, I have some query that take under 2 sec and says timed out. 
> 
> On the documentation it says; 
> timeout A search timeout, bounding the search request to be executed within the specified time value and bail with the hits accumulated up to that point when expired. Defaults to no timeout.
> 
> With that I'm expecting every query to be under (or roughly) around 2 second, but not 5 or 10 seconds.

On Wednesday, April 17, 2013 5:27:01 AM UTC-4, Kranti wrote:

> Hi,
> 
> I have a query on method setTimeout() of SearchRequestBuilder. We have set  
> a  
> timeout value of 1 milliseconds while creating SearchRequestBuilder to  
> execute the query. When we get the SearchResponse object and extract total  
> time taken by executing the method getTookInMillis() of SearchResponse  
> class, the total time comes as 100 milliseconds. That means query should  
> have timed out as we have set time out value of 1 milliseconds earlier,  
> still we are getting the result. It means that timeout value set in  
> SearchRequestBuilder is not working.
> 
> When we check the docs for SearchRequestBuilder, it says that setTimeout()  
> method allow us to set 'an optional timeout to control how long search is  
> allowed to take'.
> 
> Can you please suggest if we are interpreting or doing something wrong!
> 
> Thanks.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/setTimeout-of-SearchRequestBuilder-not-working-tp4033517.html](http://elasticsearch-users.115913.n3.nabble.com/setTimeout-of-SearchRequestBuilder-not-working-tp4033517.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [April 22, 2013, 5:56am UTC](https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611/3 "2013-04-22T05:56:36Z")

</div>

Thanks for sharing the information.

---

<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:40am UTC](https://discuss.elastic.co/t/settimeout-of-searchrequestbuilder-not-working/11611/4 "2017-07-06T02:40:14Z")

</div>


