0
0
Elasticsearchquery~10 mins

Index templates in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Index templates
Create or Update Template
Define Index Patterns
Set Settings, Mappings, Aliases
Save Template
New Index Created
Template Matches Index Name?
NoUse Default Settings
Yes
Apply Template Settings, Mappings, Aliases
Index Ready for Use
The flow shows how an index template is created and applied automatically to new indices matching its pattern.
Execution Sample
Elasticsearch
PUT _index_template/my_template
{
  "index_patterns": ["logs-*"] ,
  "template": {
    "settings": {"number_of_shards": 1}
  }
}
This creates an index template named 'my_template' that applies to indices starting with 'logs-' and sets shards to 1.
Execution Table
StepActionInput/ConditionResult/Output
1Create templateName: my_template, Pattern: logs-*Template stored with pattern logs-*
2New index creationIndex name: logs-2024-06-01Check templates matching 'logs-2024-06-01'
3Match template?Does 'logs-2024-06-01' match 'logs-*'?Yes, matches pattern
4Apply templateApply settings from 'my_template'Index created with 1 shard
5New index creationIndex name: data-2024-06-01Check templates matching 'data-2024-06-01'
6Match template?Does 'data-2024-06-01' match 'logs-*'?No match
7Apply defaultNo matching templateIndex created with default settings
💡 Execution stops after index creation with applied template or default settings.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 4After Step 6Final
Template Storeemptymy_template with pattern logs-*my_template with pattern logs-*my_template with pattern logs-*my_template with pattern logs-*my_template with pattern logs-*
Index Namenonenonelogs-2024-06-01logs-2024-06-01data-2024-06-01data-2024-06-01
Template Matchnonenonetruetruefalsefalse
Index Settingsdefaultdefaultapplied shards=1applied shards=1defaultdefault
Key Moments - 3 Insights
Why does the index 'data-2024-06-01' not get the template settings?
Because its name does not match the template pattern 'logs-*' as shown in execution_table step 6 where the match is false.
Can multiple templates apply to one index?
Yes, but in this example only one template matches. The system applies the best matching template or merges settings if multiple match.
What happens if no template matches an index?
The index is created with default settings, as shown in execution_table step 7 for 'data-2024-06-01'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the shard count for the index 'logs-2024-06-01' after step 4?
ADefault shard count
B1 shard
C5 shards
D0 shards
💡 Hint
Check the 'Index Settings' variable in variable_tracker after step 4.
At which step does the index 'data-2024-06-01' fail to match the template pattern?
AStep 3
BStep 5
CStep 6
DStep 7
💡 Hint
Look at the 'Match template?' action and result in execution_table.
If the template pattern was changed to '*-2024-*', which index would match the template?
ABoth 'logs-2024-06-01' and 'data-2024-06-01'
BOnly 'logs-2024-06-01'
COnly 'data-2024-06-01'
DNeither index
💡 Hint
Consider how the pattern '*-2024-*' matches index names in execution_table steps 2 and 5.
Concept Snapshot
Index templates in Elasticsearch:
- Define patterns to match index names
- Set default settings, mappings, aliases
- Automatically apply when new index matches
- Helps keep index configurations consistent
- No effect on existing indices
Full Transcript
Index templates in Elasticsearch let you define settings and mappings that automatically apply to new indices matching a name pattern. First, you create or update a template with a pattern like 'logs-*'. When a new index is created, Elasticsearch checks if its name matches any template pattern. If yes, it applies the template's settings and mappings to the index. If no template matches, default settings are used. This process ensures new indices have consistent configurations without manual setup each time.