0
0
Elasticsearchquery~20 mins

Dynamic templates in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic Templates Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the mapping result of this dynamic template?

Given the following dynamic template in an Elasticsearch index mapping, what will be the data type of fields named user_email and user_age?

Elasticsearch
{
  "mappings": {
    "dynamic_templates": [
      {
        "strings_as_keywords": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword"
          }
        }
      },
      {
        "integers_as_long": {
          "match_mapping_type": "long",
          "mapping": {
            "type": "long"
          }
        }
      }
    ]
  }
}
Auser_email: keyword, user_age: long
Buser_email: text, user_age: integer
Cuser_email: keyword, user_age: integer
Duser_email: text, user_age: long
Attempts:
2 left
💡 Hint

Look at the match_mapping_type and the mapping type for each template.

🧠 Conceptual
intermediate
2:00remaining
Which dynamic template matches fields ending with '_id'?

Which dynamic template configuration will match any field name that ends with _id and map it as a keyword type?

A{ "match": "*_id", "mapping": { "type": "keyword" } }
B{ "match_pattern": "regex", "match": ".*_id$", "mapping": { "type": "keyword" } }
C{ "match": "_id", "mapping": { "type": "keyword" } }
D{ "match_pattern": "wildcard", "match": "*_id", "mapping": { "type": "keyword" } }
Attempts:
2 left
💡 Hint

Use match_pattern with regex to match field name endings.

🔧 Debug
advanced
2:00remaining
Why does this dynamic template cause a mapping error?

Consider this dynamic template snippet. Why will it cause an error when applied?

Elasticsearch
{
  "dynamic_templates": [
    {
      "strings_as_text": {
        "match_mapping_type": "string",
        "mapping": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        }
      }
    },
    {
      "strings_as_keyword": {
        "match": "*_id",
        "mapping": {
          "type": "keyword"
        }
      }
    }
  ]
}
AThe templates conflict because both match string fields, causing a mapping conflict error.
BThe first template's nested fields are not allowed inside dynamic templates.
CThe second template's match pattern is invalid because it uses '*' instead of '?' wildcard.
DThe second template uses wildcard match without specifying match_pattern, causing an error.
Attempts:
2 left
💡 Hint

Check if the wildcard pattern requires a special setting.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this dynamic template

What is the syntax error in this dynamic template snippet?

Elasticsearch
{
  "dynamic_templates": [
    {
      "template_1": {
        "match_mapping_type": "string",
        "mapping": {
          "type": "keyword"
        }
      }
    },
    {
      "template_2": {
        "match": "*_date",
        "mapping": {
          "type": "date"
        }
      }
    }
  ]
}
AThe second template uses wildcard match but lacks match_pattern specification.
BMissing comma after the first template object inside the array.
CThe mapping type 'date' is invalid in dynamic templates.
DThe dynamic_templates array must contain only one template object.
Attempts:
2 left
💡 Hint

Check the use of wildcards in match fields.

🚀 Application
expert
2:00remaining
How many fields will be mapped as 'text' in this dynamic template setup?

Given this dynamic template configuration, how many fields will be mapped as text if the document contains fields: title, description, user_id, created_at?

Elasticsearch
{
  "dynamic_templates": [
    {
      "strings_as_text": {
        "match_mapping_type": "string",
        "unmatch": "*_id",
        "mapping": {
          "type": "text"
        }
      }
    },
    {
      "ids_as_keyword": {
        "match": "*_id",
        "mapping": {
          "type": "keyword"
        }
      }
    },
    {
      "dates_as_date": {
        "match_mapping_type": "date",
        "mapping": {
          "type": "date"
        }
      }
    }
  ]
}
A1
B3
C2
D4
Attempts:
2 left
💡 Hint

Check which fields match each template and consider the unmatch clause.