企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Task Management API ## Current Tasks Information(当前任务信息) **task management API** 可以获取关于集群中一个或多个节点正在执行中的任务的信息。 | `curl -XGET ``'localhost:9200/_tasks ?pretty'``①` `curl -XGET ``'localhost:9200/_tasks?nodes=nodeId1,nodeId2 &pretty'``②` `curl -XGET ``'localhost:9200/_tasks?nodes=nodeId1,nodeId2&actions=cluster:* &pretty'``③` | | 编号 | 描述 | | --- | --- | | [![](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/images/icons/callouts/1.png)](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tasks.html#CO135-1) | Retrieves all tasks currently running on all nodes in the cluster. | | [![](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/images/icons/callouts/2.png)](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tasks.html#CO135-2) | Retrieves all tasks running on nodes `nodeId1` and `nodeId2`. See [the section called “Node specification](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cluster.html#cluster-nodes "Node specificationedit")[edit](https://github.com/elastic/elasticsearch/edit/5.0/docs/reference/cluster.asciidoc "Edit this page on GitHub")” for more info about how to select individual nodes. | | [![](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/images/icons/callouts/3.png)](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tasks.html#CO135-3) | Retrieves all cluster-related tasks running on nodes `nodeId1` and `nodeId2`. | 返回结果看起来如下 :  | `{` `"nodes"` `: {` `"oTUltX4IQMOUUVeiohTt8A"` `: {` `"name"` `: ``"H5dfFeA"``,` `"transport_address"` `: ``"127.0.0.1:9300"``,` `"host"` `: ``"127.0.0.1"``,` `"ip"` `: ``"127.0.0.1:9300"``,` `"tasks"` `: {` `"oTUltX4IQMOUUVeiohTt8A:124"` `: {` `"node"` `: ``"oTUltX4IQMOUUVeiohTt8A"``,` `"id"` `: 124,` `"type"` `: ``"direct"``,` `"action"` `: ``"cluster:monitor/tasks/lists[n]"``,` `"start_time_in_millis"` `: 1458585884904,` `"running_time_in_nanos"` `: 47402,` `"cancellable"` `: ``false``,` `"parent_task_id"` `: ``"oTUltX4IQMOUUVeiohTt8A:123"` `},` `"oTUltX4IQMOUUVeiohTt8A:123"` `: {` `"node"` `: ``"oTUltX4IQMOUUVeiohTt8A"``,` `"id"` `: 123,` `"type"` `: ``"transport"``,` `"action"` `: ``"cluster:monitor/tasks/lists"``,` `"start_time_in_millis"` `: 1458585884904,` `"running_time_in_nanos"` `: 236042,` `"cancellable"` `: ``false` `}` `}` `}` `}` `}` | 也可以获取指定任务的信息 :  | `curl -XGET ``'localhost:9200/_tasks/task_id:1 ?pretty'` | | [![](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/images/icons/callouts/1.png)](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tasks.html#CO136-1) | This will return a 404 if the task isn’t found. | 或者获取任务所有子任务的信息 :  | `curl -XGET ``'localhost:9200/_tasks?parent_task_id=parentTaskId:1 &pretty'` | 如果父任务不存在也不会返回 404 错误。 该任务 **API** 也可用于等待一个指定的任务完成。在 **id** 为**oTUltX4IQMOUUVeiohTt8A** 的任务完成之前,下面的调用将锁住 **10** 秒。 | `curl -XGET ``'localhost:9200/_tasks/oTUltX4IQMOUUVeiohTt8A:12345?wait_for_completion=true&timeout=10s&pretty'` | 你可以等待所有任务中的某个动作类型直到完成。这个命令将等待所有的**reindex** 任务直到完成 :  | `curl -XGET ``'localhost:9200/_tasks?actions=*reindex&wait_for_completion=true&timeout=10s&pretty'` | 可以使用 **_cat** 列出任务命令列表,它接受与标准的 **list task** 命令相同的参数。 | `curl -XGET ``'localhost:9200/_cat/tasks?pretty'` | ## Task Cancellation(任务取消) 如果一个长期运行的任务支持取消,可以通过下列的命令来取消它 :  | `curl -XPOST ``'localhost:9200/_tasks/task_id:1/_cancel?pretty'` | 该任务取消命令支持和 **list tasks** 命令相同的任务选择参数,所以多个任务可以在同时取消。例如,下面的命令将取消所有运行在 **nodeId1** 和 **nodeId2** 上的**reindex** 任务。 | `curl -XPOST ``'localhost:9200/_tasks/_cancel?nodes=nodeId1,nodeId2&actions=*reindex&pretty'` | ## Task Grouping(任务组) 通过使用 **task API** 命令使用 **group_by** 参数可以通过 **nodes**(默认)或者父任务来分组以返回任务列表。下面的命令将改变分组为父任务 :  | `curl -XGET ``'localhost:9200/_tasks?group_by=parents&pretty'` |