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
}
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"
{
"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": []
}
}
{
"acknowledged": true
}