【问题标题】:Can an elastic search index template define a default type for fields, and allow overriding specific fields only?弹性搜索索引模板能否定义字段的默认类型,并仅允许覆盖特定字段?
【发布时间】:2019-09-05 20:42:25
【问题描述】:

我正在映射传递的文档中的所有字段,但有时弹性搜索的动态字段映射类型检测会为包含纯文本的字段选择非常严格的类型(如long)。这似乎是基于 ES 收到的包含该字段的初始文档。例如:

文档 1:

{
  "a": 1,
  "b": "foo",
  "c": {
    "nested": 5.5
  }
}

文档 2:

{
  "a": "plain text",
  "b": "bar",
  "c": {
    "nested": "plain text again"
  }
}

我能否定义一个索引模板,使所有值默认索引为text,并且仅在我明确想要这样做时才索引为其他类型?

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    Elasticsearch 允许自定义动态映射规则。 例如,您可以定义将long 映射到text 的规则:

    {
      "mappings": {
        "dynamic_templates": [
          {
            "long_to_text": {
              "match_mapping_type": "long",
              "mapping": {
                "type": "text"
              }
            }
          }
        ]
    }
    

    更多细节可以在文档中找到:https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html

    【讨论】:

    • 我发现动态模板的路径匹配选项非常有用,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多