Create or Update Alias

Introduced 1.0

The Create or Update Alias API adds a data stream or index to an alias or updates the settings for an existing alias. For more alias API operations, see Index aliases.

The Create or Update Alias API is distinct from the Alias API, which supports the addition and removal of aliases and the removal of alias indexes. In contrast, the following API only supports adding or updating an alias without updating the index itself. Each API also uses different request body parameters.

Path and HTTP methods

  1. POST /<target>/_alias/<alias-name>
  2. PUT /<target>/_alias/<alias-name>
  3. POST /_alias/<alias-name>
  4. PUT /_alias/<alias-name>
  5. POST /<target>/_aliases/<alias-name>
  6. PUT /<target>/_aliases/<alias-name>
  7. POST /_aliases/<alias-name>
  8. PUT /_aliases/<alias-name>
  9. PUT /<target>/_alias
  10. PUT /<target>/_aliases
  11. PUT /_alias

Path parameters

ParameterTypeDescription
targetStringA comma-delimited list of data streams and indexes. Wildcard expressions () are supported. To target all data streams and indexes in a cluster, use _all or . Optional.
alias-nameStringThe alias name to be created or updated. Optional.

Query parameters

All query parameters are optional.

ParameterTypeDescription
cluster_manager_timeoutTimeThe amount of time to wait for a response from the cluster manager node. Default is 30s.
timeoutTimeThe amount of time to wait for a response from the cluster. Default is 30s.

Request body

In the request body, you can specify the index name, the alias name, and the settings for the alias. All fields are optional.

FieldTypeDescription
indexStringA comma-delimited list of data streams or indexes that you want to associate with the alias. If this field is set, it will override the index name specified in the URL path.
aliasStringThe name of the alias. If this field is set, it will override the alias name specified in the URL path.
is_write_indexBooleanSpecifies whether the index should be a write index. An alias can only have one write index at a time. If a write request is submitted to an alias that links to multiple indexes, then OpenSearch runs the request only on the write index.
routingStringAssigns a custom value to a shard for specific operations.
index_routingStringAssigns a custom value to a shard only for index operations.
search_routingStringAssigns a custom value to a shard only for search operations.
filterObjectA filter to use with the alias so that the alias points to a filtered part of the index.

Example request

The following example request adds a sample alias with a custom routing value:

  1. POST sample-index/_alias/sample-alias
  2. {
  3. "routing":"test"
  4. }

copy

Example response

  1. {
  2. "acknowledged": true
  3. }

For more alias API operations, see Index aliases.