Bird
Raised Fist0
Elasticsearchquery~20 mins

Component templates in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Component Template Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of creating a component template with settings
What is the output of this Elasticsearch API call when creating a component template named my_template with a number_of_shards setting of 3?
Elasticsearch
PUT _component_template/my_template
{
  "template": {
    "settings": {
      "number_of_shards": 3
    }
  }
}
A{"acknowledged":true}
B{"error":"component_template_already_exists_exception"}
C{"acknowledged":false}
D{"error":"invalid_template_settings"}
Attempts:
2 left
💡 Hint
Creating a new component template returns an acknowledged true response if successful.
❓ Predict Output
intermediate
2:00remaining
Result of applying a component template to an index template
Given a component template comp_temp that sets number_of_replicas to 2, what will be the number_of_replicas setting of an index created from an index template that uses this component template?
Elasticsearch
PUT _component_template/comp_temp
{
  "template": {
    "settings": {
      "number_of_replicas": 2
    }
  }
}

PUT _index_template/my_index_template
{
  "index_patterns": ["myindex*"],
  "composed_of": ["comp_temp"]
}

PUT myindex1
A0
B1
CUndefined (error)
D2
Attempts:
2 left
💡 Hint
Component templates settings are merged into index templates and applied to indices.
🔧 Debug
advanced
2:00remaining
Identify the error in this component template definition
What error will this component template creation request produce?
Elasticsearch
PUT _component_template/bad_template
{
  "template": {
    "mappings": {
      "properties": {
        "name": { "type": "text" },
        "age": { "type": "integer" }
      }
    },
    "settings": {
      "number_of_shards": "two"
    }
  }
}
ANo error, template created successfully
BValidationException: number_of_shards must be an integer
CParsingException: unknown field 'mappings' in template
DElasticsearchTimeoutException
Attempts:
2 left
💡 Hint
Check the type of the number_of_shards setting value.
🧠 Conceptual
advanced
2:00remaining
Understanding component template composition order
If an index template composes two component templates, compA and compB, and both define the refresh_interval setting differently, which value will the index use?
AThe value from the index template itself, ignoring component templates
BThe value from the first component template listed in the composed_of array
CThe value from the last component template listed in the composed_of array
DElasticsearch throws a conflict error and refuses to create the index
Attempts:
2 left
💡 Hint
Later component templates override earlier ones in the composition order.
❓ Predict Output
expert
2:00remaining
Output of retrieving a non-existent component template
What is the output of this request when the component template missing_template does not exist?
Elasticsearch
GET _component_template/missing_template
A{"error":{"root_cause":[{"type":"resource_not_found_exception","reason":"component_template [missing_template] missing"}],"type":"resource_not_found_exception","reason":"component_template [missing_template] missing"},"status":404}
B{"component_templates":[]}
C{"acknowledged":false}
D{"error":"index_not_found_exception"}
Attempts:
2 left
💡 Hint
Elasticsearch returns a 404 error with details if the component template is missing.

Practice

(1/5)
1. What is the main purpose of a component template in Elasticsearch?
easy
A. To manage user access permissions
B. To store actual index data
C. To store reusable index settings and mappings
D. To perform search queries

Solution

  1. Step 1: Understand component template role

    Component templates hold reusable parts like settings and mappings for indexes.
  2. Step 2: Differentiate from other features

    They do not store data or handle queries or permissions directly.
  3. Final Answer:

    To store reusable index settings and mappings -> Option C
  4. Quick Check:

    Component templates = reusable settings/mappings [OK]
Hint: Component templates hold reusable settings, not data or queries [OK]
Common Mistakes:
  • Confusing component templates with actual index data storage
  • Thinking component templates handle search queries
  • Assuming component templates manage user permissions
2. Which of the following is the correct way to create a component template using Elasticsearch API?
easy
A. PUT /_component_template/my_template { "template": { "settings": { "number_of_shards": 1 } } }
B. POST /my_template { "settings": { "number_of_shards": 1 } }
C. GET /_component_template/my_template { "settings": { "number_of_shards": 1 } }
D. DELETE /_component_template/my_template

Solution

  1. Step 1: Identify correct HTTP method and endpoint

    Creating a component template uses PUT method on /_component_template/{name}.
  2. Step 2: Check request body structure

    The body must include a template object with settings or mappings.
  3. Final Answer:

    PUT /_component_template/my_template { "template": { "settings": { "number_of_shards": 1 } } } -> Option A
  4. Quick Check:

    PUT + /_component_template + template body = A [OK]
Hint: Use PUT with /_component_template and include 'template' in body [OK]
Common Mistakes:
  • Using POST instead of PUT for creation
  • Using GET or DELETE for creating templates
  • Omitting the 'template' wrapper in the JSON body
3. Given this component template creation request, what will be the value of number_of_replicas in the resulting index if used in an index template?
PUT /_component_template/replica_template
{
  "template": {
    "settings": {
      "number_of_replicas": 2
    }
  }
}
medium
A. 2
B. 1
C. 0
D. Undefined

Solution

  1. Step 1: Read the component template settings

    The template sets number_of_replicas to 2 explicitly.
  2. Step 2: Understand inheritance in index templates

    When this component template is used in an index template, the setting applies to the index.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Component template sets replicas = 2 [OK]
Hint: Settings in component templates apply directly when used [OK]
Common Mistakes:
  • Assuming default replica count 1 overrides component template
  • Thinking replicas default to 0 if not set elsewhere
  • Confusing component template with index data
4. You tried to create a component template but got an error. Which of these is the most likely cause?
PUT /_component_template/my_template
{
  "settings": {
    "number_of_shards": 3
  }
}
medium
A. Using PUT instead of POST
B. number_of_shards cannot be set in component templates
C. Incorrect endpoint; should be /_index_template
D. Missing the 'template' wrapper around settings

Solution

  1. Step 1: Check JSON structure for component template

    Component templates require a template key wrapping settings and mappings.
  2. Step 2: Identify missing wrapper

    The request body lacks the "template" object, causing the error.
  3. Final Answer:

    Missing the 'template' wrapper around settings -> Option D
  4. Quick Check:

    Component template body must have 'template' key [OK]
Hint: Always wrap settings inside 'template' in component templates [OK]
Common Mistakes:
  • Omitting the 'template' key in JSON body
  • Confusing component template endpoint with index template
  • Thinking PUT is wrong method for creation
5. You want to create an index template that uses two component templates: one for settings and one for mappings. Which is the correct way to reference both component templates in the index template?
hard
A. { "index_patterns": ["logs-*"], "template": { "settings": {}, "mappings": {} } }
B. { "index_patterns": ["logs-*"], "composed_of": ["settings_template", "mappings_template"] }
C. { "index_patterns": ["logs-*"], "components": ["settings_template", "mappings_template"] }
D. { "index_patterns": ["logs-*"], "use_components": ["settings_template", "mappings_template"] }

Solution

  1. Step 1: Recall index template syntax for component templates

    Index templates use the composed_of array to list component templates.
  2. Step 2: Match correct JSON structure

    { "index_patterns": ["logs-*"], "composed_of": ["settings_template", "mappings_template"] } correctly uses composed_of with component template names.
  3. Final Answer:

    { "index_patterns": ["logs-*"], "composed_of": ["settings_template", "mappings_template"] } -> Option B
  4. Quick Check:

    Use 'composed_of' to combine component templates [OK]
Hint: Use 'composed_of' array to combine component templates [OK]
Common Mistakes:
  • Using wrong key like 'components' or 'use_components'
  • Trying to put settings and mappings directly instead of referencing components
  • Confusing index template syntax with component template syntax
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