10

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

Yoga Arie
  • 101
  • 1
  • 1
  • 3

3 Answers3

14

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

L.querter
  • 2,332
  • 2
  • 13
  • 23
1

If you have a rollover in the lifecycle policy delete it and then also delete the alias part like this;

before

  "index_patterns": ["this-is-index-*"],                 
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "index.lifecycle.name": "delete-index-policy",      
    "index.lifecycle.rollover_alias": "this-is-alias-*.*.*" 

after

  "index_patterns": ["this-is-index-*"],                 
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "index.lifecycle.name": "delete-index-policy"  
hbceylan
  • 968
  • 10
  • 10
0

Two solutions here.

First solution (What I found first time)

Get pointed indice using GET _alias/metricbeat-6.8.4-alias

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

Then, you can add document to active indice that is "is_write_index": true

Second solution (What I am using)

At first, I tried to get indice what alias is pointed. But we can put document using alias. So we don't need to get indice name from alias. We only need to add indice using alias first time. And then the alias point right indice and add document.

const isExists = await elasticClient.indices.existsAlias({
  name: config.alias,
});

if (!isExists) {
  await elasticClient.indices.create({
    index: 'metricbeat-6.8.4-alias-000000',
    aliases: {
      [config.alias]: {
        is_write_index: true,
      },
    },
  });
}

const operations = streams.flatMap((v) => [
  {
    create: {
      _index: config.alias,
    },
  },
  v,
]);
MickeyWoW
  • 41
  • 5