Add index alias API

Creates or updates an index alias.

An index alias is a secondary name used to refer to one or more existing indices.

Most Elasticsearch APIs accept an index alias in place of an index name.

  1. PUT /my-index-000001/_alias/alias1

Request

PUT /<index>/_alias/<alias>

POST /<index>/_alias/<alias>

PUT /<index>/_aliases/<alias>

POST /<index>/_aliases/<alias>

Path parameters

<index>

(Required, string) Comma-separated list or wildcard expression of index names to add to the alias.

To add all indices in the cluster to the alias, use a value of _all.

You cannot add data streams to an index alias.

<alias>

(Required, string) Name of the index alias to create or update.

Query parameters

master_timeout

(Optional, time units) Specifies the period of time 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. Defaults to 30s.

timeout

(Optional, time units) Specifies the period of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Defaults to 30s.

Request body

filter

(Required, query object) Filter query used to limit the index alias.

If specified, the index alias only applies to documents returned by the filter. Filter query used to limit the index alias.

If specified, the index alias only applies to documents returned by the filter.

routing

(Optional, string) Custom routing value used to route operations to a specific shard.

Examples

Add a time-based alias

The following request creates an alias, 2030, for the logs_20302801 index.

  1. PUT /logs_20302801/_alias/2030

Add a user-based alias

First, create an index, users, with a mapping for the user_id field:

  1. PUT /users
  2. {
  3. "mappings" : {
  4. "properties" : {
  5. "user_id" : {"type" : "integer"}
  6. }
  7. }
  8. }

Then add the index alias for a specific user, user_12:

  1. PUT /users/_alias/user_12
  2. {
  3. "routing" : "12",
  4. "filter" : {
  5. "term" : {
  6. "user_id" : 12
  7. }
  8. }
  9. }

Add an alias during index creation

You can use the create index API to add an index alias during index creation.

  1. PUT /logs_20302801
  2. {
  3. "mappings": {
  4. "properties": {
  5. "year": { "type": "integer" }
  6. }
  7. },
  8. "aliases": {
  9. "current_day": {},
  10. "2030": {
  11. "filter": {
  12. "term": { "year": 2030 }
  13. }
  14. }
  15. }
  16. }