Search code examples
elasticsearch

How to update the effects of dynamic templates for existing indices in Elasticsearch


If I define a template with a specific setting I can then update that setting in all existing indices by PUTTING to the _settings subpath of the index.

How would I do the same for dynamic templates? That is, if I define a dynamic template, how would I reflect this change in all existing indices as if the dynamic template had been defined when the index was created?

This is my dynamic template:

{
  "index_patterns": [
    "eks-*"
  ],
  "mappings": {
    "dynamic_templates": [
      {
        "default_no_index": {
          "path_match": "^.*$",
          "path_unmatch": "^(@timestamp|auditID|level|stage|requestURI|sourceIPs|metadata|objectRef|user|verb)(\\..+)?$",
          "match_pattern": "regex",
          "mapping": {
            "index": false,
            "enabled": false
          }
        }
      }
    ]
  }
}

Elasticsearch verion: 7.1


Solution

  • A dynamic template specifies (part of) the mapping of your index, and you cannot change the mapping of an existing index (Elasticsearch Documentation | Mapping). This means that although you can update the (dynamic) mapping in your index template at any time, those changes will apply only to the new indices matching the template pattern.