【问题标题】:How to have not_analyzed for all new indexes by default?默认情况下如何对所有新索引进行 not_analyzed?
【发布时间】:2016-04-06 18:58:57
【问题描述】:

know 我可以使用dynamic_template 将字符串字段设置为not_analyzed,用于特定新索引中的新字段

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

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    是的,您可以通过在 * 上创建 index template_default_ mapping typedynamic templates 来实现此目的

    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_indexdummy_type 映射类型,您会看到name 字段将为not_analyzed

    【讨论】:

    • 如何在java客户端启动时在全新的弹性搜索中做到这一点?
    • @JayaAnanthram 如果您搜索[elasticsearch] java mapping,您会找到很多答案,例如stackoverflow.com/questions/23552845/…
    • 啊,这正是我要找的……宾果游戏!
    猜你喜欢
    • 2015-08-22
    • 2020-06-19
    • 2018-12-25
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 2021-12-10
    相关资源
    最近更新 更多