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

问题描述 投票:0回答:1

我试图使用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上测试它。

elasticsearch elasticsearch-5
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.