---
type: api
title: Create or update an alias
description: Adds a data stream or index to an alias.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-indices-update-aliases
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-indices-update-aliases
products:
  - Elasticsearch
---

# Create or update an alias

Availability: 1.3+

## Paths

- `POST` `/_aliases`

- [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)

## Description

Adds a data stream or index to an alias.

## Query String Parameters

- `master_timeout` (string Duration · default: 30s)
  Period to wait for a connection to the master node.
If no response is received before the timeout expires, the request fails and returns an error.
- `timeout` (string Duration · default: 30s)
  Period to wait for a response.
If no response is received before the timeout expires, the request fails and returns an error.

## Request Body

`application/json`

- `actions` ([] Action) — optional
  Actions to perform.
  - `add` ({} AddAction) — optional
    Adds a data stream or index to an alias.
If the alias doesn’t exist, the `add` action creates it.
    - `alias` (string) — optional
      Alias for the action.
Index alias names support date math.
    - `aliases` (union IndexAlias | [] IndexAlias) — optional
      Aliases for the action.
Index alias names support date math.
    - `filter` ({} QueryContainer) — optional
      Query used to limit documents the alias can access.
      See [QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)
    - `index` (string IndexName) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
    - `indices` (string Indices) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
    - `index_routing` (string) — optional
      Value used to route indexing operations to a specific shard.
If specified, this overwrites the `routing` value for indexing operations.
Data stream aliases don’t support this parameter.
    - `is_hidden` (boolean · default: false) — optional
      If `true`, the alias is hidden.
    - `is_write_index` (boolean) — optional
      If `true`, sets the write index or data stream for the alias.
    - `routing` (string) — optional
      Value used to route indexing and search operations to a specific shard.
Data stream aliases don’t support this parameter.
    - `search_routing` (string) — optional
      Value used to route search operations to a specific shard.
If specified, this overwrites the `routing` value for search operations.
Data stream aliases don’t support this parameter.
    - `must_exist` (boolean · default: false) — optional
      If `true`, the alias must exist to perform the action.
  - `remove` ({} RemoveAction) — optional
    Removes a data stream or index from an alias.
    - `alias` (string) — optional
      Alias for the action.
Index alias names support date math.
    - `aliases` (union IndexAlias | [] IndexAlias) — optional
      Aliases for the action.
Index alias names support date math.
    - `index` (string IndexName) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
    - `indices` (string Indices) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
    - `must_exist` (boolean · default: false) — optional
      If `true`, the alias must exist to perform the action.
  - `remove_index` ({} RemoveIndexAction) — optional
    Deletes an index.
You cannot use this action on aliases or data streams.
    - `index` (string IndexName) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
    - `indices` (string Indices) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
    - `must_exist` (boolean · default: false) — optional
      If `true`, the alias must exist to perform the action.

## 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 _aliases
{
  "actions": [
    {
      "add": {
        "index": "logs-nginx.access-prod",
        "alias": "logs"
      }
    }
  ]
}
```

#### JavaScript

```javascript
const response = await client.indices.updateAliases({
  actions: [
    {
      add: {
        index: "logs-nginx.access-prod",
        alias: "logs",
      },
    },
  ],
});
```

#### Python

```python
resp = client.indices.update_aliases(
    actions=[
        {
            "add": {
                "index": "logs-nginx.access-prod",
                "alias": "logs"
            }
        }
    ],
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_aliases" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "actions": [
      {
        "add": {
          "index": "logs-nginx.access-prod",
          "alias": "logs"
        }
      }
    ]
  }'
```

#### Java

```java
client.indices().updateAliases(u -> u
    .actions(a -> a
        .add(ad -> ad
            .alias("logs")
            .index("logs-nginx.access-prod")
        )
    )
);
```

#### C#

```c#
var response = await client.Indices
    .UpdateAliasesAsync(d1 => d1
        .Actions(d2 => d2
            .Add(d3 => d3
                .Alias("logs")
                .Index("logs-nginx.access-prod")
            )
        )
    );
```

#### PHP

```php
$resp = $client->indices()->updateAliases([
    "body" => [
        "actions" => array(
            [
                "add" => [
                    "index" => "logs-nginx.access-prod",
                    "alias" => "logs",
                ],
            ],
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.indices.update_aliases(
  body: {
    "actions": [
      {
        "add": {
          "index": "logs-nginx.access-prod",
          "alias": "logs"
        }
      }
    ]
  }
)
```

