Elasticsearch Task Management API

x33g5p2x  于2021-03-14 发布在 ElasticSearch  
字(2.8k)|赞(0)|评价(0)|浏览(465)

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tasks.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/Task+Management+API

贡献者 : [那伊抹微笑]

警告 :

该 Task Management API 是一个新功能,并且仍然处于实验阶段,该 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'③
编号描述
Retrieves all tasks currently running on all nodes in the cluster.
Retrieves all tasks running on nodes nodeId1 and nodeId2. See the section called “Node specificationedit” for more info about how to select individual nodes.
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'

| | This will return a 404 if the task isn’t found. |

或者获取任务所有子任务的信息 : 

curl -XGET 'localhost:9200/_tasks?parent_task_id=parentTaskId:1 &pretty'

如果父任务不存在也不会返回 404 错误。

该任务 API 也可用于等待一个指定的任务完成。在 idoTUltX4IQMOUUVeiohTt8A 的任务完成之前,下面的调用将锁住 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 命令相同的任务选择参数,所以多个任务可以在同时取消。例如,下面的命令将取消所有运行在 nodeId1nodeId2 上的 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'

相关文章