# How to delete a task in Elasticsearch v7.14

**URL:** <https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321>\
**Category:** Elasticsearch\
**Created:** [September 3, 2021, 9:38pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321 "2021-09-03T21:38:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Estes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_estes/32/64928_2.png) [@Tim\_Estes](https://discuss.elastic.co/u/Tim_Estes)\
**Post date:** [September 3, 2021, 9:38pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/1 "2021-09-03T21:38:59Z")

</div>

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

In [the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html), 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`](https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) 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](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/tasks.html) 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

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [September 4, 2021, 2:17am UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/2 "2021-09-04T02:17:06Z")

</div>

[Task management](https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html#tasks)

[Task cancellation](https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html#task-cancellation)

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

```

---

<div class="post-metadata">

**Author:** ![Tim\_Estes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_estes/32/64928_2.png) [@Tim\_Estes](https://discuss.elastic.co/u/Tim_Estes)\
**Post date:** [September 7, 2021, 4:06pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/3 "2021-09-07T16:06:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [September 7, 2021, 4:19pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/4 "2021-09-07T16:19:15Z")

</div>

@Tim_Estes

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Estes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_estes/32/64928_2.png) [@Tim\_Estes](https://discuss.elastic.co/u/Tim_Estes)\
**Post date:** [September 7, 2021, 4:33pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/5 "2021-09-07T16:33:04Z")

</div>

Maybe [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html#docs-delete-by-query-task-api) are outdated? Maybe manually deleting tasks after running async search\_by\_query operations is no longer needed?

---

<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:** [September 7, 2021, 4:55pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/6 "2021-09-07T16:55:55Z")

</div>

> [@stephenb](#):
>
> Perhaps @DavidTurner can comment on the manually deleting the task document.

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:

> <https://github.com/elastic/elasticsearch/issues/51628>
>
> This is an experimental status issue, documenting the known remains before the \[…Task management API\](https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html) can move out of experimental/beta state.
> 
> The primary outstanding items on the API is cementing the intentions of the API usage and its backwards compatibility guarantees. This was discussed in some detail \[here\](https://github.com/elastic/elasticsearch/pull/47378#issuecomment-546236503). This in turn adds work in several areas.
> 
> Following are the expected remaining actions before removing the experimental/beta status:
> 
> \- \[\] Reframe the tasks API as a powerful troubleshooting tool that should not be used for building applications (discuss + docs).
> \- \[x\] Clarify in docs that only the basic structure of the tasks API follows our backwards compatibliity principles. The structure (parent/child) of tasks, action names, descriptions, status and more can change in any release, including potentially micro/bugfix.
> \- \[\] Remove \`node\` and \`id\` from response (#31253)
> \- \[\] Ensure we do not use \`ListTasksResponse\` as response type for \`rethrottle\` (part of #42612)
> \- \[\] Add explicit cancel APIs where appropriate to not point users to the task cancel API.
> \- \[\] Similarly add explicit APIs for obtaining the result of tasks submitted with \`wait\_for\_completion=false\` (at least update and delete-by-query) and a mechanism for cleaning up older results once no longer needed.
> \- \[\] Remove the ability to view persisted task results, since these should be obtained through dedicated APIs (notice: the ephemeral task id is inherently unsafe to use, since it may be reused after node restarts). 
> \- \[\] (optional) Add \`manage\_tasks\` security privilege.

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

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [September 7, 2021, 5:31pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/7 "2021-09-07T17:31:35Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html)  
`DELETE .tasks/task/_doc/<yourtaskid>` .

---

<div class="post-metadata">

**Author:** ![Tim\_Estes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_estes/32/64928_2.png) [@Tim\_Estes](https://discuss.elastic.co/u/Tim_Estes)\
**Post date:** [September 7, 2021, 5:49pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/8 "2021-09-07T17:49:45Z")

</div>

Amazing. Thanks for the replies gentlemen.

---

<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:** [October 5, 2021, 5:49pm UTC](https://discuss.elastic.co/t/how-to-delete-a-task-in-elasticsearch-v7-14/283321/9 "2021-10-05T17:49:50Z")

</div>

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