Index lifecycle management in Elasticsearch - Time & Space Complexity
When managing data in Elasticsearch, index lifecycle management helps automate how indexes change over time.
We want to understand how the time to apply lifecycle policies grows as the number of indexes increases.
Analyze the time complexity of this lifecycle policy application snippet.
PUT _ilm/policy/my_policy
{
"policy": {
"phases": {
"hot": { "actions": { "rollover": { "max_size": "50gb" } } },
"delete": { "min_age": "30d", "actions": { "delete": {} } }
}
}
}
POST my_index/_ilm/explain
This code defines a lifecycle policy with rollover and delete phases, then checks the policy status on an index.
Look at what repeats when applying lifecycle policies.
- Primary operation: Checking and updating each index against its lifecycle policy.
- How many times: Once per index in the cluster.
As the number of indexes grows, the system must check each one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The work grows directly with the number of indexes.
Time Complexity: O(n)
This means the time to apply lifecycle policies grows linearly with the number of indexes.
[X] Wrong: "Applying lifecycle policies happens instantly no matter how many indexes there are."
[OK] Correct: Each index needs to be checked and updated, so more indexes mean more work and more time.
Understanding how operations scale with data size shows you can design systems that stay efficient as they grow.
"What if lifecycle policies were applied only to indexes with a specific tag? How would that affect the time complexity?"
Practice
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 AQuick Check:
ILM automates index management = A [OK]
- Thinking ILM is for manual index creation
- Confusing ILM with backup or encryption
- Assuming ILM only deletes indexes
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 AQuick Check:
Rollover needs max_size and max_age keys = A [OK]
- Using string 'true' instead of object for rollover
- Missing max_age or max_size keys
- Using incorrect key names like 'size'
{"phases": {"hot": {"actions": {"rollover": {"max_size": "10gb"}}}, "delete": {"min_age": "90d", "actions": {"delete": {}}}}}What happens to an index after it reaches 10GB?
Solution
Step 1: Analyze rollover action in hot phase
The policy rolls over the index when it reaches 10GB.Step 2: Understand delete phase timing
Deletion happens only after 90 days, so not immediate.Final Answer:
It rolls over to a new index and continues indexing -> Option BQuick Check:
Rollover at 10GB, delete after 90d = D [OK]
- Confusing rollover with immediate deletion
- Ignoring min_age delay for delete phase
- Assuming data stops indexing after rollover
{"phases": {"hot": {"actions": {"rollover": {"max_size": "20gb"}}}, "warm": {"min_age": "10d", "actions": {"shrink": {"number_of_shards": 1}}}}}After applying, the shrink action never runs. What is the likely cause?
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 DQuick Check:
min_age controls action timing = C [OK]
- Assuming shrink needs delete phase
- Changing rollover size unrelated to shrink
- Placing shrink in wrong phase
- 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?
Solution
Step 1: Verify rollover conditions
{"phases": {"hot": {"actions": {"rollover": {"max_size": "30gb", "max_age": "15d"}}}, "warm": {"min_age": "15d", "actions": {}}, "delete": {"min_age": "60d", "actions": {"delete": {}}}}} uses max_size 30gb and max_age 15d, matching requirements.Step 2: Check warm and delete phases
Warm phase starts at 15d (after rollover), delete at 60d, as required.Step 3: Confirm other options
Other options have wrong sizes, ages, or missing actions.Final Answer:
{"phases": {"hot": {"actions": {"rollover": {"max_size": "30gb", "max_age": "15d"}}}, "warm": {"min_age": "15d", "actions": {}}, "delete": {"min_age": "60d", "actions": {"delete": {}}}}} -> Option CQuick Check:
Rollover at 30gb/15d, warm at 15d, delete at 60d = B [OK]
- Swapping max_size and max_age values
- Setting warm min_age too late
- Missing delete action or wrong min_age
Ready to prove it?
Pass the test and this pattern moves unknown
