Applying a policy to an index template

The index.lifecycle.name setting can be set in an index template so that it is automatically applied to indexes matching the templates index pattern:

PUT _template/my_template
{
  "index_patterns": ["test-*"], 
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "index.lifecycle.name": "my_policy", 
    "index.lifecycle.rollover_alias": "test-alias"
  }
}

This template will be applied to all indexes which have a name starting with test-

The template will set the policy to be used to my_policy

Now that a policy exists and is used in an index template we can create an initial index which will be managed by our policy:

PUT test-000001
{
  "aliases": {
    "test-alias":{
      "is_write_index": true 
    }
  }
}

Set this initial index to be the write index for this alias.

We can now write data to the test-alias alias. Because we have a rollover action defined in our policy, when the index grows larger than 25GB index lifecycle management will create a new index and roll the alias over to use the new index automatically.