tasks.asciidoc 6.4 KB

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