---
type: api
title: Update aliases and delete indices atomically
description: Applies one or more actions in a single request:
url: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/operation/operation-indices-update-aliases
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/operation/operation-indices-update-aliases
products:
  - Elasticsearch
---

# Update aliases and delete indices atomically

Authentication: required

Availability: Generally available since 1.3

## Paths

- `POST` `/_aliases`

## Description

Applies one or more actions in a single request:

- Add a data stream or index to an alias.
- Remove a data stream or index from an alias.
- Delete an index in that same request, so the deletion and the alias changes are applied together.

For example, you can replace an index with an alias of the same name.

NOTE: Every `remove_index` action in the request runs first, before any `add` or `remove` actions, no matter where it sits in the `actions` array.

## Required authorization

- Index privileges: `manage`

## Query string parameters

- `master_timeout` (string · default: 30s) — optional
  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 · default: 30s) — optional
  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` (object[]) — optional
  Actions to perform.
  - `add` (object) — 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 string | string[]) — optional
      Aliases for the action.
Index alias names support date math.
    - `filter` ({} Query) — optional
      Query used to limit documents the alias can access.
      See [Query](https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)
    - `index` (string) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
Wildcard patterns that match both data streams and indices return an error.
    - `indices` (union oneOf) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
Wildcard patterns that match both data streams and indices return an error.
      One of: `string[]` or `string`
    - `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` (object) — 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 string | string[]) — optional
      Aliases for the action.
Index alias names support date math.
    - `index` (string) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
    - `indices` (union oneOf) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
      One of: `string[]` or `string`
    - `must_exist` (boolean · default: false) — optional
      If `true`, the alias must exist to perform the action.
  - `remove_index` (object) — optional
    Deletes an index.
You cannot use this action on aliases or data streams.
    - `index` (string) — optional
      Data stream or index for the action.
Supports wildcards (`*`).
    - `indices` (union oneOf) — optional
      Data streams or indices for the action.
Supports wildcards (`*`).
      One of: `string[]` or `string`
    - `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.
- `errors` (boolean)
  If `true`, at least one alias action failed.
The request still returns HTTP 200.
- `action_results` (object[])
  Results for each action in the request.
Returned only when `errors` is `true`.
  - `action` (object)
    The action this result describes.
    - `type` (enum)
      The action that was applied.
      Values: `add`, `remove`, `remove_index`
    - `indices` (string[])
      Resolved data streams or indices for the action.
    - `aliases` (string[])
      Aliases for the action.
  - `status` (number)
    HTTP status for this action.
`200` when the action succeeds.
  - `error` (object)
    Cause of the failure.
Returned only when this action fails.
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` (object) — recursive
      Same fields as `error` in `action_results`
    - `root_cause` (object[]) — recursive
      Same fields as `error` in `action_results`
    - `suppressed` (object[]) — recursive
      Same fields as `error` in `action_results`
## Code examples

### Add a data stream or index to an alias

#### Console

```console
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "logs-nginx.access-*",
        "alias": "logs"
      }
    }
  ]
}
```

#### JavaScript

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

#### Python

```python
resp = client.indices.update_aliases(
    actions=[
        {
            "add": {
                "index": "logs-nginx.access-*",
                "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-*",
          "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-*")
            )
        )
    );
```

#### PHP

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

#### Ruby

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

### Remove a data stream or index from an alias

#### Console

```console
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "logs-nginx.access-prod",
        "alias": "logs"
      }
    }
  ]
}
```

#### JavaScript

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

#### Python

```python
resp = client.indices.update_aliases(
    actions=[
        {
            "remove": {
                "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": [
      {
        "remove": {
          "index": "logs-nginx.access-prod",
          "alias": "logs"
        }
      }
    ]
  }'
```

#### C#

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

#### PHP

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

#### Ruby

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

### Remove an index and update an alias

#### Console

```console
POST _aliases
{
  "actions": [
    {
      "remove_index": {
        "index": "my-index-1"
      }
    },
    {
      "add": {
        "index": "my-index-2",
        "alias": "my-alias"
      }
    }
  ]
}
```

#### JavaScript

```javascript
const response = await client.indices.updateAliases({
  actions: [
    {
      remove_index: {
        index: "my-index-1",
      },
    },
    {
      add: {
        index: "my-index-2",
        alias: "my-alias",
      },
    },
  ],
});
```

#### Python

```python
resp = client.indices.update_aliases(
    actions=[
        {
            "remove_index": {
                "index": "my-index-1"
            }
        },
        {
            "add": {
                "index": "my-index-2",
                "alias": "my-alias"
            }
        }
    ],
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_aliases" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "actions": [
      {
        "remove_index": {
          "index": "my-index-1"
        }
      },
      {
        "add": {
          "index": "my-index-2",
          "alias": "my-alias"
        }
      }
    ]
  }'
```

#### C#

```c#
var response = await client.Indices
    .UpdateAliasesAsync(d1 => d1
        .Actions(d2 => d2
            .RemoveIndex(d3 => d3
                .Index("my-index-1")
            ), d2 => d2
            .Add(d3 => d3
                .Alias("my-alias")
                .Index("my-index-2")
            )
        )
    );
```

#### PHP

```php
$resp = $client->indices()->updateAliases([
    "body" => [
        "actions" => array(
            [
                "remove_index" => [
                    "index" => "my-index-1",
                ],
            ],
            [
                "add" => [
                    "index" => "my-index-2",
                    "alias" => "my-alias",
                ],
            ],
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.indices.update_aliases(
  body: {
    "actions": [
      {
        "remove_index": {
          "index": "my-index-1"
        }
      },
      {
        "add": {
          "index": "my-index-2",
          "alias": "my-alias"
        }
      }
    ]
  }
)
```

## Response examples

#### A partially successful response

`application/json`

When using multiple actions, if some succeed and some fail, the API returns a list of per-action results. For example, if the alias `logs-non-existing` does not exist, the API returns a 404 error for the `remove` action.

```json
{
  "acknowledged": true,
  "errors": true,
  "action_results": [
    {
      "action": {
        "type": "remove",
        "indices": [
          "logs-nginx.access-prod"
        ],
        "aliases": [
          "logs-non-existing"
        ]
      },
      "status": 404,
      "error": {
        "type": "aliases_not_found_exception",
        "reason": "aliases [logs-non-existing] missing",
        "resource.type": "aliases",
        "resource.id": "logs-non-existing"
      }
    },
    {
      "action": {
        "type": "add",
        "indices": [
          "logs-nginx.access-default"
        ],
        "aliases": [
          "logs-non-existing"
        ]
      },
      "status": 200
    }
  ]
}
```

