Tutorial: Automate rollover with ILM
editTutorial: Automate rollover with ILM
editThis tutorial demonstrates how to use index lifecycle management (ILM) to manage indices that contain time-series data.
When you continuously index timestamped documents into Elasticsearch using Filebeat, Logstash, or some other mechanism, you typically use an index alias so you can periodically roll over to a new index. This enables you to implement a hot-warm-cold architecture to meet your performance requirements for your newest data, control costs over time, enforce retention policies, and still get the most out of your data.
To automate rollover and management of time-series indices with ILM, you:
- 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.
- Verify indices are moving through the lifecycle phases as expected.
For an introduction to rolling indices, see Rollover.
Filebeat includes a default ILM policy that initiates the rollover action when the index size reaches 50GB or becomes 30 days old. You can use this policy as a starting point, or replace it with a custom policy. See Use ILM to manage Filebeat time-based indices.
Create a lifecycle policy
editA lifecycle policy specifies the phases in the index lifecycle
and the actions to perform in each phase. A lifecycle can have up to four phases:
hot
, warm
, cold
, and delete
.
You can define and manage policies through Kibana Management or with the put policy API.
For example, you might define a timeseries_policy
that has two phases:
-
A
hot
phase that defines a rollover action to specify that an index rolls over when it reaches either amax_size
of 50 gigabytes or amax_age
of 30 days. -
A
delete
phase that setsmin_age
to remove the index 90 days after rollover. Note that this value is relative to the rollover time, not the index creation time.
The underlying put policy request looks like this:
PUT _ilm/policy/datastream_policy { "policy": { "phases": { "hot": { "actions": { "rollover": { "max_size": "50GB", "max_age": "30d" } } }, "delete": { "min_age": "90d", "actions": { "delete": {} } } } } }
The |
|
Trigger the |
|
Move the index into the |
|
Trigger the |
You can also invoke this API directly to add lifecycle policies.
For the complete list of actions that index lifecycle management can perform, see Index lifecycle actions.
Create an index template to apply the lifecycle policy
editTo automatically apply a lifecycle policy to the new write index on rollover, specify the policy in the index template used to create new indices.
For example, you might create a timeseries_template
that is applied to new indices
whose names match the timeseries-*
index pattern.
To enable automatic rollover, the template configures two ILM settings:
-
index.lifecycle.name
specifies the name of the lifecycle policy to apply to new indices that match the index pattern. -
index.lifecycle.rollover_alias
specifies the index alias to be rolled over when the rollover action is triggered for an index.
You can use the Kibana Create template wizard to add the template. This wizard invokes the put template API to create the template with the options you specify.
The underlying request looks like this:
PUT _template/datastream_template { "index_patterns": ["datastream-*"], "settings": { "number_of_shards": 1, "number_of_replicas": 1, "index.lifecycle.name": "datastream_policy", "index.lifecycle.rollover_alias": "datastream" } }
Apply the template to a new index if its name starts with |
|
The name of the lifecycle policy to apply to each new index. |
|
The name of the alias used to reference these indices. Required for policies that use the rollover action. |
You can also invoke this API directly to add templates.
Bootstrap the initial time-series index
editTo get things started, you need to bootstrap an initial index and designate it as the write index for the rollover alias specified in your index template. The name of this index must match the template’s index pattern and end with a number. On rollover, this value is incremented to generate a name for the new index.
For example, the following request creates an index called datastream-000001
and makes it the write index for the datastream
alias.
PUT datastream-000001 { "aliases": { "datastream": { "is_write_index": true } } }
When the rollover conditions are met, the rollover
action:
-
Creates a new index called
datastream-000002
. This matches thedatastream-*
pattern, so the settings fromdatastream_template
are applied to the new index. - Designates the new index as the write index and makes the bootstrap index read-only.
This process repeats each time rollover conditions are met.
You can search across all of the indices managed by the datastream_policy
with the datastream
alias.
Write operations are routed to the current write index.
Check lifecycle progress
editTo get status information for managed indices, you use the ILM explain API. This lets you find out things like:
- What phase an index is in and when it entered that phase.
- The current action and what step is being performed.
- If any errors have occurred or progress is blocked.
For example, the following request gets information about the datastream
indices:
GET datastream-*/_ilm/explain
The response below shows that the bootstrap index is waiting in the hot
phase’s rollover
action.
It remains in this state and ILM continues to call attempt-rollover
until the rollover conditions are met.
{ "indices": { "datastream-000001": { "index": "datastream-000001", "managed": true, "policy": "datastream_policy", "lifecycle_date_millis": 1538475653281, "age": "30s", "phase": "hot", "phase_time_millis": 1538475653317, "action": "rollover", "action_time_millis": 1538475653317, "step": "attempt-rollover", "step_time_millis": 1538475653317, "phase_execution": { "policy": "datastream_policy", "phase_definition": { "min_age": "0ms", "actions": { "rollover": { "max_size": "50gb", "max_age": "30d" } } }, "version": 1, "modified_date_in_millis": 1539609701576 } } } }