---
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/4371/api/doc/elasticsearch/operation/operation-ml-put-trained-model-alias
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-ml-put-trained-model-alias
products:
  - Elasticsearch
---

# Create or update a trained model alias

Availability: 7.13+

## Paths

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

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

#### Path Parameters

- `model_id` (string Id)
  The identifier for the trained model that the alias refers to.
- `model_alias` (string Name)
  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`

## Query String Parameters

- `reassign` (boolean · default: false)
  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"
)
```

