How to check size of a bucket in S3?
April 6, 2023What is the difference between map and mapValues functions in Spark?
April 13, 2023An alias as the name suggests is an alias or another name to the index in Elasticsearch. It is quite useful when you want to refer to an index by another name. So instead of performing an reindex to rename or cloning an index you can create an alias to the index.
Creating an alias
Here we are creating a new alias named account_alias to account index.
curl -X POST "localhost:9200/_aliases?pretty" -H 'Content-Type: application/json' -d'
{ "actions" : [ { "add" : { "index" : "account", "alias" : "account_alias" } } ] }' { "acknowledged" : true }
Using the alias
We can now use the name account_alias in place of account. account_alias can be used in all places where we use account and using either account or account_alias will yield the same result because they both are pointing to the same index.
[osboxes@wk1 ~]$ curl -X GET localhost:9200/account/_doc/954?pretty { "_index" : "account", "_type" : "_doc", "_id" : "954", "_version" : 1, "_seq_no" : 790, "_primary_term" : 1, "found" : true, "_source" : { "account_number" : 954, "balance" : 49404, "firstname" : "Jenna", "lastname" : "Martin", "age" : 22, "gender" : "M", "address" : "688 Hart Street", "employer" : "Zinca", "email" : "jennamartin@zinca.com", "city" : "Oasis", "state" : "MD" } } [osboxes@wk1 ~]$ curl -X GET localhost:9200/account_alias/_doc/954?pretty { "_index" : "account", "_type" : "_doc", "_id" : "954", "_version" : 1, "_seq_no" : 790, "_primary_term" : 1, "found" : true, "_source" : { "account_number" : 954, "balance" : 49404, "firstname" : "Jenna", "lastname" : "Martin", "age" : 22, "gender" : "M", "address" : "688 Hart Street", "employer" : "Zinca", "email" : "jennamartin@zinca.com", "city" : "Oasis", "state" : "MD" } }
Removing an alias
Note that when we remove an alias we specify remove under actions.
curl -X POST "localhost:9200/_aliases?pretty" -H 'Content-Type: application/json' -d' { "actions" : [ { "remove" : { "index" : "account", "alias" : "account_alias" } } ] }' { "acknowledged" : true }
1 Comment
[…] The Big Data in Real World team needs an alias: […]