Bird
Raised Fist0
Elasticsearchquery~10 mins

Why templates standardize index creation in Elasticsearch - Test Your Understanding

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

Complete the code to define a template that applies to all indices starting with 'logs-'.

Elasticsearch
{
  "index_patterns": ["[1]"],
  "settings": {
    "number_of_shards": 1
  }
}
Drag options to blanks, or click blank then click option'
A*-logs
Blog-*
Clogs
Dlogs-*
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'log-*' which misses the 's' in 'logs'.
Using 'logs' without wildcard, which matches only one index.
Using '*-logs' which matches indices ending with '-logs'.
2fill in blank
medium

Complete the code to set the number of replicas to 2 in the template settings.

Elasticsearch
{
  "settings": {
    "number_of_replicas": [1]
  }
}
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting replicas to 0 disables redundancy.
Setting replicas to 1 only creates one copy, not two.
3fill in blank
hard

Fix the error in the template mapping by completing the field type for 'timestamp'.

Elasticsearch
"mappings": {
  "properties": {
    "timestamp": { "type": "[1]" }
  }
}
Drag options to blanks, or click blank then click option'
Ainteger
Btext
Cdate
Dkeyword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' which is for full text search, not dates.
Using 'keyword' which is for exact string matches.
Using 'integer' which is for numbers, not dates.
4fill in blank
hard

Fill both blanks to create a template that applies to indices starting with 'app-' and sets refresh interval to 30s.

Elasticsearch
{
  "index_patterns": ["[1]"],
  "settings": {
    "refresh_interval": "[2]"
  }
}
Drag options to blanks, or click blank then click option'
Aapp-*
B60s
C30s
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' without wildcard matches only one index.
Setting refresh interval to '60s' instead of '30s'.
5fill in blank
hard

Fill all three blanks to define a template with pattern 'metrics-*', 3 shards, and mapping type 'keyword' for 'host'.

Elasticsearch
{
  "index_patterns": ["[1]"],
  "settings": {
    "number_of_shards": [2]
  },
  "mappings": {
    "properties": {
      "host": { "type": "[3]" }
    }
  }
}
Drag options to blanks, or click blank then click option'
Ametrics-*
B3
Ckeyword
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'keyword' for 'host' field.
Setting shards to 1 or 5 instead of 3.
Using wrong index pattern without wildcard.

Practice

(1/5)
1. Why do Elasticsearch index templates help when creating multiple indexes with similar data?
easy
A. They speed up the search queries by caching results.
B. They delete old indexes to save space.
C. They automatically apply consistent settings and mappings to all matching indexes.
D. They convert data into a different format before indexing.

Solution

  1. Step 1: Understand the purpose of index templates

    Index templates define settings and mappings that apply automatically to new indexes matching a pattern.
  2. Step 2: Recognize the benefit of consistency

    Using templates ensures all similar indexes have the same structure, avoiding manual errors and saving time.
  3. Final Answer:

    They automatically apply consistent settings and mappings to all matching indexes. -> Option C
  4. Quick Check:

    Templates = consistent index setup [OK]
Hint: Templates set index rules automatically for matching names [OK]
Common Mistakes:
  • Thinking templates speed up searches directly
  • Confusing templates with index deletion tools
  • Believing templates change data format
2. Which of the following is the correct way to define an index template in Elasticsearch?
easy
A. { "template": { "shards": 1 }, "pattern": ["logs"] }
B. { "index": { "shards": 1 }, "pattern": "logs-*" }
C. { "settings": { "shards": 1 }, "match": "logs-*" }
D. { "template": { "settings": { "number_of_shards": 1 } }, "index_patterns": ["logs-*"] }

Solution

  1. Step 1: Recall the correct template structure

    Elasticsearch templates use "index_patterns" to match index names and "template" to define settings and mappings.
  2. Step 2: Identify the valid JSON format

    { "template": { "settings": { "number_of_shards": 1 } }, "index_patterns": ["logs-*"] } correctly uses "index_patterns" and nests settings inside "template".
  3. Final Answer:

    { "template": { "settings": { "number_of_shards": 1 } }, "index_patterns": ["logs-*"] } -> Option D
  4. Quick Check:

    Correct template keys = { "template": { "settings": { "number_of_shards": 1 } }, "index_patterns": ["logs-*"] } [OK]
Hint: Look for "index_patterns" and nested "template" keys [OK]
Common Mistakes:
  • Using "pattern" instead of "index_patterns"
  • Placing settings outside the "template" object
  • Using incorrect JSON keys like "match"
3. Given this template:
{
  "index_patterns": ["sales-*"],
  "template": {
    "settings": { "number_of_replicas": 2 },
    "mappings": { "properties": { "price": { "type": "float" } } }
  }
}
What will be the number_of_replicas for an index named sales-2024 created after this template?
medium
A. 2
B. 1
C. 0
D. 3

Solution

  1. Step 1: Match index name with template pattern

    The index name "sales-2024" matches the pattern "sales-*" in the template.
  2. Step 2: Apply template settings to the index

    The template sets "number_of_replicas" to 2, so the new index will have 2 replicas.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Matching pattern applies replicas = 2 [OK]
Hint: Match index name to pattern, then apply template settings [OK]
Common Mistakes:
  • Assuming default replicas instead of template value
  • Ignoring pattern matching rules
  • Confusing replicas with shards
4. You created this template:
{
  "index_patterns": ["app-*"],
  "template": {
    "settings": { "number_of_shards": 3 }
  }
}
But new indexes named app-logs are created with 5 shards instead of 3. What is the likely problem?
medium
A. The template was created after the indexes were created.
B. The index name does not match the pattern "app-*".
C. The setting "number_of_shards" cannot be set by templates.
D. The template JSON syntax is invalid.

Solution

  1. Step 1: Understand when templates apply

    Templates apply only when an index is created. Existing indexes keep their original settings.
  2. Step 2: Check index creation timing

    If indexes were created before the template, they won't have the template's shard settings.
  3. Final Answer:

    The template was created after the indexes were created. -> Option A
  4. Quick Check:

    Templates affect new indexes only [OK]
Hint: Templates apply only at index creation time [OK]
Common Mistakes:
  • Thinking templates update existing indexes
  • Assuming pattern mismatch without checking
  • Believing shard count can't be set in templates
5. You want to ensure all indexes starting with user-data- have the same mapping for a username field as keyword type and 1 shard. Which template JSON correctly achieves this?
hard
A. { "index_patterns": ["user-data-*"], "template": { "settings": { "number_of_replicas": 1 }, "mappings": { "properties": { "username": { "type": "keyword" } } } } }
B. { "index_patterns": ["user-data-*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "username": { "type": "keyword" } } } } }
C. { "index_patterns": ["user-data-*"], "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "username": { "type": "text" } } } }
D. { "pattern": "user-data-*", "settings": { "shards": 1 }, "mappings": { "username": "keyword" } }

Solution

  1. Step 1: Check index pattern and template structure

    { "index_patterns": ["user-data-*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "username": { "type": "keyword" } } } } } uses "index_patterns" and nests settings and mappings inside "template", which is correct.
  2. Step 2: Verify settings and mapping details

    It sets "number_of_shards" to 1 and maps "username" as "keyword", matching requirements.
  3. Final Answer:

    { "index_patterns": ["user-data-*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "username": { "type": "keyword" } } } } } -> Option B
  4. Quick Check:

    Correct pattern, shards, and mapping = { "index_patterns": ["user-data-*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "username": { "type": "keyword" } } } } } [OK]
Hint: Use "index_patterns" and nest settings/mappings inside "template" [OK]
Common Mistakes:
  • Using wrong keys like "pattern" or placing settings outside "template"
  • Setting wrong shard or replica counts
  • Mapping "username" as "text" instead of "keyword"
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