elasticsearch es 索引重建

 

ElasticSearch索引重建

ElasticSearch索引一旦建立,便不可修改索引字段类型(允许增加或者删除该字段)

例如从Integer类型修改为long类型,这是不被允许的,错误信息如下:

复制代码
  {
    "error" : {
      "root_cause" : [
        {
          "type" : "illegal_argument_exception",
          "reason" : "mapper [age] cannot be changed from type [integer] to [long]"
        }
      ],
      "type" : "illegal_argument_exception",
     "reason" : "mapper [age] cannot be changed from type [integer] to [long]"
   },
   "status" : 400
 }
复制代码

因此,如果项目中有需求需要修改ElasticSearch的索引中字段的类型,则需要重建索引

以下介绍通过别名_aliase的方式实现不停机的重建ElasticSearch索引

前提:项目中使用的索引的别名,例如索引是index_user ,使用的是别名index_user_latest

索引重建的步骤:

step1: 创建新索引index_user_20210123并初始化映射关系,映射也就是包含了修改后的字段类型;

step2: 使用 _reindex 将原索引index_user中的数据,导入到新索引index_user_20210123;

step3: aliases actions修改别名: 将index_user的别名index_user_latest移除,index_user_20210123新增别名index_user_latest

以上便完成了修改字段类型的数据迁移

备注:

1.旧的索引index_user 可以删也可以不删

posted @   一个人的孤独自白  阅读(1435)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2020-09-16 phpstrom 取消创建一个文件自动就add提交到git
2017-09-16 Linux使用退格键时出现^H解决方法
2017-09-16 Linux centos7下php安装cphalcon扩展的方法
点击右上角即可分享
微信分享提示