How to do it...

The URL format for control aliases is as follows:

http://<server>/_aliases
http://<server>/<index>/_alias/<alias_name>

For managing the index aliases, we will perform the following steps:

  1. We are reading the aliases and statuses for all indices using the REST API, so the method will be GET. An example of a call is as follows:
GET /_aliases
  1. This gives a response similar to this one:
{
".monitoring-es-7-2019.04.06" : {
"aliases" : { }
},
"myindex" : {
"aliases" : { }
}
}
  1. Aliases can be changed with add and delete commands.
  2. To read an alias for a single index, we use the _alias endpoint:
GET /myindex/_alias

The result should be as follows:

{
"myindex" : {
"aliases" : { }
}
}
  1. To add an alias, type the following command:
PUT /myindex/_alias/myalias1

The result should be as follows:

{
"acknowledged" : true
}

This action adds the myindex index to the myalias1 alias.

  1. To delete an alias, type the following command:
DELETE /myindex/_alias/myalias1

The result should be as follows:

{
"acknowledged" : true
}

The delete action removed myindex from the myalias1 alias.