Cancel a task Technical preview

POST /_tasks/{task_id}/_cancel

A task may continue to run for some time after it has been cancelled because it may not be able to safely stop its current activity straight away. It is also possible that Elasticsearch must complete its work on other tasks before it can process the cancellation. The get task information API will continue to list these cancelled tasks until they complete. The cancelled flag in the response indicates that the cancellation command has been processed and the task will stop as soon as possible.

To troubleshoot why a cancelled task does not complete promptly, use the get task information API with the ?detailed parameter to identify the other tasks the system is running. You can also use the node hot threads API to obtain detailed information about the work the system is doing instead of completing the cancelled task.

Path parameters

  • task_id string | number Required

    ID of the task.

Query parameters

  • actions string | array[string]

    Comma-separated list or wildcard expression of actions used to limit the request.

  • nodes array[string]

    Comma-separated list of node IDs or names used to limit the request.

  • Parent task ID used to limit the tasks.

  • Should the request block until the cancellation of the task and its descendant tasks is completed. Defaults to false

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • node_failures array[object]
      Hide node_failures attributes Show node_failures attributes object
      • type string Required

        The type of error

      • reason string

        A human-readable explanation of the error, in english

      • The server stack trace. Present only if the error_trace=true parameter was sent with the request.

      • Additional properties are allowed.

      • root_cause array[object]

        Additional properties are allowed.

      • suppressed array[object]

        Additional properties are allowed.

    • task_failures array[object]
      Hide task_failures attributes Show task_failures attributes object
      • task_id number Required
      • node_id string Required
      • status string Required
      • reason object Required

        Additional properties are allowed.

        Hide reason attributes Show reason attributes object
        • type string Required

          The type of error

        • reason string

          A human-readable explanation of the error, in english

        • The server stack trace. Present only if the error_trace=true parameter was sent with the request.

        • Additional properties are allowed.

        • root_cause array[object]

          Additional properties are allowed.

        • suppressed array[object]

          Additional properties are allowed.

    • nodes object

      Task information grouped by node, if group_by was set to node (the default).

      Hide nodes attribute Show nodes attribute object
      • * object Additional properties

        Additional properties are allowed.

        Hide * attributes Show * attributes object
        • name string
        • host string
        • ip string
        • roles array[string]
        • Hide attributes attribute Show attributes attribute object
          • * string Additional properties
        • tasks object Required
          Hide tasks attribute Show tasks attribute object
          • * object Additional properties

            Additional properties are allowed.

            Hide * attributes Show * attributes object
            • action string Required
            • cancelled boolean
            • cancellable boolean Required
            • Human readable text that identifies the particular request that the task is performing. For example, it might identify the search request being performed by a search task. Other kinds of tasks have different descriptions, like _reindex which has the source and the destination, or _bulk which just has the number of requests and the destination indices. Many requests will have only an empty description because more detailed information about the request is not easily available or particularly helpful in identifying the request.

            • headers object Required
              Hide headers attribute Show headers attribute object
              • * string Additional properties
            • id number Required
            • node string Required
            • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

            • Time unit for nanoseconds

            • Time unit for milliseconds

            • status object

              The internal status of the task, which varies from task to task. The format also varies. While the goal is to keep the status for a particular task consistent from version to version, this is not always possible because sometimes the implementation changes. Fields might be removed from the status for a particular request so any parsing you do of the status might break in minor releases.

              Additional properties are allowed.

            • type string Required
    • tasks array[object] | object

      One of:
      Hide attributes Show attributes object
      • action string Required
      • cancelled boolean
      • cancellable boolean Required
      • Human readable text that identifies the particular request that the task is performing. For example, it might identify the search request being performed by a search task. Other kinds of tasks have different descriptions, like _reindex which has the source and the destination, or _bulk which just has the number of requests and the destination indices. Many requests will have only an empty description because more detailed information about the request is not easily available or particularly helpful in identifying the request.

      • headers object Required
        Hide headers attribute Show headers attribute object
        • * string Additional properties
      • id number Required
      • node string Required
      • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

      • Time unit for nanoseconds

      • Time unit for milliseconds

      • status object

        The internal status of the task, which varies from task to task. The format also varies. While the goal is to keep the status for a particular task consistent from version to version, this is not always possible because sometimes the implementation changes. Fields might be removed from the status for a particular request so any parsing you do of the status might break in minor releases.

        Additional properties are allowed.

      • type string Required
POST /_tasks/{task_id}/_cancel
curl \
 -X POST http://api.example.com/_tasks/{task_id}/_cancel
Response examples (200)
{
  "node_failures": [
    {
      "type": "string",
      "reason": "string",
      "stack_trace": "string",
      "caused_by": {},
      "root_cause": [
        {}
      ],
      "suppressed": [
        {}
      ]
    }
  ],
  "task_failures": [
    {
      "task_id": 42.0,
      "node_id": "string",
      "status": "string",
      "reason": {
        "type": "string",
        "reason": "string",
        "stack_trace": "string",
        "caused_by": {},
        "root_cause": [
          {}
        ],
        "suppressed": [
          {}
        ]
      }
    }
  ],
  "nodes": {
    "additionalProperty1": {
      "name": "string",
      "transport_address": "string",
      "host": "string",
      "ip": "string",
      "roles": [
        "string"
      ],
      "attributes": {
        "additionalProperty1": "string",
        "additionalProperty2": "string"
      },
      "tasks": {
        "additionalProperty1": {
          "action": "string",
          "cancelled": true,
          "cancellable": true,
          "description": "string",
          "headers": {
            "additionalProperty1": "string",
            "additionalProperty2": "string"
          },
          "id": 42.0,
          "node": "string",
          "running_time": "string",
          "": "string",
          "status": {},
          "type": "string"
        },
        "additionalProperty2": {
          "action": "string",
          "cancelled": true,
          "cancellable": true,
          "description": "string",
          "headers": {
            "additionalProperty1": "string",
            "additionalProperty2": "string"
          },
          "id": 42.0,
          "node": "string",
          "running_time": "string",
          "": "string",
          "status": {},
          "type": "string"
        }
      }
    },
    "additionalProperty2": {
      "name": "string",
      "transport_address": "string",
      "host": "string",
      "ip": "string",
      "roles": [
        "string"
      ],
      "attributes": {
        "additionalProperty1": "string",
        "additionalProperty2": "string"
      },
      "tasks": {
        "additionalProperty1": {
          "action": "string",
          "cancelled": true,
          "cancellable": true,
          "description": "string",
          "headers": {
            "additionalProperty1": "string",
            "additionalProperty2": "string"
          },
          "id": 42.0,
          "node": "string",
          "running_time": "string",
          "": "string",
          "status": {},
          "type": "string"
        },
        "additionalProperty2": {
          "action": "string",
          "cancelled": true,
          "cancellable": true,
          "description": "string",
          "headers": {
            "additionalProperty1": "string",
            "additionalProperty2": "string"
          },
          "id": 42.0,
          "node": "string",
          "running_time": "string",
          "": "string",
          "status": {},
          "type": "string"
        }
      }
    }
  },
  "": [
    {
      "action": "string",
      "cancelled": true,
      "cancellable": true,
      "description": "string",
      "headers": {
        "additionalProperty1": "string",
        "additionalProperty2": "string"
      },
      "id": 42.0,
      "node": "string",
      "running_time": "string",
      "": "string",
      "status": {},
      "type": "string"
    }
  ]
}