Bird
Raised Fist0
Elasticsearchquery~10 mins

Component templates in Elasticsearch - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a component template with a settings block.

Elasticsearch
{
  "template": {
    "settings": [1]
  }
}
Drag options to blanks, or click blank then click option'
Anumber_of_shards: 1
B["number_of_shards", 1]
C"number_of_shards: 1"
D{"number_of_shards": 1}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces for settings.
Not quoting keys or values properly.
2fill in blank
medium

Complete the code to add a mappings block with a dynamic template.

Elasticsearch
{
  "template": {
    "mappings": {
      "dynamic_templates": [
        {
          "strings_as_keywords": {
            "match_mapping_type": [1]
          }
        }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A"string"
B"keyword"
C"text"
D"integer"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "keyword" instead of "string" for match_mapping_type.
Using incorrect data types like "integer".
3fill in blank
hard

Fix the error in the component template by completing the lifecycle policy reference.

Elasticsearch
{
  "template": {
    "settings": {
      "index.lifecycle.name": [1]
    }
  }
}
Drag options to blanks, or click blank then click option'
Apolicy_1
B"policy_1"
Cpolicy1
D'policy_1'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the policy name, causing JSON errors.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill both blanks to create a component template with an alias and a priority.

Elasticsearch
{
  "template": {
    "aliases": {
      "[1]": {}
    },
    "priority": [2]
  }
}
Drag options to blanks, or click blank then click option'
Alogs_alias
B5
C10
Dmetrics_alias
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number as an alias name.
Using a string for priority instead of a number.
5fill in blank
hard

Fill all three blanks to define a component template with settings, mappings, and aliases.

Elasticsearch
{
  "template": {
    "settings": [1],
    "mappings": [2],
    "aliases": {
      "[3]": {}
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"number_of_replicas": 2}
B{"properties": {"field1": {"type": "keyword"}}}
Capp_logs
D{"number_of_shards": 3}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up settings and mappings blocks.
Not quoting alias names properly.

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