tasks.asciidoc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. [[tasks]]
  2. == Task Management API
  3. beta[The Task Management API is new and should still be considered a beta feature. 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" : "H5dfFeA",
  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. // NOTCONSOLE
  54. // We can't test tasks output
  55. It is also possible to retrieve information for a particular task:
  56. [source,js]
  57. --------------------------------------------------
  58. GET _tasks/task_id:1 <1>
  59. --------------------------------------------------
  60. // CONSOLE
  61. // TEST[catch:missing]
  62. <1> This will return a 404 if the task isn't found.
  63. Or to retrieve all children of a particular task:
  64. [source,js]
  65. --------------------------------------------------
  66. GET _tasks?parent_task_id=parentTaskId:1 <1>
  67. --------------------------------------------------
  68. // CONSOLE
  69. <1> This won't return a 404 if the parent isn't found.
  70. You can also use the `detailed` request parameter to get more information about
  71. the running tasks. This is useful for telling one task from another but is more
  72. costly to execute. For example, fetching all searches using the `detailed`
  73. request parameter:
  74. [source,js]
  75. --------------------------------------------------
  76. GET _tasks?actions=*search&detailed
  77. --------------------------------------------------
  78. // CONSOLE
  79. might look like:
  80. [source,js]
  81. --------------------------------------------------
  82. {
  83. "nodes" : {
  84. "oTUltX4IQMOUUVeiohTt8A" : {
  85. "name" : "H5dfFeA",
  86. "transport_address" : "127.0.0.1:9300",
  87. "host" : "127.0.0.1",
  88. "ip" : "127.0.0.1:9300",
  89. "tasks" : {
  90. "oTUltX4IQMOUUVeiohTt8A:464" : {
  91. "node" : "oTUltX4IQMOUUVeiohTt8A",
  92. "id" : 464,
  93. "type" : "transport",
  94. "action" : "indices:data/read/search",
  95. "description" : "indices[test], types[test], search_type[QUERY_THEN_FETCH], source[{\"query\":...}]",
  96. "start_time_in_millis" : 1483478610008,
  97. "running_time_in_nanos" : 13991383,
  98. "cancellable" : true
  99. }
  100. }
  101. }
  102. }
  103. }
  104. --------------------------------------------------
  105. // NOTCONSOLE
  106. // We can't test tasks output
  107. The new `description` field contains human readable text that identifies the
  108. particular request that the task is performing such as identifying the search
  109. request being performed by a search task like the example above. Other kinds of
  110. task have have different descriptions, like <<docs-reindex,`_reindex`>> which
  111. has the search and the destination, or <<docs-bulk,`_bulk`>> which just has the
  112. number of requests and the destination indices. Many requests will only have an
  113. empty description because more detailed information about the request is not
  114. easily available or particularly helpful in identifying the request.
  115. The task API can also be used to wait for completion of a particular task. The
  116. following call will block for 10 seconds or until the task with id
  117. `oTUltX4IQMOUUVeiohTt8A:12345` is completed.
  118. [source,js]
  119. --------------------------------------------------
  120. GET _tasks/oTUltX4IQMOUUVeiohTt8A:12345?wait_for_completion=true&timeout=10s
  121. --------------------------------------------------
  122. // CONSOLE
  123. // TEST[catch:missing]
  124. You can also wait for all tasks for certain action types to finish. This
  125. command will wait for all `reindex` tasks to finish:
  126. [source,js]
  127. --------------------------------------------------
  128. GET _tasks?actions=*reindex&wait_for_completion=true&timeout=10s
  129. --------------------------------------------------
  130. // CONSOLE
  131. Tasks can be also listed using _cat version of the list tasks command, which
  132. accepts the same arguments as the standard list tasks command.
  133. [source,js]
  134. --------------------------------------------------
  135. GET _cat/tasks
  136. GET _cat/tasks?detailed
  137. --------------------------------------------------
  138. // CONSOLE
  139. [float]
  140. [[task-cancellation]]
  141. === Task Cancellation
  142. If a long-running task supports cancellation, it can be cancelled by the following command:
  143. [source,js]
  144. --------------------------------------------------
  145. POST _tasks/node_id:task_id/_cancel
  146. --------------------------------------------------
  147. // CONSOLE
  148. // TEST[s/task_id/1/]
  149. The task cancellation command supports the same task selection parameters as the list tasks command, so multiple tasks
  150. can be cancelled at the same time. For example, the following command will cancel all reindex tasks running on the
  151. nodes `nodeId1` and `nodeId2`.
  152. [source,js]
  153. --------------------------------------------------
  154. POST _tasks/_cancel?nodes=nodeId1,nodeId2&actions=*reindex
  155. --------------------------------------------------
  156. // CONSOLE
  157. [float]
  158. === Task Grouping
  159. The task lists returned by task API commands can be grouped either by nodes (default) or by parent tasks using the `group_by` parameter.
  160. The following command will change the grouping to parent tasks:
  161. [source,js]
  162. --------------------------------------------------
  163. GET _tasks?group_by=parents
  164. --------------------------------------------------
  165. // CONSOLE