tasks.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [[tasks]]
  2. == Task Management API
  3. experimental[The Task Management API is new and should still be considered experimental. The API may change in ways that are not backwards compatible]
  4. [float]
  5. === Current Tasks Information
  6. The task management API allows to retrieve information about the tasks currently
  7. executing on one or more nodes in the cluster.
  8. [source,js]
  9. --------------------------------------------------
  10. GET _tasks <1>
  11. GET _tasks?nodes=nodeId1,nodeId2 <2>
  12. GET _tasks?nodes=nodeId1,nodeId2&actions=cluster:* <3>
  13. --------------------------------------------------
  14. // CONSOLE
  15. <1> Retrieves all tasks currently running on all nodes in the cluster.
  16. <2> Retrieves all tasks running on nodes `nodeId1` and `nodeId2`. See <<cluster-nodes>> for more info about how to select individual nodes.
  17. <3> Retrieves all cluster-related tasks running on nodes `nodeId1` and `nodeId2`.
  18. The result will look similar to the following:
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "nodes" : {
  23. "oTUltX4IQMOUUVeiohTt8A" : {
  24. "name" : "Tamara Rahn",
  25. "transport_address" : "127.0.0.1:9300",
  26. "host" : "127.0.0.1",
  27. "ip" : "127.0.0.1:9300",
  28. "tasks" : {
  29. "oTUltX4IQMOUUVeiohTt8A:124" : {
  30. "node" : "oTUltX4IQMOUUVeiohTt8A",
  31. "id" : 124,
  32. "type" : "direct",
  33. "action" : "cluster:monitor/tasks/lists[n]",
  34. "start_time_in_millis" : 1458585884904,
  35. "running_time_in_nanos" : 47402,
  36. "cancellable" : false,
  37. "parent_task_id" : "oTUltX4IQMOUUVeiohTt8A:123"
  38. },
  39. "oTUltX4IQMOUUVeiohTt8A:123" : {
  40. "node" : "oTUltX4IQMOUUVeiohTt8A",
  41. "id" : 123,
  42. "type" : "transport",
  43. "action" : "cluster:monitor/tasks/lists",
  44. "start_time_in_millis" : 1458585884904,
  45. "running_time_in_nanos" : 236042,
  46. "cancellable" : false
  47. }
  48. }
  49. }
  50. }
  51. }
  52. --------------------------------------------------
  53. It is also possible to retrieve information for a particular task:
  54. [source,js]
  55. --------------------------------------------------
  56. GET _tasks/taskId:1 <1>
  57. --------------------------------------------------
  58. // CONSOLE
  59. // TEST[catch:missing]
  60. <1> This will return a 404 if the task isn't found.
  61. Or to retrieve all children of a particular task:
  62. [source,js]
  63. --------------------------------------------------
  64. GET _tasks?parent_task_id=parentTaskId:1 <1>
  65. --------------------------------------------------
  66. // CONSOLE
  67. <1> This won't return a 404 if the parent isn't found.
  68. The task API can be also used to wait for completion of a particular task. The following call will
  69. block for 10 seconds or until the task with id `oTUltX4IQMOUUVeiohTt8A:12345` is completed.
  70. [source,js]
  71. --------------------------------------------------
  72. GET _tasks/oTUltX4IQMOUUVeiohTt8A:12345?wait_for_completion=true&timeout=10s
  73. --------------------------------------------------
  74. // CONSOLE
  75. // TEST[catch:missing]
  76. You can also wait for all tasks for certain action types to finish. This
  77. command will wait for all `reindex` tasks to finish:
  78. [source,js]
  79. --------------------------------------------------
  80. GET _tasks?actions=*reindex&wait_for_completion=true&timeout=10s
  81. --------------------------------------------------
  82. // CONSOLE
  83. Tasks can be also listed using _cat version of the list tasks command, which accepts the same arguments
  84. as the standard list tasks command.
  85. [source,js]
  86. --------------------------------------------------
  87. GET _cat/tasks
  88. --------------------------------------------------
  89. // CONSOLE
  90. [float]
  91. === Task Cancellation
  92. If a long-running task supports cancellation, it can be cancelled by the following command:
  93. [source,js]
  94. --------------------------------------------------
  95. POST _tasks/taskId:1/_cancel
  96. --------------------------------------------------
  97. // CONSOLE
  98. The task cancellation command supports the same task selection parameters as the list tasks command, so multiple tasks
  99. can be cancelled at the same time. For example, the following command will cancel all reindex tasks running on the
  100. nodes `nodeId1` and `nodeId2`.
  101. [source,js]
  102. --------------------------------------------------
  103. POST _tasks/_cancel?node_id=nodeId1,nodeId2&actions=*reindex
  104. --------------------------------------------------
  105. // CONSOLE
  106. [float]
  107. === Task Grouping
  108. The task lists returned by task API commands can be grouped either by nodes (default) or by parent tasks using the `group_by` parameter.
  109. The following command will change the grouping to parent tasks:
  110. [source,js]
  111. --------------------------------------------------
  112. GET _tasks?group_by=parents
  113. --------------------------------------------------
  114. // CONSOLE