What is an alias and how to create an alias in Elasticsearch? - Big Data In Real World

What is an alias and how to create an alias in Elasticsearch?

How to check size of a bucket in S3?
April 6, 2023
What is the difference between map and mapValues functions in Spark?
April 13, 2023
How to check size of a bucket in S3?
April 6, 2023
What is the difference between map and mapValues functions in Spark?
April 13, 2023

An 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
}



Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

1 Comment

  1. […] The Big Data in Real World team needs an alias: […]

What is an alias and how to create an alias in Elasticsearch?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X