Given the following dynamic template in an Elasticsearch index mapping, what will be the data type of fields named user_email and user_age?
{
"mappings": {
"dynamic_templates": [
{
"strings_as_keywords": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
},
{
"integers_as_long": {
"match_mapping_type": "long",
"mapping": {
"type": "long"
}
}
}
]
}
}Look at the match_mapping_type and the mapping type for each template.
The dynamic template matches string fields and maps them as keyword. It matches long fields and maps them as long. So user_email (a string) becomes keyword and user_age (a long) becomes long.
Which dynamic template configuration will match any field name that ends with _id and map it as a keyword type?
Use match_pattern with regex to match field name endings.
To match fields ending with _id, you need a regex pattern .*_id$ and specify match_pattern": "regex". Option B correctly uses this.
Consider this dynamic template snippet. Why will it cause an error when applied?
{
"dynamic_templates": [
{
"strings_as_text": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
},
{
"strings_as_keyword": {
"match": "*_id",
"mapping": {
"type": "keyword"
}
}
}
]
}Check if the wildcard pattern requires a special setting.
When using wildcards in match, you must specify match_pattern": "wildcard". Without it, the pattern is treated as a literal string, causing an error.
What is the syntax error in this dynamic template snippet?
{
"dynamic_templates": [
{
"template_1": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
},
{
"template_2": {
"match": "*_date",
"mapping": {
"type": "date"
}
}
}
]
}Check the use of wildcards in match fields.
When using wildcards in match, you must specify match_pattern": "wildcard". Without it, the pattern is treated literally, causing the template not to match as expected.
Given this dynamic template configuration, how many fields will be mapped as text if the document contains fields: title, description, user_id, created_at?
{
"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"
}
}
}
]
}Check which fields match each template and consider the unmatch clause.
Fields title and description are strings and do not end with _id, so they match the first template and become text. user_id matches the second template and becomes keyword. created_at matches the third template as date. So only 2 fields are mapped as text.