Cancel an ongoing reindex task
- 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_idstring TaskIdrequired -
The ID of the reindex task to cancel.
Query Parameters
-
wait_for_completionboolean · default: true If
true(the default), the request blocks until the cancellation is complete and returns the final task state. Iffalse, the request returns immediately withacknowledged: true.
Response
-
acknowledgedboolean -
Present and
truewhenwait_for_completion=false. -
completedboolean -
Whether the reindex task has completed. Present when
wait_for_completion=true. -
idstring TaskId -
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. -
descriptionstring -
A sanitized description of the reindex operation.
-
start_time_in_millisEpochTimeUnitMillis -
The time at which the reindex task started, in milliseconds since the Unix epoch.
-
start_timestring -
The time at which the reindex task started, as an ISO 8601 formatted string.
-
running_timestring Duration -
The elapsed running time of the reindex task, in a human-readable format. Only present when the request includes the
?human=truequery parameter. -
running_time_in_nanosDurationValueUnitNanos -
The elapsed running time of the reindex task, in nanoseconds.
-
cancelledboolean -
Whether the reindex task has been cancelled.
-
statusReindexStatus -
The status of the reindex operation at the time of cancellation.
-
slice_idnumber -
The slice ID
-
batchesnumberrequired -
The number of scroll responses pulled back by the reindex.
-
creatednumber -
The number of documents that were successfully created.
-
deletednumberrequired -
The number of documents that were successfully deleted.
-
noopsnumberrequired -
The number of documents that were ignored because the script used for the reindex returned a
noopvalue forctx.op. -
requests_per_secondnumberrequired -
The number of requests per second effectively executed during the reindex.
-
retriesRetriesrequired -
The number of retries attempted by reindex.
bulkis the number of bulk actions retried andsearchis the number of search actions retried. -
throttledstring Duration -
throttled_millisDurationValueUnitMillisrequired -
Number of milliseconds the request slept to conform to
requests_per_second. -
throttled_untilstring Duration -
throttled_until_millisDurationValueUnitMillisrequired -
This field should always be equal to zero in a
_reindexresponse. It only has meaning when using the Task API, where it indicates the next time (in milliseconds since epoch) a throttled request will be executed again in order to conform torequests_per_second. -
totalnumberrequired -
The number of documents that were successfully processed.
-
updatednumber -
The number of documents that were successfully updated, for example, a document with same ID already existed prior to reindex updating it.
-
version_conflictsnumberrequired -
The number of version conflicts that reindex hits.
-
cancelledstring -
The reason for cancellation if the slice was canceled
-
errorErrorCause -
The error that caused the reindex task to fail, if any.
-
typestringrequired -
The type of error
-
reasonstringnullable -
A human-readable explanation of the error, in English.
-
stack_tracestring -
The server stack trace. Present only if the
error_trace=trueparameter was sent with the request. -
caused_byErrorCause -
root_causeErrorCause -
suppressedErrorCause -
responseReindexTaskResult -
The final result of the reindex operation, if it completed before being cancelled.
-
batchesnumber -
The number of scroll responses pulled back by the reindex.
-
creatednumber -
The number of documents that were successfully created.
-
deletednumber -
The number of documents that were successfully deleted.
-
failuresBulkIndexByScrollFailure -
Any failures encountered during the reindex. If non-empty, the reindex ended because of these failures.
-
causeErrorCauserequired -
typestringrequired -
The type of error
-
reasonstringnullable -
A human-readable explanation of the error, in English.
-
stack_tracestring -
The server stack trace. Present only if the
error_trace=trueparameter was sent with the request. -
caused_byErrorCause -
root_causeErrorCause -
suppressedErrorCause -
idstring Idrequired -
indexstring IndexNamerequired -
statusnumberrequired -
noopsnumber -
The number of documents that were ignored because the script returned a
noopvalue forctx.op. -
requests_per_secondnumber -
The number of requests per second effectively executed during the reindex.
-
retriesRetries -
The number of retries attempted by reindex.
-
throttled_millisDurationValueUnitMillis -
Number of milliseconds the request slept to conform to
requests_per_second. -
throttled_until_millisDurationValueUnitMillis -
This field should always be equal to zero in a completed reindex result.
-
timed_outboolean -
Whether any of the requests executed during the reindex timed out.
-
tookDurationValueUnitMillis -
The total milliseconds the entire operation took.
-
totalnumber -
The number of documents that were successfully processed.
-
updatednumber -
The number of documents that were successfully updated.
-
version_conflictsnumber -
The number of version conflicts that occurred.