How to delete a task in Elasticsearch v7.14

I'm currently running a delete_by_query job and setting the wait_for_completion argument to false.

In the documentation, it says:

Running delete by query asynchronously

If the request contains wait_for_completion=false , Elasticsearch performs some preflight checks, launches the request, and returns a task you can use to cancel or get the status of the task. Elasticsearch creates a record of this task as a document at .tasks/task/${taskId} . When you are done with a task, you should delete the task document so Elasticsearch can reclaim the space.

However, I haven't found any information about how to delete task documents. All the task management APIs I've looked at only have the /get, /list, and /cancel. No /delete !

How do I delete a task from an elasticsearch cluster?

Relevant info:

  • Elasticsearch version: 7.14

Task management

Task cancellation

curl -X POST "localhost:9200/_tasks/oTUltX4IQMOUUVeiohTt8A:12345/_cancel?pretty"

Is task cancellation the same thing as task deletion?

The task will have finished, so using the /cancel endpoint doesn't make a lot of sense to me. I need to use a /delete endpoint if I need to do what the docs suggest:

When you are done with a task, you should delete the task document so Elasticsearch can reclaim the space.


Interesting... I did not read your OP close enough, I have never deleted a task manually nor really thought about it because on the clusters I have the .tasks index is so small relative to my data indices.

Typically it is not recommended to operate on the . system indices directly perhaps this is still a valid case with tasks.

Perhaps @DavidTurner can comment on the manually deleting the task document.

Maybe the docs are outdated? Maybe manually deleting tasks after running async search_by_query operations is no longer needed?

I don't know much more than what you said. The .tasks index dates back to a time when manually deleting things would have been the only option. I see code for recording new task results (and retrieving them by ID) but I see no mechanism that would delete anything from this index so it looks like a manual delete is still the only option.

There's an issue open for the things left to do before we can stop calling the task management feature "experimental", but it's pretty far down the priority list right now:

I added the phrase "and a mechanism for cleaning up older results once no longer needed" in reaction to this conversation at least.

1 Like

So @Tim_Estes

All that said IF you still want to delete that task document (which is probably not necessary)

Execute the following in Kibana Dev Tools

This is simply a document DELETE see here
DELETE .tasks/task/_doc/<yourtaskid> .

Amazing. Thanks for the replies gentlemen.