Regex Pattern Field Names

Spatialized founder Jozef Sorocin
Jozef Soročin
Book a consultation ↗
2 min read  •  Updated 07/13/2025

My document contains

  • various date-time fields names *Time and *AtshipmentTime, createdAt etc.
  • boolean fields of the form is_*is_premium, is_company etc.
  • 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:

Join 200+ developers who've mastered this! Get Lifetime Access — $5
Already a member? Sign in here