elasticsearch template doesn't change index ILM

834 views Asked by At

in my elasticsearch, I will receive daily index with format like dstack-prod_dcbs-. I want to add ILM to them, immediately after they are revived. I dont know why ILM are not added to indexs. below you can find my command.(I have already defined "dstack-prod_dcbs-policy" ILM)

*PUT _template/dstack-prod_dcbs
{
  "index_patterns": ["dstack-prod_dcbs-*"], 
  "settings": {
    "index.lifecycle.name": "dstack-prod_dcbs-policy"
}
}*

but when I run

GET dstack-prod_dcbs/_ilm/explain*

below result returns

*{
  "indices" : {
    "dstack-prod_dcbs-20200821" : {
      "index" : "dstack-prod_dcbs-20200821",
      "managed" : false
    },
    "dstack-prod_dcbs-2020-09-22" : {
      "index" : "dstack-prod_dcbs-2020-09-22",
      "managed" : false
    }
  }
}*
1

There are 1 answers

3
Jason Silver On BEST ANSWER

I believe ILM is an alternative to using daily indices where indices are rolled over when a condition is met in the policy (not when it becomes a new day)

For ILM you need to define a rollover alias for the template

PUT _template/dstack-prod_dcbs
{
  "index_patterns": ["dstack-prod_dcbs-*"], 
  "settings": {
    "index.lifecycle.name": "dstack-prod_dcbs-policy",
    "index.lifecycle.rollover_alias": "dstack-prod_dcbs"
  } 
}

Then you need to create the first index manually and assign it as the write index for the alias

PUT dstack-prod_dcbs-000001
{
   "aliases": {
        "dstack-prod_dcbs":{
            "is_write_index": true 
        }
    }
}

After that everything will be handled automatically and a new index will be created on rollover which will be then assigned as the write index for the alias