弹性搜索索引模板是否可以为字段定义默认类型,并且只允许覆盖特定字段?

问题描述 投票:2回答:1

我正在映射传递文档中的所有字段,但偶尔弹性搜索的动态字段映射类型检测会为包含纯文本的字段选择非常严格的类型(如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个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.