---
type: api
title: Set upgrade_mode for ML indices
description: Sets a cluster wide upgrade_mode setting that prepares machine learning
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-set-upgrade-mode
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-set-upgrade-mode
products:
  - Elasticsearch
---

# Set upgrade_mode for ML indices

Availability: 6.7+

## Paths

- `POST` `/_ml/set_upgrade_mode`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

## Description

Sets a cluster wide upgrade_mode setting that prepares machine learning
indices for an upgrade.
When upgrading your cluster, in some circumstances you must restart your
nodes and reindex your machine learning indices. In those circumstances,
there must be no machine learning jobs running. You can close the machine
learning jobs, do the upgrade, then open all the jobs again. Alternatively,
you can use this API to temporarily halt tasks associated with the jobs and
datafeeds and prevent new jobs from opening. You can also use this API
during upgrades that do not require you to reindex your machine learning
indices, though stopping jobs is not a requirement in that case.
You can see the current value for the upgrade_mode setting by using the get
machine learning info API.

## Required authorization

* Cluster privileges: `manage_ml`

## Query String Parameters

- `enabled` (boolean · default: false)
  When `true`, it enables `upgrade_mode` which temporarily halts all job
and datafeed tasks and prohibits new job and datafeed tasks from
starting.
- `timeout` (string Duration · default: 30s)
  The time to wait for the request to be completed.

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
POST _ml/set_upgrade_mode?enabled=true
```

#### JavaScript

```javascript
const response = await client.ml.setUpgradeMode({
  enabled: "true",
});
```

#### Python

```python
resp = client.ml.set_upgrade_mode(
    enabled=True,
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/set_upgrade_mode?enabled=true" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().setUpgradeMode(s -> s
    .enabled(true)
);
```

#### C#

```c#
var response = await client.MachineLearning
    .SetUpgradeModeAsync(d1 => d1
        .Enabled(true)
    );
```

#### PHP

```php
$resp = $client->ml()->setUpgradeMode([
    "enabled" => "true",
]);
```

#### Ruby

```ruby
response = client.ml.set_upgrade_mode(
  enabled: "true"
)
```

