Cancel an ongoing reindex task Generally available; Added in 9.5.0

POST /_reindex/{task_id}/_cancel

If wait_for_completion is true (the default), the response contains the final task state after cancellation. If wait_for_completion is false, the response contains only acknowledged: true.

This API follows reindex tasks across node-shutdown relocations, so callers can keep using the original task ID throughout the lifetime of the operation. Returned task IDs and timings reflect the original task, not its relocated successor. Relocated task IDs are also supported. They are followed transparently and return the task ID and timings of the original task.

When the task ID cannot be cancelled (unknown ID, non-reindex task, sliced child, finished task, or node left with no stored result), the API returns the following response with a 404 status code:

{
  "error": {
    "type": "resource_not_found_exception",
    "reason": "reindex task [r1A2WoRbTwKZ516z6NEs5A:36619] either not found or completed"
  },
  "status": 404
}

During a brief handoff window of a node-shutdown relocation, you may receive the response below with a 503 status code. Retry with the same task ID; the retry follows the relocated task transparently.

{
  "error": {
    "type": "status_exception",
    "reason": "cannot cancel task [36619] because it is being relocated"
  },
  "status": 503
}

Path parameters

  • task_id string Required

    The ID of the reindex task to cancel.

Query parameters

  • wait_for_completion boolean

    If true (the default), the request blocks until the cancellation is complete and returns the final task state. If false, the request returns immediately with acknowledged: true.

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • acknowledged boolean

      Present and true when wait_for_completion=false.

    • completed boolean

      Whether the reindex task has completed. Present when wait_for_completion=true.

    • id string

      The ID of the reindex task. The value is the ID assigned when the task was first created and remains stable across node-shutdown relocations. Present when wait_for_completion=true.

    • description string

      A sanitized description of the reindex operation.

    • start_time_in_millis number

      Time unit for milliseconds

    • start_time string

      The time at which the reindex task started, as an ISO 8601 formatted string.

    • running_time string

      The elapsed running time of the reindex task, in a human-readable format. Only present when the request includes the ?human=true query parameter.

      External documentation
    • running_time_in_nanos number

      Time unit for nanoseconds

    • cancelled boolean

      Whether the reindex task has been cancelled.

    • status object

      The status of the reindex operation at the time of cancellation.

      Hide status attributes Show status attributes object
      • slice_id number

        The slice ID

      • batches number Required

        The number of scroll responses pulled back by the reindex.

      • created number

        The number of documents that were successfully created.

      • deleted number Required

        The number of documents that were successfully deleted.

      • noops number Required

        The number of documents that were ignored because the script used for the reindex returned a noop value for ctx.op.

      • requests_per_second number Required

        The number of requests per second effectively executed during the reindex.

      • retries object Required

        The number of retries attempted by reindex. bulk is the number of bulk actions retried and search is the number of search actions retried.

        Hide retries attributes Show retries attributes object
        • bulk number Required

          The number of bulk actions retried.

      • throttled string

        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.

        External documentation
      • throttled_millis number

        Time unit for milliseconds

      • throttled_until string

        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.

        External documentation
      • throttled_until_millis number

        Time unit for milliseconds

      • total number Required

        The number of documents that were successfully processed.

      • updated number

        The number of documents that were successfully updated, for example, a document with same ID already existed prior to reindex updating it.

      • version_conflicts number Required

        The number of version conflicts that reindex hits.

      • cancelled string

        The reason for cancellation if the slice was canceled

    • error object

      The error that caused the reindex task to fail, if any.

      Hide error attributes Show error attributes object
      • type string Required

        The type of error

      • reason string | null

        A human-readable explanation of the error, in English.

      • stack_trace string

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

      • caused_by object

        Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

      • root_cause array[object]

        Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

        Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

      • suppressed array[object]

        Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

        Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

    • response object

      The final result of the reindex operation, if it completed before being cancelled.

      Hide response attributes Show response attributes object
      • batches number

        The number of scroll responses pulled back by the reindex.

      • created number

        The number of documents that were successfully created.

      • deleted number

        The number of documents that were successfully deleted.

      • failures array[object]

        Any failures encountered during the reindex. If non-empty, the reindex ended because of these failures.

        Hide failures attributes Show failures attributes object
        • cause object Required

          Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

        • id string Required
        • index string Required
        • status number Required
      • noops number

        The number of documents that were ignored because the script returned a noop value for ctx.op.

      • requests_per_second number

        The number of requests per second effectively executed during the reindex.

      • retries object

        The number of retries attempted by reindex.

        Hide retries attributes Show retries attributes object
        • bulk number Required

          The number of bulk actions retried.

      • throttled_millis number

        Time unit for milliseconds

      • throttled_until_millis number

        Time unit for milliseconds

      • timed_out boolean

        Whether any of the requests executed during the reindex timed out.

      • took number

        Time unit for milliseconds

      • total number

        The number of documents that were successfully processed.

      • updated number

        The number of documents that were successfully updated.

      • version_conflicts number

        The number of version conflicts that occurred.

POST /_reindex/{task_id}/_cancel
POST _reindex/r1A2WoRbTwKZ516z6NEs5A:36619/_cancel
resp = client.cancel_reindex(
    task_id="r1A2WoRbTwKZ516z6NEs5A:36619",
)
const response = await client.cancelReindex({
  task_id: "r1A2WoRbTwKZ516z6NEs5A:36619",
});
response = client.cancel_reindex(
  task_id: "r1A2WoRbTwKZ516z6NEs5A:36619"
)
$resp = $client->cancelReindex([
    "task_id" => "r1A2WoRbTwKZ516z6NEs5A:36619",
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_reindex/r1A2WoRbTwKZ516z6NEs5A:36619/_cancel"
Response examples (200)
A successful response from `POST _reindex/{task_id}/_cancel` (the default `wait_for_completion=true`). The response includes the final task state with `cancelled: true` and the `response` block summarising work done before cancellation.
{
  "completed": true,
  "id": "iXIKIbk_T4aF05n5iTA0nA:876",
  "description": "reindex from [cancel_reindex_src] to [cancel_reindex_dst]",
  "start_time_in_millis": 1778265634844,
  "running_time_in_nanos": 1096397958,
  "cancelled": true,
  "status": {
    "total": 170,
    "updated": 0,
    "created": 16,
    "deleted": 0,
    "batches": 8,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled_millis": 941,
    "requests_per_second": 17.0,
    "canceled": "by user request",
    "throttled_until_millis": 0,
    "slices": [
      {
        "slice_id": 0,
        "total": 75,
        "updated": 0,
        "created": 6,
        "deleted": 0,
        "batches": 3,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled_millis": 235,
        "requests_per_second": -1.0,
        "canceled": "by user request",
        "throttled_until_millis": 0
      },
      {
        "slice_id": 1,
        "total": 95,
        "updated": 0,
        "created": 10,
        "deleted": 0,
        "batches": 5,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled_millis": 705,
        "requests_per_second": -1.0,
        "canceled": "by user request",
        "throttled_until_millis": 0
      }
    ]
  },
  "response": {
    "took": 1074,
    "timed_out": false,
    "total": 170,
    "updated": 0,
    "created": 16,
    "deleted": 0,
    "batches": 8,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "941.1ms",
    "throttled_millis": 941,
    "requests_per_second": 17.0,
    "canceled": "by user request",
    "throttled_until": "0s",
    "throttled_until_millis": 0,
    "slices": [
      {
        "slice_id": 0,
        "total": 75,
        "updated": 0,
        "created": 6,
        "deleted": 0,
        "batches": 3,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "235.2ms",
        "throttled_millis": 235,
        "requests_per_second": -1.0,
        "canceled": "by user request",
        "throttled_until": "0s",
        "throttled_until_millis": 0
      },
      {
        "slice_id": 1,
        "total": 95,
        "updated": 0,
        "created": 10,
        "deleted": 0,
        "batches": 5,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "705.8ms",
        "throttled_millis": 705,
        "requests_per_second": -1.0,
        "canceled": "by user request",
        "throttled_until": "0s",
        "throttled_until_millis": 0
      }
    ],
    "failures": []
  }
}
A successful response from `POST _reindex/{task_id}/_cancel?wait_for_completion=false`. The cancellation has been acknowledged but may not yet have taken effect; use the get reindex API to observe progress.
{
  "acknowledged": true
}