Tasks

    The following request returns information about all of your tasks:

    By including a task ID, you can get information specific to a particular task. Note that a task ID consists of a node’s identifying string and the task’s numerical ID. For example, if your node’s identifying string is nodestring and the task’s numerical ID is 1234, then your task ID is nodestring:1234. You can find this information by running the tasks operation:

    1. GET _tasks/<task_id>

    Note that if a task finishes running, it won’t be returned as part of your request. For an example of a task that takes a little longer to finish, you can run the _reindex API operation on a larger document, and then run tasks.

    Sample Response

    1. {
    2. "nodes": {
    3. "Mgqdm0r9SEGClWxp_RbnaQ": {
    4. "name": "opensearch-node1",
    5. "transport_address": "172.18.0.3:9300",
    6. "host": "172.18.0.3",
    7. "ip": "172.18.0.3:9300",
    8. "roles": [
    9. "data",
    10. "ingest",
    11. "master",
    12. "remote_cluster_client"
    13. ],
    14. "tasks": {
    15. "Mgqdm0r9SEGClWxp_RbnaQ:17416": {
    16. "node": "Mgqdm0r9SEGClWxp_RbnaQ",
    17. "id": 17416,
    18. "type": "transport",
    19. "action": "cluster:monitor/tasks/lists",
    20. "start_time_in_millis": 1613599752458,
    21. "running_time_in_nanos": 994000,
    22. "cancellable": false,
    23. "headers": {}
    24. },
    25. "Mgqdm0r9SEGClWxp_RbnaQ:17413": {
    26. "node": "Mgqdm0r9SEGClWxp_RbnaQ",
    27. "id": 17413,
    28. "type": "transport",
    29. "start_time_in_millis": 1613599752286,
    30. "running_time_in_nanos": 172846500,
    31. "parent_task_id": "Mgqdm0r9SEGClWxp_RbnaQ:17366",
    32. "headers": {}
    33. },
    34. "Mgqdm0r9SEGClWxp_RbnaQ:17366": {
    35. "node": "Mgqdm0r9SEGClWxp_RbnaQ",
    36. "id": 17366,
    37. "type": "transport",
    38. "action": "indices:data/write/reindex",
    39. "start_time_in_millis": 1613599750929,
    40. "running_time_in_nanos": 1529733100,
    41. "cancellable": true,
    42. "headers": {}
    43. }
    44. }
    45. }
    46. }
    47. }

    For example, this request returns tasks currently running on a node named opensearch-node1:

    Sample Request

    Sample Response

    1. {
    2. "nodes": {
    3. "Mgqdm0r9SEGClWxp_RbnaQ": {
    4. "name": "opensearch-node1",
    5. "transport_address": "sample_address",
    6. "host": "sample_host",
    7. "ip": "sample_ip",
    8. "roles": [
    9. "data",
    10. "ingest",
    11. "master",
    12. ],
    13. "tasks": {
    14. "Mgqdm0r9SEGClWxp_RbnaQ:24578": {
    15. "node": "Mgqdm0r9SEGClWxp_RbnaQ",
    16. "id": 24578,
    17. "type": "transport",
    18. "action": "cluster:monitor/tasks/lists",
    19. "start_time_in_millis": 1611612517044,
    20. "running_time_in_nanos": 638700,
    21. "cancellable": false,
    22. "headers": {}
    23. },
    24. "Mgqdm0r9SEGClWxp_RbnaQ:24579": {
    25. "node": "Mgqdm0r9SEGClWxp_RbnaQ",
    26. "id": 24579,
    27. "type": "direct",
    28. "action": "cluster:monitor/tasks/lists[n]",
    29. "start_time_in_millis": 1611612517044,
    30. "running_time_in_nanos": 222200,
    31. "cancellable": false,
    32. "parent_task_id": "Mgqdm0r9SEGClWxp_RbnaQ:24578",
    33. "headers": {}
    34. }
    35. }
    36. }
    37. }
    38. }

    After getting a list of tasks, you can cancel all cancelable tasks with the following request:

    1. POST _tasks/_cancel

    You can also cancel a task by including a specific task ID.

    The cancel operation supports the same parameters as the tasks operation. The following example shows how to cancel all cancelable tasks on multiple nodes.

    1. POST _tasks/_cancel?nodes=opensearch-node1,opensearch-node2

    Attaching headers to tasks

    To associate requests with tasks for better tracking, you can provide a X-Opaque-Id:<ID_number> header as part of the HTTPS request reader of your curl command. The API will attach the specified header in the returned result.

    Usage:

    1. curl -i -H "X-Opaque-Id: 111111" "https://localhost:9200/_tasks" -u 'admin:admin' --insecure

    This operation supports the same parameters as the tasks operation. The following example shows how you can associate with specific tasks:

    1. curl -i -H "X-Opaque-Id: 123456" "https://localhost:9200/_tasks?nodes=opensearch-node1" -u 'admin:admin' --insecure