Search code examples
regexelasticsearchkibana

Elasticsearch dynamic template with regex fails to work


I'm trying to create dynamic template which aim is to change data type of all fields inside index according to regular expression /(fields.Account.*[a-zA-Z0-9_])/ig. Meaning template should filter all the field names containing fields.Account and change their datatype to text. However the dynamic template below makes no intended impact at all.

`[
  {
    "Account": {
      "match_pattern": "regex",
      "mapping": {
        "type": "text"
      },
      "match_mapping_type": "*",
      "match": "/(fields.Account.*[a-zA-Z0-9_])/ig"
    }
  }
]`

I definitely miss something. Please help me to find out what exactly.

I tried to play with different expressions but with no success


Solution

  • match only operates on the final field name, not on nested fields.

    You should use path_match instead:

    [
      {
        "Account": {
          "path_match": "fields.Account.*",
          "mapping": {
            "type": "text"
          }
        }
      }
    ]