【问题标题】:Create ElasticSearch dynamic template to ensure all fields are set to not_analyzed创建 ElasticSearch 动态模板以确保所有字段都设置为 not_analyzed
【发布时间】:2015-07-10 08:12:21
【问题描述】:

我有一个 ElasticSearch 类型,我希望为其动态设置映射。我要分析该类型的一些选择字段,但其他所有内容都应设置为“not_analyzed”。

我想出了以下 sn-p。这会将所有 string 字段设置为不被分析,但不涵盖所有其他数据类型。我尝试使用文档中显示的“通用”字段,但没有帮助。谁能告诉我如何做到这一点?

{
  "TypeName": {
    "dynamic_templates": [
      {
        "template_name": {
          "match": "*",
          "match_mapping_type": "string",
          "mapping": {
            "index": "no",
            "type": "string"
          }
        }
      }
    ],
    "dynamic": true,
    "properties": {
      "url": {
        "index": "analyzed",
        "type": "string"
      },
      "resourceUrl": {
        "index": "analyzed",
        "type": "string"
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:
    {
      "mappings": {
        "TypeName": {
          "dynamic_templates": [
            {
              "base": {
                "mapping": {
                  "index": "not_analyzed"
                },
                "match": "*",
                "match_mapping_type": "*"
              }
            }
          ],
          "dynamic": true,
          "properties": {
            "url": {
              "index": "analyzed",
              "type": "string"
            },
            "resourceUrl": {
              "index": "analyzed",
              "type": "string"
            }
          }
        }
      }
    }
    

    整体,索引级模板:

    {
      "mappings": {
        "_default_": {
          "dynamic_templates": [
            {
              "base": {
                "mapping": {
                  "index": "not_analyzed"
                },
                "match": "*",
                "match_mapping_type": "*"
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

    • 感谢您的建议,但似乎没有用。其他所有字符串字段仍在分析中。
    • 您是否定义了其他模板?
    • 没有其他模板。我试图解决的问题是我将大量数据推送到 ElasticSearch 中,如果它尝试分析所有字段,则会引发错误。
    • 那是不可能的。该模板可以捕获除url 和resourceUrl 之外的所有内容。因此,除非您有另一个模板优先于上面定义的匹配类型test 的模板,否则这是不可能的。
    • 那么你需要索引级模板。已更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多