Regex Pattern Field Names
My document contains
- various date-time fields names
*Timeand*At—shipmentTime,createdAtetc. - boolean fields of the form
is_*—is_premium,is_companyetc. - other fields that I all want to declare as
keywords.
How can I auto-generate mappings for these 3 field varieties?
This technique is especially powerful when combined with Mapping Automation strategies and becomes crucial when indexing in bulk where manual field definition would be impractical.
You already know you should be utilizing match_mapping_type along with match and/or unmatch so you may be tempted to use
PUT myindex
{
"mappings": {
"dynamic_templates": [
{
"justKeywords": {
"match_mapping_type": "*",
"unmatch": [
"*Time",
"*At",
"is_*"
],
"mapping": {
"type": "keyword"
}
}
},
...
]
}
}
That's not going to work because unmatch can only be a pattern string, not an array thereof.
Use match instead and order the templates from the most specific restriction to the least: