Aliases API
editAliases API
editPerforms one or more alias actions in a single atomic operation.
resp = client.indices.update_aliases(
actions=[
{
"add": {
"index": "my-data-stream",
"alias": "my-alias"
}
}
],
)
print(resp)
response = client.indices.update_aliases(
body: {
actions: [
{
add: {
index: 'my-data-stream',
alias: 'my-alias'
}
}
]
}
)
puts response
const response = await client.indices.updateAliases({
actions: [
{
add: {
index: "my-data-stream",
alias: "my-alias",
},
},
],
});
console.log(response);
POST _aliases
{
"actions": [
{
"add": {
"index": "my-data-stream",
"alias": "my-alias"
}
}
]
}
Request
editPOST _aliases
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the following index privileges:
-
To use the
addorremoveaction, you must have themanageindex privilege for the alias and its data streams or indices. -
To use the
remove_indexaction, you must have themanageindex privilege for the index.
-
To use the
Query parameters
edit-
master_timeout -
(Optional, time units)
Period to wait for the master node. If the master node is not available before
the timeout expires, the request fails and returns an error. Defaults to
30s. Can also be set to-1to indicate that the request should never timeout. -
timeout -
(Optional, time units) Period to wait for a response from all relevant nodes in the cluster after updating the cluster metadata.
If no response is received before the timeout expires, the cluster metadata update still applies but the response will indicate that it was not completely acknowledged.
Defaults to
30s. Can also be set to-1to indicate that the request should never timeout.
Request body
edit-
actions -
(Required, array of objects) Actions to perform.
Properties of
actionsobjects-
<action> -
(Required, object) The key is the action type. At least one action is required.
Valid
<action>keys-
add -
Adds a data stream or index to an alias. If the alias doesn’t exist, the
addaction creates it. -
remove - Removes a data stream or index from an alias.
-
remove_index - Deletes an index. You cannot use this action on aliases or data streams.
The object body contains options for the alias. Supports an empty object.
Properties of
<action>-
alias -
(Required*, string) Alias for the action. Index alias names support
date math. If
aliasesis not specified, theaddandremoveactions require this parameter. For theremoveaction, this parameter supports wildcards (*). Theremove_indexaction doesn’t support this parameter. -
aliases -
(Required*, array of strings) Aliases for the action. Index alias names support
date math. If
aliasis not specified, theaddandremoveactions require this parameter. For theremoveaction, this parameter supports wildcards (*). Theremove_indexaction doesn’t support this parameter.
-
filter -
(Optional, Query DSL object Query used to limit documents the alias can access.
Only the
addaction supports this parameter. -
index -
(Required*, string) Data stream or index for the action. Supports wildcards
(
*). Ifindicesis not specified, this parameter is required. For theaddandremove_indexactions, wildcard patterns that match both data streams and indices return an error. -
indices -
(Required*, array of strings) Data streams or indices for the action. Supports
wildcards (
*). Ifindexis not specified, this parameter is required. For theaddandremove_indexactions, wildcard patterns that match both data streams and indices return an error.
-
index_routing -
(Optional, string) Value used to route indexing operations to a specific shard. If specified, this overwrites the
routingvalue for indexing operations. Data stream aliases don’t support this parameter.Only the
addaction supports this parameter.
-
is_hidden -
(Optional, Boolean) If
true, the alias is hidden. Defaults tofalse. All data streams or indices for the alias must have the sameis_hiddenvalue.Only the
addaction supports this parameter.
-
is_write_index -
(Optional, Boolean) If
true, sets the write index or data stream for the alias.If an alias points to multiple indices or data streams and
is_write_indexisn’t set, the alias rejects write requests. If an index alias points to one index andis_write_indexisn’t set, the index automatically acts as the write index. Data stream aliases don’t automatically set a write data stream, even if the alias points to one data stream.Only the
addaction supports this parameter.
-
must_exist -
(Optional, Boolean) Affects the behavior when attempting to remove an alias which does not exist. If
true, removing an alias which does not exist will cause all actions to fail. Iffalse, removing an alias which does not exist will only cause that removal to fail. Defaults tofalse.Only the
removeaction supports this parameter.
-
routing -
(Optional, string) Value used to route indexing and search operations to a specific shard. Data stream aliases don’t support this parameter.
Only the
addaction supports this parameter.
-
search_routing -
(Optional, string) Value used to route search operations to a specific shard. If specified, this overwrites the
routingvalue for search operations. Data stream aliases don’t support this parameter.Only the
addaction supports this parameter.
-
-
Response body
edit-
acknowledged -
(Boolean)
If
true, the request received a response from the master node within thetimeoutperiod. -
errors -
(Boolean)
If
true, at least one of the requested actions failed. -
action_results -
(Optional, array of objects) Results for each requested action.
Properties of
action_resultsobjects-
action -
(object) Description of the associated action request.
Properties of
actionobject-
type -
(string) The type of the associated action, one of
add,remove, orremove_index. -
indices - (array of strings) List of indices in the associated action.
-
aliases - (array of strings) List of aliases in the associated action.
-
-
status - (integer) HTTP status code returned for the action.
-
error -
(Optional, object) Contains additional information about the failed action.
Only present if the action failed.
-