tasks.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // AUTOSENSE
  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, or all children of a particular
  54. tasks using the following two commands:
  55. [source,js]
  56. --------------------------------------------------
  57. GET _tasks/taskId:1
  58. GET _tasks?parent_task_id=parentTaskId:1
  59. --------------------------------------------------
  60. // AUTOSENSE
  61. The task API can be also used to wait for completion of a particular task. The following call will
  62. block for 10 seconds or until the task with id `oTUltX4IQMOUUVeiohTt8A:12345` is completed.
  63. [source,js]
  64. --------------------------------------------------
  65. GET _tasks/oTUltX4IQMOUUVeiohTt8A:12345?wait_for_completion=true&timeout=10s
  66. --------------------------------------------------
  67. // AUTOSENSE
  68. Tasks can be also listed using _cat version of the list tasks command, which accepts the same arguments
  69. as the standard list tasks command.
  70. [source,js]
  71. --------------------------------------------------
  72. GET _cat/tasks
  73. --------------------------------------------------
  74. // AUTOSENSE
  75. [float]
  76. === Task Cancellation
  77. If a long-running task supports cancellation, it can be cancelled by the following command:
  78. [source,js]
  79. --------------------------------------------------
  80. POST _tasks/taskId:1/_cancel
  81. --------------------------------------------------
  82. // AUTOSENSE
  83. The task cancellation command supports the same task selection parameters as the list tasks command, so multiple tasks
  84. can be cancelled at the same time. For example, the following command will cancel all reindex tasks running on the
  85. nodes `nodeId1` and `nodeId2`.
  86. [source,js]
  87. --------------------------------------------------
  88. POST _tasks/_cancel?node_id=nodeId1,nodeId2&actions=*reindex
  89. --------------------------------------------------
  90. // AUTOSENSE
  91. [float]
  92. === Task Grouping
  93. The task lists returned by task API commands can be grouped either by nodes (default) or by parent tasks using the `group_by` parameter.
  94. The following command will change the grouping to parent tasks:
  95. [source,js]
  96. --------------------------------------------------
  97. GET _tasks?group_by=parents
  98. --------------------------------------------------
  99. // AUTOSENSE