如何使用 `regex` 类型的 `match_pattern` 来定义 elasticsearch 动态模板

How do I use a `match_pattern` of type `regex` to define an elasticsearch dynamic template

我正在尝试使用 regex 来匹配各种 id 字段,例如 collection_id,这样它们就不会被分析。

简单的正则表达式 ^.*_id$ 无法匹配字段。

{
  "_default_": {
      "dynamic_templates": [
        {
          "system_ids": {
            "match_mapping_type": "string",
            "match_pattern": "regex",
            "match": "^.*_id$",
            "mapping": {
              "type": "keyword"
            }
         }
       }
    ]
  }
}

我正在 elasticsearch 5.5 上测试这个。

经过大量试验和错误后,发现您需要将正则表达式添加到捕获组。 使用 ^(.*_id)$ 作为 match 工作。我不知道为什么,但确实如此。