小编典典

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

elasticsearch

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

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


阅读 294

收藏
2020-06-22

共1个答案

小编典典

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

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

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

curl -XPUT localhost:9200/dummy_index/dummy_type/1 -d '{"name": "dummy"}'

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

2020-06-22