当前位置: 首页 > news >正文

elsticsearch 通过reindex修改shards

elasticsearch reindex 索引。

背景:

索引test1 reindex到test2 修改sharding数量
程序是通过别名test1_alias访问索引

1、创建目标索引test2

索引需要手动提前创建自动创建可能会有mapping 不一致性的风险。

The destination should be configured as wanted before calling _reindex. Reindex does not copy the settings from the source or its associated template.

Mappings, shard counts, replicas, and so on must be configured ahead of time.

复制test1的创建索引语句,修改sharding数量,

GET test1 查看索引

去掉下面test1属性的部分。

  "test1" : {
    "aliases" : {
      "test1_alias" : { }
    },

         "provided_name" : "test1",
        "creation_date" : "1742388051938",

        , #注意前面的","号也要去掉,因为处于底部
        "uuid" : "LG30E6iGSPu-09Ca5nGbPQ",
        "version" : {
          "created" : "6070099"
        }

PUT test2 创建索引
修改后的json文件
“number_of_shards” : 修改到目标数量
执行命令返回的数据

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "test2"
}

2、禁止源索引test1 写

防止reindex期间写入数据,无法同步到目标索引

PUT /test1/_settings
{
  "index.blocks.write": true
}

对应放开写的命令

PUT /test1/_settings
{
  "index.blocks.write": false
}

3、 执行reindex 命令

POST _reindex?wait_for_completion=false&requests_per_second=1000
{
  "source": {
    "index": "test1"
  },
  "dest": {
    "index": "test2"
  }
}

返回信息

{
  "task" : "KsO_WIvXRC2ccMCCxbuF3w:28779984"
}

wait_for_completion=false 后台执行命令,requests_per_second=500限制速度500

调整同步速度命令:
POST _reindex/KsO_WIvXRC2ccMCCxbuF3w:28779984/_rethrottle?requests_per_second=500
取消任务命令
POST _tasks/KsO_WIvXRC2ccMCCxbuF3w:28779984/_cancel
查看reindex任务
GET _tasks?actions=*reindex&detailed

4、 查看任务是否完成

GET _tasks/KsO_WIvXRC2ccMCCxbuF3w:28779984

返回 true的时候就是完成了reindx
“completed” : true

5、修改别名指向新的索引别名

test1_alias指向test2

POST _aliases
{
  "actions": [
    { "remove": { "index": "test1", "alias": "test1_alias" } },
    { "add": { "index": "test2", "alias": "test1_alias" } }
  ]
}
6、查看别名
GET test2

删除原来的索引(可以保留归档)

DELETE test1

加速执行速度的方法
1、增加size 默认1000

POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "test1",
    "size": 5000
  },
  "dest": {
    "index": "test2"
  }
}

2、副本改成0

PUT /test2/_settings
{
    "number_of_replicas": 0
}

3、禁止自动刷新

PUT /test2/_settings
{ "refresh_interval": -1 }

4、提高scroll的并行度


POST _reindex?slices=5&refresh

参考文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

https://blog.csdn.net/wwd0501/article/details/132192692

相关文章:

  • 使用crash解析vmcore(fulldump)文件,基于qemu,arm64,linux6.6
  • 社区医疗管理系统基于Spring Boot SSM
  • Trae如何使用插件Mybatis Log MybatisX转换SQL语句?
  • 分裂层次聚类算法:从原理到实战的全方位解析
  • Java-模块一
  • Controller/RestController的区别
  • 支持多个和可选参数
  • 【WPF】c#读取CAD的dxf文件,并基于Canvas将读取到的数据重新描绘到界面
  • Unity URP 实现场景和UI添加后处理
  • Java 反射详细教程
  • 数据可视化(matplotlib)-------辅助图标的设置
  • 早餐 3.20
  • 笔记:代码随想录算法训练营day57:99.岛屿数量 深搜、岛屿数量 广搜、100.岛屿的最大面积
  • ssh连接解析时间过长如何解决
  • 模块、包和库
  • 【day16】搭建测试环境数据库
  • uni-app基础问题(一)
  • SysOM 可观测体系建设(一):万字长文解读低开销、高精度性能剖析工具livetrace
  • Linux线程操作(创建,终止,等待,分离)
  • 基于STM32电子钟闹钟数码管显示设计(Proteus仿真+程序+设计报告+原理图PCB+讲解视频)
  • 专访|《内沙》导演杨弋枢:挽留终将失去的美好
  • 圆桌丨全球化博弈与人工智能背景下,企业如何落地合规体系
  • 湖南慈利一村干部用AI生成通知并擅自发布,乡纪委立案
  • 坚决打好产业生态培育攻坚战!陈吉宁调研奉贤区
  • 海昏侯博物馆展览上新,“西汉帝陵文化展”将持续展出3个月
  • 韩正会见美国景顺集团董事会主席瓦格纳