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 parameters
-
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.
Default value is
30s. -
Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
Default value is
30s.
POST
/_aliases
Console
POST _aliases
{
"actions": [
{
"add": {
"index": "logs-nginx.access-*",
"alias": "logs"
}
}
]
}
resp = client.indices.update_aliases(
actions=[
{
"add": {
"index": "logs-nginx.access-*",
"alias": "logs"
}
}
],
)
const response = await client.indices.updateAliases({
actions: [
{
add: {
index: "logs-nginx.access-*",
alias: "logs",
},
},
],
});
response = client.indices.update_aliases(
body: {
"actions": [
{
"add": {
"index": "logs-nginx.access-*",
"alias": "logs"
}
}
]
}
)
$resp = $client->indices()->updateAliases([
"body" => [
"actions" => array(
[
"add" => [
"index" => "logs-nginx.access-*",
"alias" => "logs",
],
],
),
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"actions":[{"add":{"index":"logs-nginx.access-*","alias":"logs"}}]}' "$ELASTICSEARCH_URL/_aliases"
var response = await client.Indices
.UpdateAliasesAsync(d1 => d1
.Actions(d2 => d2
.Add(d3 => d3
.Alias("logs")
.Index("logs-nginx.access-*")
)
)
);
client.indices().updateAliases(u -> u
.actions(a -> a
.add(ad -> ad
.alias("logs")
.index("logs-nginx.access-prod")
)
)
);
Request examples
Add a data stream or index to an alias
If the alias does not exist, it is created.
{
"actions": [
{
"add": {
"index": "logs-nginx.access-*",
"alias": "logs"
}
}
]
}
{
"actions": [
{
"remove": {
"index": "logs-nginx.access-prod",
"alias": "logs"
}
}
]
}
First, remove the index `my-index-1` (which has the alias `my-alias`) and then add the index `my-index-2` to the alias in a single request.
{
"actions": [
{
"remove_index": {
"index": "my-index-1"
}
},
{
"add": {
"index": "my-index-2",
"alias": "my-alias"
}
}
]
}
Response examples (200)
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.
{
"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
}
]
}