Skip to content

Do you know: how to create an alias for your Elasticsearch index with the format index_name-yyyy.MM.dd-00001?

Each week, a new “Do you know” will be posted on our Elastic Technical Knowledge Hub to share useful knowledge to improve the observability using Elasticsearch. These topics originate from day-to-day challenges we solved for our clients. A stepwise description helps you to successfully implement solutions on improving the performance of your deployment and get the best monitoring of your applications using dashboards and alerting.

This week I will discuss: how to create an alias for your Elasticsearch index using this format: <index_name> – yyyy.MM.dd-00001.

Background

Consider working with an index alias as a strategic approach. An index alias is a way to create a secondary name for one or multiple indexes. The use of index aliases ​​is useful in situations where you want to perform migrations or changes to the index with zero downtime.

Solution

Create an index lifecycle policy, by going to the Kibana menu and choosing: Stack Management Index LifeCycle Policies Create Policy.

Put in a retention time configuration and choose a phase. Do not forget to give your policy a name.

Create an index template. Just go to Stack Management Index Templates Create template.

Add the following lines at tab 3 (Index settings) in the template configuration:

{
  "index": {
    "lifecycle": {
      "name": "<index lifecycle policy name>",
      "rollover_alias": "<alias name>"
    }
  }
}

Go to the Dev Tools in Kibana and perform the following PUT function:

PUT %3C<alias name>-%7Bnow%2Fm%7Byyyy.MM.dd%7D%7D-1%3E
{
  "settings": { 
  "index.lifecycle.name": "<index lifecycle policy name>",
  "index.lifecycle.rollover_alias": "<alias name>"},
  "aliases": {
    "<alias name>": {
      "is_write_index" : true
    }
  }
}

Perform a rollover on your alias name to check that your index name has the following naming structure:  <index_name> – yyyy.MM.dd-00001.

Post <alias name>/_rollover

Need help with your Elastic challenges? Contact our experts.

With our 25+ Elastic certified consultants, Devoteam is your partner for developing and implementing Monitoring & Observability solutions that facilitate optimal IT control, from Business & IT Operations dashboards to centralized logging and proactive alerting.