Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

illegal_argument_exception: index.lifecycle.rollover_alias [metricbeat-6.8.4-alias] does not point to index [metricbeat-6.8.4-2020.02.24]

currently looking for help about setup ilm, i have setup the template, index alias and policy as below

PUT metricbeat-6.8.4-alias-000001
{
  "aliases": {
    "metricbeat-6.8.4-alias": {
      "is_write_index": true
    }
  }
}

PUT _template/metricbeat-6.8.4-alias
{
  "index_patterns": ["metricbeat-6.8.4-*"],                 
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "index.lifecycle.name": "Delete_Index",      
    "index.lifecycle.rollover_alias": "metricbeat-6.8.4-alias"    
  }
}

but still error ocurred like below

illegal_argument_exception: index.lifecycle.rollover_alias [metricbeat-6.8.4-alias] does not point to index [metricbeat-6.8.4-2020.02.24]

looking for help how i setup correcly the ilm ? thanks

like image 285
Yoga Arie Avatar asked Feb 24 '20 14:02

Yoga Arie


People also ask

Why can't I rollover an index for an alias?

An index can only rollover if it is the current write index for an alias that's pointing to multiple indexes. To prevent those problems, don't configure aliases in the index template. It's fine to use index templates for settings and mappings, but not for the alias. You configure the alias when you create the first index.

How to create an alias with the lifecycle policy?

Creating an alias with the lifecycle policy is a 3 step process. Create a lifecycle policy that defines the appropriate phases and actions. Create an index template to apply the policy to each new index. Bootstrap an index as the initial write index. I think you are creating the template AFTER you create the first index.

Why does my_index-000002 not work with the alias?

This works because the alias will have one "write index", which is always pointing to the current active index. When an index rolls over from my_index-000002 to my_index-000003, the write index is automatically adjusted. The error you were seeing has to do with the alias.

Why can't I rollover an index in Elasticsearch?

This would cause problems indexing the data, because Elasticsearch would not know what index to write the documents to. It also caused problems with the rollover API. An index can only rollover if it is the current write index for an alias that's pointing to multiple indexes.


1 Answers

Creating an alias with the lifecycle policy is a 3 step process.

Elastic provides a great tutorial

In short:

  1. Create a lifecycle policy that defines the appropriate phases and actions.
  2. Create an index template to apply the policy to each new index.
  3. Bootstrap an index as the initial write index.

I think you are creating the template AFTER you create the first index. You should first create the ilm, after that the template where you specify what ilm policy you want to use for the indexes and finally create the first index (bootstrap).

Example in code:

var indexName = "index_name";
var indexPattern = $"{indexName}-*";
var aliasName = $"{indexName}-alias";
var policyName = $"{indexName}-policy";
var firstIndexName = $"{indexName}-000001";

PUT _ilm/policy/index_name-policy
{
    "policy": {
        "phases": {
            "hot": {
                "actions": {
                    "rollover": {
                        "max_size": "5gb",
                        "max_docs": 10000,
                        "max_age":"2d"
                    }
                }
            },
            "warm": {
                "min_age": "5d",
                "actions": {
                }
            },
            "delete": {
                "min_age": "10d",
                "actions": {
                    "delete": {}
                }
            }
        }
    }
}

PUT _template/index_name-template
{
    "index_patterns": ["{{.IndexPattern}}"],
    "settings": {
        "index.number_of_shards": "1",
        "index.number_of_replicas": "1",
        "index.lifecycle.name": "{{.PolicyName}}", 
        "index.lifecycle.rollover_alias": "{{.AliasName}}" 
    },
    "mappings": {
         "_source": {
            "enabled": true
         },
         "properties": {
            {{Properties}}
        }
    }
}

PUT index_name-000001
{
   "aliases": {
        "{{.AliasName}}":{
            "is_write_index": true 
        }
    }
}

like image 105
L.querter Avatar answered Sep 22 '22 13:09

L.querter