首页 > 解决方案 > 更新 Elasticsearch 中现有字段的映射索引参数

问题描述

我有映射

{
  "test" : {
    "mappings" : {
      "properties" : {
        "description" : {
          "type" : "text"
        },
        "location" : {
          "type" : "keyword",
          "index" : false
        },
        "title" : {
          "type" : "text"
        }
      }
    }
  }
}

我想将该字段的index参数更新为locationtrue

我在尝试

PUT /test/_mapping
{
  
    "properties": {
        "location": { 
            "type": "keyword",
            "index": true
        }
    }
  
}

我得到

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Mapper for [location] conflicts with existing mapping:\n[mapper [location] has different [index] values]"}],"type":"illegal_argument_exception","reason":"Mapper for [location] conflicts with existing mapping:\n[mapper [location] has different [index] values]"},"status":400}

如何更新index参数?

标签: elasticsearchelasticsearch-mapping

解决方案


您要实现的目标称为破坏性更改或冲突性更改,这是不可能的,错误消息中也提到了这一点。

从索引文档中思考索引参数的作用以及为什么它会发生重大变化

index 选项控制字段值是否被索引。它接受真或假,默认为真。未编入索引的字段不可查询。

早期的索引值是false因为您现有的文档没有索引值并且不可查询,现在您更改为true哪个没有意义,因为您的早期文档将没有索引值,这就是它称为重大更改的原因。

您必须使用新的索引值创建一个新索引,并且可以为此使用reindex API


推荐阅读