【问题标题】:Do I need to reindex all older documents forcefully when mapping of any NON-INDEXED field is changed?更改任何 NON-INDEXED 字段的映射时,是否需要强制重新索引所有旧文档?
【发布时间】:2020-10-31 13:20:02
【问题描述】:

我的弹性搜索中有以下映射

"properties": {
  "id": {
    "type": "string",
    "index": "not_analyzed"
  },
  "tag": {
    "type": "long"
  },
  "level": {
    "type": "integer"
  },
  "fieldIn": {
    "type": "long",
    "index": "no"
  },
  "fieldOut": {
    "type": "long",
    "index": "no"
  },
  
}

我需要将 fieldIn/fieldOut 的数据类型更改为 String。由于它是非索引的,我是否需要强制重新索引所有旧文档

【问题讨论】:

标签: elasticsearch indexing


【解决方案1】:

您正在更改现有字段的数据类型,这是一项重大更改,Elastic 不允许这样做,请按照我创建的示例向您展示 ES 将把你的案子扔进去。

使用长字段创建索引映射:

{
  "mappings": {
    "mytype": {
      "properties": {
        "fieldOut": {
          "type": "long",
          "index": "no"
        }
      }
    }
  }
}

包含长值的索引文档

{
 "fieldOut" :14897594242
}

{
 "fieldOut" :112343434534
}

** 尝试使用put aka update mapping APIfieldOut 更改为字符串**

{
  "mytype": {
    "properties": {
      "fieldOut": {
        "type": "string", // note changed to string type
        "index": "no"
      }
    }
  }
}

这导致以下异常:

{ "error": "MergeMappingException[Merge failed with failures {[mapper [fieldOut] of different type, current_type [long], 合并类型 [字符串]]}]", “状态”:400 }

【讨论】:

    猜你喜欢
    • 2014-05-29
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 2020-11-24
    相关资源
    最近更新 更多