---
type: api
title: Create or update a trained model alias
description: A trained model alias is a logical name used to reference a single trained
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-ml-put-trained-model-alias
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-ml-put-trained-model-alias
products:
  - Elasticsearch
---

# Create or update a trained model alias

Availability: Generally available since 7.13

## Paths

- `PUT` `/_ml/trained_models/{model_id}/model_aliases/{model_alias}`

#### Path parameters

- `model_id` (string) — required
  The identifier for the trained model that the alias refers to.
- `model_alias` (string) — required
  The alias to create or update. This value cannot end in numbers.

## Description

A trained model alias is a logical name used to reference a single trained
model.
You can use aliases instead of trained model identifiers to make it easier to
reference your models. For example, you can use aliases in inference
aggregations and processors.
An alias must be unique and refer to only a single trained model. However,
you can have multiple aliases for each trained model.
If you use this API to update an alias such that it references a different
trained model ID and the model uses a different type of data frame analytics,
an error occurs. For example, this situation occurs if you have a trained
model for regression analysis and a trained model for classification
analysis; you cannot reassign an alias from one type of trained model to
another.
If you use this API to update an alias and there are very few input fields in
common between the old and new trained models for the model alias, the API
returns a warning.

## Required authorization

- Cluster privileges: `manage_ml`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Query string parameters

- `reassign` (boolean · default: false) — optional
  Specifies whether the alias gets reassigned to the specified trained
model if it is already assigned to a different model. If the alias is
already assigned and this parameter is false, the API returns an error.

## 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
PUT _ml/trained_models/flight-delay-prediction-1574775339910/model_aliases/flight_delay_model
```

#### JavaScript

```javascript
const response = await client.ml.putTrainedModelAlias({
  model_id: "flight-delay-prediction-1574775339910",
  model_alias: "flight_delay_model",
});
```

#### Python

```python
resp = client.ml.put_trained_model_alias(
    model_id="flight-delay-prediction-1574775339910",
    model_alias="flight_delay_model",
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_ml/trained_models/flight-delay-prediction-1574775339910/model_aliases/flight_delay_model" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().putTrainedModelAlias(p -> p
    .modelAlias("flight_delay_model")
    .modelId("flight-delay-prediction-1574775339910")
);
```

#### C#

```c#
var response = await client.MachineLearning.PutTrainedModelAliasAsync(modelId: "flight-delay-prediction-1574775339910", modelAlias: "flight_delay_model");
```

#### PHP

```php
$resp = $client->ml()->putTrainedModelAlias([
    "model_id" => "flight-delay-prediction-1574775339910",
    "model_alias" => "flight_delay_model",
]);
```

#### Ruby

```ruby
response = client.ml.put_trained_model_alias(
  model_id: "flight-delay-prediction-1574775339910",
  model_alias: "flight_delay_model"
)
```

