**同步结果摘要**: | 目录 | 同步前 | 同步后 | 官方 | |------|--------|--------|------| | aggregations | 40 | 65 | 64 | | analyzers | 8 | 141 | 140 | | api-reference | 97 | 186 | 174 | | benchmark | 34 | 67 | 53 | | clients | 17 | 18 | 18 | | dashboards | 38 | 149 | 131 | | data-prepper | 77 | 134 | 123 | | im-plugin | 22 | 37 | 37 | | ingest-pipelines | 27 | 52 | 51 | | install-and-configure | 37 | 57 | 53 | | ml-commons-plugin | 81 | 157 | 155 | | observing-your-data | 39 | 73 | 66 | | query-dsl | 40 | 77 | 75 | | search-plugins | 80 | 139 | 95 | | security-analytics | 22 | 47 | 46 | **说明**: - 本地文件数 > 官方:本地有一些官方已删除或重命名的文件 - 新增了约 **740 个英文文档文件** - 已有文件保持不变(未覆盖)
4.3 KiB
layout, title, parent, nav_order
| layout | title | parent | nav_order |
|---|---|---|---|
| default | Cancel tasks | Tasks APIs | 40 |
Cancel Tasks API
Introduced 1.0 {: .label .label-purple }
The Cancel Tasks API cancels a task, stopping it from running in the cluster. Not all tasks can be canceled. To determine whether a task is cancelable, check the cancellable field in the Cancel Tasks API response.
Endpoints
POST /_tasks/_cancel
POST /_tasks/{task_id}/_cancel
Path parameters
The following table lists the available path parameters. All path parameters are optional.
| Parameter | Data type | Description |
|---|---|---|
task_id |
String | The task ID. |
Query parameters
The following table lists the available query parameters. All query parameters are optional.
| Parameter | Data type | Description |
|---|---|---|
actions |
List or String | A comma-separated list of actions that should be returned. Keep empty to return all. |
nodes |
List | A comma-separated list of node IDs or names used to limit the returned information. Use _local to return information from the node you're connecting to, specify the node name to get information from a specific node, or keep the parameter empty to get information from all nodes. |
parent_task_id |
String | Returns tasks with a specified parent task ID (node_id:task_number). Keep empty or set to -1 to return all. |
wait_for_completion |
Boolean | Waits for the matching task to complete. When true, the request is blocked until the task has completed. (Default: false) |
Example request
The following request cancels any tasks currently running on opensearch-node1 and opensearch-node2:
{% capture step1_rest %} POST /_tasks/_cancel?nodes=opensearch-node1,opensearch-node2 {% endcapture %}
{% capture step1_python %}
response = client.tasks.cancel( params = { "nodes": "opensearch-node1,opensearch-node2" } )
{% endcapture %}
{% include code-block.html rest=step1_rest python=step1_python %}
Example response
The following response shows that a bulk write and update task were canceled without a node failure and provides additional information about the canceled tasks:
{
"node_failures": [],
"nodes": {
"JzrCxdtFTCO_RaINw8ckNA": {
"name": "opensearch-node1",
"transport_address": "127.0.0.1:9300",
"host": "127.0.0.1",
"ip": "127.0.0.1:9300",
"roles": [
"data",
"ingest",
"cluster_manager",
"remote_cluster_client"
],
"attributes": {},
"tasks": {
"JzrCxdtFTCO_RaINw8ckNA:54": {
"node": "JzrCxdtFTCO_RaINw8ckNA",
"id": 54,
"type": "transport",
"action": "indices:data/write/bulk",
"status": "cancelled",
"description": "bulk request to [test_index]",
"start_time_in_millis": 1625145678901,
"running_time_in_nanos": 2345678,
"cancellable": true,
"cancelled": true
}
}
},
"K8iyDdtGQCO_SbJNw9dkMB": {
"name": "opensearch-node2",
"transport_address": "127.0.0.1:9301",
"host": "127.0.0.1",
"ip": "127.0.0.1:9301",
"roles": [
"data",
"ingest",
"master",
"remote_cluster_client"
],
"attributes": {},
"tasks": {
"K8iyDdtGQCO_SbJNw9dkMB:78": {
"node": "K8iyDdtGQCO_SbJNw9dkMB",
"id": 78,
"type": "transport",
"action": "indices:data/write/update",
"status": "cancelled",
"description": "updating document in [another_index]",
"start_time_in_millis": 1625145679012,
"running_time_in_nanos": 1234567,
"cancellable": true,
"cancelled": true
}
}
}
}
}
Required permissions
If you use the Security plugin, make sure you have the appropriate permissions: cluster:admin/tasks/cancel.