在Elasticsearch上将字段类型从文本迁移到关键字 [英] Migrate field type from text to keyword on Elasticsearch

查看:397
本文介绍了在Elasticsearch上将字段类型从文本迁移到关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想使用此命令将字段的类型从文本更改为关键字时:

When I want to change the type of a field from text to keyword with this commande :

PUT indexStat/_mapping/StatCateg
{
  "StatCateg":{
    "properties": {
      "nom_categorie": {
        "type":"keyword","index": true
      }
    }
  }
}

我收到此消息:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "mapper [nom_categorie] of different type, current_type [text], merged_type [keyword]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "mapper [nom_categorie] of different type, current_type [text], merged_type [keyword]"
  },
  "status": 400
}

推荐答案

好的,最后我在文档中看到无法更改字段的数据类型:

OK finaly i see in the doc that it's not possible to change data type of a field :

更新现有映射

Updating existing mappings

除了已记录的地方,现有的类型和字段映射不能 被更新.更改映射意味着已经失效 索引文件.相反,您应该使用 正确的映射,然后将数据重新索引到该索引中.

Other than where documented, existing type and field mappings cannot be updated. Changing the mapping would mean invalidating already indexed documents. Instead, you should create a new index with the correct mappings and reindex your data into that index.

所以唯一的解决方案是:

So the only solution is to :

  • 重新创建具有良好数据类型的新索引
  • 使用 Reindex API
  • 为数据重新编制索引
  • Recreate a new index with good data types
  • Reindex the data with the Reindex API

这篇关于在Elasticsearch上将字段类型从文本迁移到关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆