默认情况下如何对所有新索引进行not_analyzed?

WoJ*_*WoJ 1 elasticsearch

知道我可以dynamic_template用来not_analyzed特定新索引中的新字段设置字符串字段.

有没有办法全局应用此设置- 即为not_analyzed任何新索引中的任何字符串字段设置属性?(无需为每个新索引设置它)

Val*_*Val 9

是的,你可以通过创建一个实现这个指标模板*有一个_default_映射类型动态模板

curl -XPUT localhost:9200/_template/global -d '{
  "template": "*",
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ]
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

然后,您可以在任何新索引中创建任何文档,并且所有字符串字段都将是 not_analyzed

curl -XPUT localhost:9200/dummy_index/dummy_type/1 -d '{"name": "dummy"}'
Run Code Online (Sandbox Code Playgroud)

如果检查dummy_type新创建的映射类型dummy_index,您将看到该name字段将是not_analyzed