# Cancelling Search Request & Search Query Timeout

**URL:** <https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608>\
**Category:** Elasticsearch\
**Created:** [April 17, 2013, 6:35am UTC](https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608 "2013-04-17T06:35:03Z")\
**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, 6:35am UTC](https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608/1 "2013-04-17T06:35:03Z")

</div>

Hi Team,

We use the following statements (only partial) to get the search response -

```
SearchRequestBuilder builder = null;
SearchResponse res= builder .execute().actionGet();

```

Can we cancel the above search request!

Also we use the following statement to set the query timeout value in the SearchRequestBuilder instance -

```
SearchRequestBuilder builder= TransportClient.prepareSearch().setTimeout(...);

```

Here TransportClient has already been initialized. We set the timeout to 1 minutes. It happen sometimes that we don't get the response in 1 minutes and even query is not timed out, that is query is executing on ES server. We don't get any exception either. Can someone please explain the scenarios when query will be timed out or not timed out! Do we need to set some other way.

We have a GWT web application and when user don't get response in a certain time he started to get impatient and hit the submit button again. For this we have decided to disable the submit button and enable it only when we get back the response. But in cases where query doesn't return any response or throw exceptions, in certain time user waits longer & longer.

Please suggest.

Thanks.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [April 17, 2013, 5:37pm UTC](https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608/2 "2013-04-17T17:37:06Z")

</div>

The search request cannot be cancelled. From my understanding of the code,  
the timeout value is used only as a parameter to the TimeLimitingCollector  
wrapper around elasticsearch's facet collectors. There have been other  
discussion regarding long queries not respecting the timeout value.

--  
Ivan

On Tue, Apr 16, 2013 at 11:35 PM, ElasticUsers [kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com)wrote:

> Hi Team,
> 
> We use the following statements (only partial) to get the search response -
> 
> ```
> SearchRequestBuilder builder = null;
> SearchResponse res= builder .execute().actionGet();
> 
> ```
> 
> Can we cancel the above search request!
> 
> Also we use the following statement to set the query timeout value in the  
> SearchRequestBuilder instance -
> 
> ```
> SearchRequestBuilder builder=
> 
> ```
> 
> TransportClient.prepareSearch().setTimeout(...);
> 
> Here TransportClient has already been initialized. We set the timeout to 1  
> minutes. It happen sometimes that we don't get the response in 1 minutes  
> and  
> even query is not timed out, that is query is executing on ES server. We  
> don't get any exception either. Can someone please explain the scenarios  
> when query will be timed out or not timed out! Do we need to set some other  
> way.
> 
> We have a GWT web application and when user don't get response in a certain  
> time he started to get impatient and hit the submit button again. For this  
> we have decided to disable the submit button and enable it only when we get  
> back the response. But in cases where query doesn't return any response or  
> throw exceptions, in certain time user waits longer & longer.
> 
> Please suggest.
> 
> Thanks.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Cancelling-Search-Request-Search-Query-Timeout-tp4033510.html](http://elasticsearch-users.115913.n3.nabble.com/Cancelling-Search-Request-Search-Query-Timeout-tp4033510.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).

--  
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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [April 17, 2013, 7:37pm UTC](https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608/3 "2013-04-17T19:37:47Z")

</div>

Note that actionGet() can be replaced by a time-limited version, for example

SearchResponse response = builder.execute().actionGet()

--\>

SearchResponse response = builder.execute().actionGet(1, TimeUnit.MINUTES)

As said, this does not stop a running query execution, but it returns to  
the requester if the execution times out with an  
org.elasticsearch.ElasticSearchInterruptedException

Jörg

Am 17.04.13 19:37, schrieb Ivan Brusic:

> The search request cannot be cancelled. From my understanding of the  
> code, the timeout value is used only as a parameter to  
> the TimeLimitingCollector wrapper around elasticsearch's facet  
> collectors. There have been other discussion regarding long queries  
> not respecting the timeout value.
> 
> --  
> Ivan
> 
> On Tue, Apr 16, 2013 at 11:35 PM, ElasticUsers  
> \<[kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com) [mailto:kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com)\> wrote:
> 
> ```
> Hi Team,
> 
> We use the following statements (only partial) to get the search
> response -
> 
> SearchRequestBuilder builder = null;
> SearchResponse res= builder .execute().actionGet();
> 
> Can we cancel the above search request!
> 
> Also we use the following statement to set the query timeout value
> in the
> SearchRequestBuilder instance -
> 
> SearchRequestBuilder builder=
> TransportClient.prepareSearch().setTimeout(...);
> 
> Here TransportClient has already been initialized. We set the
> timeout to 1
> minutes. It happen sometimes that we don't get the response in 1
> minutes and
> even query is not timed out, that is query is executing on ES
> server. We
> don't get any exception either. Can someone please explain the
> scenarios
> when query will be timed out or not timed out! Do we need to set
> some other
> way.
> 
> We have a GWT web application and when user don't get response in
> a certain
> time he started to get impatient and hit the submit button again.
> For this
> we have decided to disable the submit button and enable it only
> when we get
> back the response. But in cases where query doesn't return any
> response or
> throw exceptions, in certain time user waits longer & longer.
> 
> Please suggest.
> 
> Thanks.
> 
> --
> View this message in context:
> http://elasticsearch-users.115913.n3.nabble.com/Cancelling-Search-Request-Search-Query-Timeout-tp4033510.html
> Sent from the ElasticSearch Users mailing list archive at 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%2Bunsubscribe@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> ```
> 
> --  
> 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).

--  
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:40am UTC](https://discuss.elastic.co/t/cancelling-search-request-search-query-timeout/11608/4 "2017-07-06T02:40:45Z")

</div>


