Elastic Search cancel long running task

8.6k Views Asked by At

For Elastic Search version 6.0

to cancel a running task:

POST _tasks/node_id:task_id/_cancel

I am following the same statement, but in actual it is unable to cancel the task. After running this command if I run get command to fetch all running task, the particular task don't get cancel.

If I hit cancel statement again, it gives statement that task_id is already cancelled but in reality it doesn't get cancel.

1

There are 1 best solutions below

11
Val On

Calling the _tasks/<id>/_cancel endpoint only signifies to ES that the task should be cancelled. ES will then cancel the task as soon as it possibly can.

It might not be immediate, though, for instance, if you have a very complex search that takes a long time (e.g. wildcard queries with leading wildcards).

If you check the ContextIndexSearcher class and look for all places where checkCancelled.run() is called, those are the only phases when a query can be cancelled, but sometimes a phase can take a long time before being eligible for cancellation.

If your task is a search task, then you might try to leverage the timeout parameter to see if it helps (it might not always for the same reasons as mentioned above).