# Search Cancellation mechanism on timeout before v.6.4.0

**URL:** <https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 3:04pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559 "2019-01-09T15:04:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Bokii](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@Ivan\_Bokii](https://discuss.elastic.co/u/Ivan_Bokii)\
**Post date:** [January 9, 2019, 3:04pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/1 "2019-01-09T15:04:18Z")

</div>

The 6.4.0 version of "Search Request Body" reference ([https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#\_parameters\_4](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#_parameters_4)) says that "Search Cancellation" mechanism is used on search timeout.

I am running v.6.3.0 and curious if the same mechanism is used when searches timeout or it was updated between versions 6.3.0 and 6.4.0. Would appreciate any information on what exactly happens when search hits timeout and what does it mean for a search to hit a timeout.

Thank you!

---

<div class="post-metadata">

**Author:** ![Ivan\_Bokii](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@Ivan\_Bokii](https://discuss.elastic.co/u/Ivan_Bokii)\
**Post date:** [January 9, 2019, 4:09pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/2 "2019-01-09T16:09:52Z")

</div>

The same "Search Request Body" reference in prev. versions (for example: v.6.3.0) doesn't mention "Search Cancellation" mechanism for the timeout parameter.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 9, 2019, 4:51pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/3 "2019-01-09T16:51:53Z")

</div>

> [@Ivan\_Bokii](#):
>
> curious if the same mechanism is used

I'm not familiar with the specific timeout changes between those versions but it's true to say that the implementation is constantly improving/evolving.  
The challenge is adding "timed out yet?" checks into all the various code loops that execute as part of search without significantly slowing down the search execution. These loops exist in multiple places, including the Lucene library.  
If we miss a loop eg some regex expansion logic\*, then it means that certain queries may overrun and take longer than the timeout setting defines. If we add a check into a very tight loop then we slow down search. This is why we say it is a "best effort" approach and is evolving.

\* (we may check regex expansion logic. I only use it as an example.)

---

<div class="post-metadata">

**Author:** ![Ivan\_Bokii](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@Ivan\_Bokii](https://discuss.elastic.co/u/Ivan_Bokii)\
**Post date:** [January 9, 2019, 5:23pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/4 "2019-01-09T17:23:40Z")

</div>

Hi @Mark_Harwood, thank you for the answer.

The cluster that I'm running has a lot of long-running queries. I am after building a query killer that periodically checks the list of search tasks (using Task Management API) and cancelling the ones that pass some pre-defined time-threshold (for example, 1 min).

Looks like, if I was running a newer version, 6.5.0, I wouldn't need to implement anything, since the same cancellation mechanism is used for search timeouts. If v.6.3.0 uses the same cancellation mechanism, it'd save me some time. Any suggestions on what'd be a good way to find out if Task Management API (i.e. task cancellation from it) is used in v.6.3.0 when search times out?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [January 9, 2019, 6:22pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/5 "2019-01-09T18:22:36Z")

</div>

That sentence was added to the docs in [#33354](https://github.com/elastic/elasticsearch/pull/33354) to resolve [#31263](https://github.com/elastic/elasticsearch/issues/31263) which arose from a question from a user about how search cancellation worked in 6.2.4. I don't think anything significant changed, it was just a clarification to the docs that wasn't backported because we don't normally backport this kind of thing.

---

<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:** [February 6, 2019, 6:22pm UTC](https://discuss.elastic.co/t/search-cancellation-mechanism-on-timeout-before-v-6-4-0/163559/6 "2019-02-06T18:22:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
