From Elasticsearch documentation:
“The index lifecycle management (ILM) [1] feature of the Elastic Stack provides an integrated and streamlined way to manage time-based data, making it easier to follow best practices for managing your indices. Compared to index curation, migrating to ILM gives you more fine-grained control over the lifecycle of each index.”
“You can configure index lifecycle management (ILM) [2] policies to automatically manage indices according to your performance, resiliency, and retention requirements. For example, you could use ILM to:
-
- Spin up a new index when an index reaches a certain size or number of documents
- Create a new index each day, week, or month and archive previous ones
- Delete stale indices to enforce data retention standards
You can create and manage index lifecycle policies through Kibana Management or the ILM APIs.”
This is exactly what we need to avoid our disk issues.
We would like to spin up a new index when an index reaches a certain size (I) and delete stale indices (II).
The first requirement (I) can be achieved thanks to the rollover strategy that: “Rolls over a target to a new index when the existing index meets one or more of the rollover conditions” [3]; while the second requirement (II) can be done through the definition of a policy. In the policy, we can define states, actions, and transitions.
The indexes associated with that policy start from the default state, process the actions in that state, and evaluate the transitions condition. If the condition is true, the indexes will pass to the new state for which again action and transitions will be executed.
From the Elasticsearch documentation: “An index’s lifecycle policy specifies which phases are applicable, what actions are performed in each phase, and when it transitions between phases” [4].
Let’s see together all the necessary steps to create a policy that automates index rollover and deletion. For our example, we are using the Elasticsearch 7.10 version managed by Amazon which includes Open Distro plugins.
We leverage Kibana tools for some of these steps.
1 – Create an index template for Rollover
This template is the one used for rollover. This defines the settings that the newly created index will have.
-
- In index_patterns we define the name of the new index. In this case, it starts with index_name- and then an incremental number follows.
- index.opendistro.index_state_management.rollover_alias is the name of the rollover alias. This is associated with the current active index (the one used to index new documents) and will be moved to the new index after the rollover is done.
Here is the request to create the index template: