Elasticsearch Aliases

The index aliases API allow to alias an index with a name. An alias can also be mapped to more than one index, and when specifying it, the alias will automatically expand to the aliases indices. An alias can also be associated with a filter that will automatically be applied when searching, and routing values. An alias cannot have the same name as an index.

List aliases

curl 'localhost:9200/_aliases?pretty'

Add a single Alias:

PUT /{index}/_alias/{name}

where

  • index The index the alias refers to. Can be any of * | _all | glob pattern | name1, name2, …
  • name The name of the alias. This is a required option.
  • routing An optional routing that can be associated with an alias.
  • filter An optional filter that can be associated with an alias.

Here is a sample of associating the alias alias1 with index test1:

curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ { "add" : { "index" : "test1", "alias" : "alias1" } } ] }'

Remove Alias

curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ { "remove" : { "index" : "test1", "alias" : "alias1" } } ] }'

Retrieving existing aliases

The get index alias api allows to filter by alias name and index name. This api redirects to the master and fetches the requested index aliases, if available. This api only serialise the found index aliases.

The rest endpoint is: /{index}/_alias/{alias}.

curl -XGET 'localhost:9200/tutorial1/_alias/*'

Source:

elastic.co/guide/en/elasticsearch/reference..

Did you find this article valuable?

Support Gonzalo's Blog by becoming a sponsor. Any amount is appreciated!