Bird
Raised Fist0
Elasticsearchquery~20 mins

Template priority and composition in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Template Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this template composition?
Given two index templates with different priorities, what will be the final settings applied to an index named logs-2024?
Elasticsearch
{
  "index_templates": [
    {
      "name": "base_template",
      "index_patterns": ["logs-*"],
      "priority": 10,
      "template": {
        "settings": {
          "number_of_shards": "3",
          "refresh_interval": "30s"
        }
      }
    },
    {
      "name": "override_template",
      "index_patterns": ["logs-2024"],
      "priority": 20,
      "template": {
        "settings": {
          "refresh_interval": "10s",
          "number_of_replicas": "2"
        }
      }
    }
  ]
}
A{"number_of_shards": "3", "refresh_interval": "10s", "number_of_replicas": "2"}
B{"number_of_shards": "3", "refresh_interval": "30s", "number_of_replicas": "2"}
C{"number_of_shards": "3", "refresh_interval": "30s"}
D{"number_of_shards": "3", "refresh_interval": "10s"}
Attempts:
2 left
💡 Hint
Remember that templates with higher priority override settings from lower priority templates when index patterns match.
🧠 Conceptual
intermediate
1:30remaining
Which template applies when multiple templates match with the same priority?
If two index templates have the same priority and both match an index, which template's settings will Elasticsearch apply?
AThe template with the lexicographically larger name is applied first, then the other overrides it.
BElasticsearch merges both templates, with settings combined and conflicts resolved arbitrarily.
CThe template with the lexicographically smaller name is applied first, then the other overrides it.
DElasticsearch throws an error and refuses to create the index.
Attempts:
2 left
💡 Hint
Think about how Elasticsearch resolves conflicts when priorities are equal.
🔧 Debug
advanced
2:00remaining
Why does this template composition not apply the expected settings?
You have two templates: Template A (priority 5) matches logs-* and sets refresh_interval to "30s". Template B (priority 10) matches logs-2024-* and sets refresh_interval to "15s". You create an index named logs-2023-01. The refresh_interval is "30s" instead of "15s". Why?
ATemplate A has higher priority, so its settings override Template B.
BElasticsearch only applies one template per index, always the first defined.
CThe index name is invalid, so default settings are used.
DTemplate B does not match the index name <code>logs-2023-01</code>, so only Template A applies.
Attempts:
2 left
💡 Hint
Check the index patterns carefully against the index name.
📝 Syntax
advanced
1:30remaining
Which template JSON is correctly structured for composition with priority?
Select the valid JSON structure for an index template with priority and settings composition.
A
{
  "index_patterns": ["logs-*"],
  "priority": 15,
  "settings": {
    "number_of_shards": 1
  }
}
B
{
  "index_patterns": ["logs-*"],
  "priority": 15,
  "template": {
    "settings": {
      "number_of_shards": 1
    }
  }
}
C
{
  "index_patterns": ["logs-*"],
  "priority": "high",
  "template": {
    "settings": {
      "number_of_shards": 1
    }
  }
}
D
{
  "index_patterns": "logs-*",
  "priority": "15",
  "template": {
    "settings": {
      "number_of_shards": "1"
    }
  }
}
Attempts:
2 left
💡 Hint
Check the data types and nesting of keys carefully.
🚀 Application
expert
2:30remaining
How many settings keys will the final index have after applying these templates?
You have three templates: 1. Template X: priority 5, matches logs-*, sets refresh_interval and number_of_shards. 2. Template Y: priority 10, matches logs-2024-*, sets number_of_replicas and overrides refresh_interval. 3. Template Z: priority 10, matches logs-2024-*, sets index.lifecycle.name. You create an index named logs-2024-05. How many unique settings keys will the final index have?
A4
B3
C5
D2
Attempts:
2 left
💡 Hint
Count all unique keys from all matching templates, considering overrides.

Practice

(1/5)
1. What does the priority setting control in Elasticsearch index templates?
easy
A. Which template applies first when multiple templates match an index
B. The order of fields in the index mapping
C. The number of shards for the index
D. The refresh interval of the index

Solution

  1. Step 1: Understand the role of priority in templates

    The priority setting determines which template Elasticsearch applies first when multiple templates match the same index.
  2. Step 2: Differentiate priority from other settings

    Priority does not affect shard count, field order, or refresh interval; it only controls template application order.
  3. Final Answer:

    Which template applies first when multiple templates match an index -> Option A
  4. Quick Check:

    Priority controls template application order = B [OK]
Hint: Priority decides template order when multiple match [OK]
Common Mistakes:
  • Confusing priority with shard settings
  • Thinking priority affects field order
  • Assuming priority controls refresh interval
2. Which of the following is the correct way to define a template with priority 10 in Elasticsearch?
easy
A. { "index_patterns": ["logs-*"], "priority": true, "template": { "settings": {} } }
B. { "index_patterns": ["logs-*"], "priority": "high", "template": { "settings": {} } }
C. { "index_patterns": ["logs-*"], "priority": 10, "template": { "settings": {} } }
D. { "index_patterns": ["logs-*"], "priority": null, "template": { "settings": {} } }

Solution

  1. Step 1: Check the priority value type

    Priority must be a numeric value, such as 10, not a string or boolean.
  2. Step 2: Validate JSON structure

    { "index_patterns": ["logs-*"], "priority": 10, "template": { "settings": {} } } correctly uses an integer 10 for priority and valid JSON structure for template.
  3. Final Answer:

    { "index_patterns": ["logs-*"], "priority": 10, "template": { "settings": {} } } -> Option C
  4. Quick Check:

    Priority is a number, not string or boolean = C [OK]
Hint: Priority must be a number, not string or boolean [OK]
Common Mistakes:
  • Using string like "high" instead of number
  • Setting priority to true or null
  • Incorrect JSON structure for template
3. Given two templates: Template A with priority 5 and Template B with priority 10, both matching index logs-2024. Which template settings will Elasticsearch apply first?
medium
A. Template B settings will apply first
B. Elasticsearch throws an error due to conflict
C. Both templates apply simultaneously with no order
D. Template A settings will apply first

Solution

  1. Step 1: Understand priority order

    Elasticsearch sorts matching templates by priority in ascending order (lowest first) and merges their configurations, with later (higher priority) templates overriding earlier ones.
  2. Step 2: Compare priorities of Template A and B

    Template A has priority 5, which is lower than Template B's 10, so Template A applies first.
  3. Final Answer:

    Template A settings will apply first -> Option D
  4. Quick Check:

    Lower priority number applies first = B [OK]
Hint: Lower priority number means earlier application [OK]
Common Mistakes:
  • Thinking higher priority applies first
  • Thinking templates apply simultaneously
  • Expecting error on priority conflict
4. You have two templates: Template X with composed_of referencing Template Y, but Template Y is missing. What will happen when you try to create an index matching Template X?
medium
A. Template X applies without Template Y's settings
B. Index creation fails with an error about missing template
C. Elasticsearch ignores Template X and uses default settings
D. Template Y is automatically created as empty

Solution

  1. Step 1: Understand template composition with composed_of

    Templates using composed_of require referenced templates to exist.
  2. Step 2: Check behavior when referenced template is missing

    If Template Y is missing, Elasticsearch throws an error during index creation because it cannot compose Template X fully.
  3. Final Answer:

    Index creation fails with an error about missing template -> Option B
  4. Quick Check:

    Missing composed_of template causes error = A [OK]
Hint: All composed_of templates must exist or error occurs [OK]
Common Mistakes:
  • Assuming missing templates are ignored
  • Expecting automatic creation of missing templates
  • Thinking index creation succeeds without all templates
5. You want to create a flexible index template setup where a base template defines common settings, and multiple specialized templates add mappings for different data types. How should you use priority and composition to achieve this?
hard
A. Create a base template with low priority and use composed_of in specialized templates with higher priority
B. Create specialized templates with low priority and base template with highest priority without composition
C. Use only one template with all settings combined, no priority or composition needed
D. Set all templates with the same priority and avoid composition

Solution

  1. Step 1: Use base template for common settings with low priority

    The base template should have a lower priority so it is merged first in the composition order, providing common settings that higher priority templates can override.
  2. Step 2: Use composed_of in specialized templates with higher priority

    Specialized templates compose the base template and have higher priority to add or override mappings.
  3. Step 3: Combine priority and composition for flexible layering

    This setup allows reusable base settings and flexible specialized additions.
  4. Final Answer:

    Create a base template with low priority and use composed_of in specialized templates with higher priority -> Option A
  5. Quick Check:

    Base low priority + composed_of in higher priority = D [OK]
Hint: Base template low priority, specialized templates compose with higher priority [OK]
Common Mistakes:
  • Setting base template with highest priority
  • Not using composition for reusable settings
  • Using same priority for all templates
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard