📖 Scenario: You are managing logs for a web application. To save space and keep the system fast, you want to automatically delete old logs after some time.
🎯 Goal: Create an index lifecycle policy in Elasticsearch that automatically deletes indices older than 30 days.
📋 What You'll Learn
Create an index lifecycle policy named log_policy with a delete phase
Set the delete phase to trigger after 30 days
Apply the policy to an index template named log_template
The index template should match indices named logs-*
💡 Why This Matters
🌍 Real World
Managing log data efficiently by automatically deleting old data to save storage and improve search performance.
💼 Career
Index lifecycle management is a key skill for Elasticsearch administrators and DevOps engineers to maintain healthy and cost-effective search clusters.
Progress0 / 4 steps
1
Create the index lifecycle policy
Create an index lifecycle policy called log_policy with a delete phase that deletes indices after 30d.
Elasticsearch
Hint
Use the delete phase with min_age set to 30d and an empty delete action.
2
Create an index template with the lifecycle policy
Create an index template called log_template that matches indices named logs-* and applies the lifecycle policy log_policy.
Elasticsearch
Hint
Set index_patterns to ["logs-*"] and in settings add index.lifecycle.name with value log_policy.
3
Apply the lifecycle policy to an existing index
Add the lifecycle policy log_policy to an existing index named logs-2024-06 by updating its settings.
Elasticsearch
Hint
Update the index settings to include index.lifecycle.name with value log_policy.
4
Verify the lifecycle policy is active
Write a query to get the lifecycle policy status for the index logs-2024-06 to verify the policy log_policy is applied.
Elasticsearch
Hint
Use the _ilm/explain API on the index logs-2024-06 to check lifecycle status.
Practice
(1/5)
1. What is the main purpose of Index Lifecycle Management (ILM) in Elasticsearch?
easy
A. To automate index handling and improve cluster performance
B. To manually create indexes for each data type
C. To backup data to external storage
D. To encrypt index data for security
Solution
Step 1: Understand ILM's role
ILM automates managing indexes through their lifecycle phases.
Step 2: Identify the benefit
Automation helps save space and improves cluster health and performance.
Final Answer:
To automate index handling and improve cluster performance -> Option A
Quick Check:
ILM automates index management = A [OK]
Hint: ILM automates index tasks to keep Elasticsearch healthy [OK]
Common Mistakes:
Thinking ILM is for manual index creation
Confusing ILM with backup or encryption
Assuming ILM only deletes indexes
2. Which of the following is the correct way to define a rollover action in an ILM policy JSON?
easy
A. "rollover": { "max_size": "50gb", "max_age": "30d" }
B. "rollover": "true"
C. "rollover": { "size": "50gb" }
D. "rollover": { "max_documents": 1000 }
Solution
Step 1: Check rollover action syntax
Rollover requires conditions like max_size and max_age in a JSON object.
Step 2: Validate options
"rollover": { "max_size": "50gb", "max_age": "30d" } correctly uses max_size and max_age keys with proper values.
Final Answer:
"rollover": { "max_size": "50gb", "max_age": "30d" } -> Option A
Quick Check:
Rollover needs max_size and max_age keys = A [OK]
Hint: Rollover needs max_size and max_age keys in JSON [OK]
Common Mistakes:
Using string 'true' instead of object for rollover
After applying, the shrink action never runs. What is the likely cause?
medium
A. Rollover max_size is too small
B. Shrink action requires delete phase
C. Shrink action must be in hot phase
D. The index has not reached 10 days old yet
Solution
Step 1: Check warm phase min_age
Shrink runs only after index is at least 10 days old.
Step 2: Confirm index age
If index age is less than 10 days, shrink won't trigger yet.
Final Answer:
The index has not reached 10 days old yet -> Option D
Quick Check:
min_age controls action timing = C [OK]
Hint: Check min_age before expecting warm phase actions [OK]
Common Mistakes:
Assuming shrink needs delete phase
Changing rollover size unrelated to shrink
Placing shrink in wrong phase
5. You want to create an ILM policy that: - Rolls over an index at 30GB or 15 days - Moves the index to warm phase after rollover - Deletes the index 60 days after rollover
Which policy configuration correctly implements this?