Elasticsearch Index aliases

Elasticsearch allows the user to create alias to the indices.

For example, if we are maintaining different range of employee details in different indices. And we want to query the employee details of all range from our application. We can create alias to our existing indices.

So that we can query all the needed indices with a single end point. If we are frequently adding new indices to our data sources. we don’t need to update everytime in application configuration part if we are using alias concept.

Whenever we are adding new indices to our data source, we can simply add the new index to alias. The endpoint will remain same, we add our additional index without affecting our application (lets say we are pointing our website to Elasticsearch for data set).

Index 1: sales-people

Index2: research-people

Index 3: management-people

 

Alias: our-employees (Sales people, Research people, Management people)

 

In this case, if we want to query the Index 1 to Index 3, we can simply run our query by pointing to the “our-employees” alias.

 

Following some snippets of Elasticsearch alias actions

 

Adding Alias

POST /_aliases
{
   "actions": [
      {
         "add": {
            "index": "sales-people",
            "alias": "our-employees"
         }
      }
   ]
}

 

Removing Alias

POST /_aliases
{
   "actions": [
      {
         "remove": {
            "index": "sales-people",
            "alias": "our-employees"
         }
      }
   ]
}

 

Adding and Removing index in alias using same call

POST /_aliases
{
   "actions": [
      {
         "remove": {
            "index": "sales-people",
            "alias": "our-employees"
         },
         "add": {
            "index": "research-people",
            "alias": "our-employees"
         }
      }
   ]
}

 

Happy exploring data 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s