# 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
}
```


## Servers
- http://api.example.com: http://api.example.com ()


## Authentication methods
- Api key auth


## Parameters

### Path parameters

- **task_id** (string)
  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


#### Body: application/json (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)
  The time at which the reindex task started, in milliseconds since the Unix epoch.

- **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.

- **running_time_in_nanos** (number)
  The elapsed running time of the reindex task, in nanoseconds.

- **cancelled** (boolean)
  Whether the reindex task has been cancelled.

- **status** (object)
  The status of the reindex operation at the time of cancellation.

- **error** (object)
  The error that caused the reindex task to fail, if any.

- **response** (object)
  The final result of the reindex operation, if it completed before being cancelled.



[Powered by Bump.sh](https://bump.sh)
