Elasticsearch Split和shrink API

2023-11-16

背景:

尝试解决如下问题:单分片存在过多文档,超过lucene限制

 

分析

1.一般为日志数据或者OLAP数据,直接删除索引重建

2.尝试保留索引,生成新索引

  - 数据写入新索引,查询时候包含 old_index,new_index

3.尝试split

split index API

如果需要将当前index的primary shard数量增加时,可以使用split index api。

会生成一个新index,但会保留原来的index。

步骤:

确保source index只读

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

spilt API修改primary shard数量

POST source_index/_split/new_index
{
  "settings": {
    "index.number_of_shards": 10
  }
}

监控执行进度

GET _cat/recovery/new_index

测试

版本 7.17.5

# 新建测试索引
PUT test_split
{
  
}

# 关闭source索引的写入
PUT /test_split/_settings
{
  "settings": {
    "index.blocks.write": true 
  }
}

# 执行split API
POST /test_split/_split/test_split_new
{
  "settings": {
    "index.number_of_shards": 12
  }
}

遇到报错并解决,在split API执行阶段:

1. source 索引必须是 read-only 的

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_state_exception",
        "reason": "index test_split must be read-only to resize index. use \"index.blocks.write=true\""
      }
    ],
    "type": "illegal_state_exception",
    "reason": "index test_split must be read-only to resize index. use \"index.blocks.write=true\""
  },
  "status": 500
}



2. source分片数(3)必须是target分片数的因子(所以target不能为11,可以为12)

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "the number of source shards [3] must be a factor of [11]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "the number of source shards [3] must be a factor of [11]"
  },
  "status": 400
}




应用

集群版本 6.8.5

设置source索引 "index.blocks.write": true 之后,执行split API异常:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[es-log-all-2][10.xx.x.xx:9300][indices:admin/resize]"
      }
    ],
    "type": "illegal_state_exception",
    "reason": "the number of routing shards [5] must be a multiple of the target shards [20]"
  },
  "status": 500
}

即:目标索引的主分片个数必须是index.number_of_routing_shards的因数;

注意:number_of_routing_shards 不可以动态修改

结论:ES6.8无法通过split API解决索引分片过少的问题

官方doc:Split index API | Elasticsearch Guide [8.9] | Elastic

Shrink index API

如果需要将当前index的primary shard数量减少时,可以使用shrink index api。

会生成一个新index,但会保留原来的index。

(Shrinks an existing index into a new index with fewer primary shards.)

POST /my-index-000001/_shrink/shrunk-my-index-000001

步骤

# 新建index
PUT test_shrink
{
  
}

# 查看索引的shard在哪些node
GET _cat/shards/test_shrink?v

# 将所有主分片分配到node1,副本设置为0,设置readOnly
PUT test_shrink/_settings
{
  "settings": {
    "index.number_of_replicas": 0,
    "index.routing.allocation.require._name": "node-es-0",
    "index.blocks.write": true
  }
}

# 执行shrink API
POST /test_shrink/_shrink/new_test_shrink
{
  "settings": {
    "index.number_of_replicas": 1,
    "index.number_of_shards": 1, 
    "index.codec": "best_compression" 
  },
  "aliases": {
    "my_search_indices": {}
  }
}

如果上述命令修改成:

POST /test_shrink/_shrink/new_test_shrink
{
  "settings": {
    "index.number_of_replicas": 1,
    "index.number_of_shards": 2, 
    "index.codec": "best_compression" 
  },
  "aliases": {
    "my_search_indices": {}
  }
}

新的number_of_shards不是source index的number_of_shards的因子,那么出现如下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "the number of source shards [3] must be a multiple of [2]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "the number of source shards [3] must be a multiple of [2]"
  },
  "status": 400
}

官方doc:Shrink index API | Elasticsearch Guide [8.9] | Elastic

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Elasticsearch Split和shrink API 的相关文章

随机推荐

  • 2023 前端一场面试及答案整理

    金三马上就要开始了 俗话说得好 知己知彼百战百胜 多准备总是没有错的 以面试的形式和大家一起学习 一起回顾我们的职场生涯 今天简单总结一下我个人去面试 包括我在面试别人时的经验 加油加加油 目录 开头热场问题 1 说一下工作中解决过比较困难
  • 解决TortoiseGit每次Pull或者Push都需要输用户名密码的问题

    解决TortoiseGit每次Pull或者Push都需要输用户名密码的问题 每次提交代码到仓库都要输入用户名和密码 王同学差点哭了 忍住 忍住 不能哭 不能哭 解决方法如下 Right click TortoiseGit Settings
  • Linux 进程间通信之管道

    进程之间的通讯之管道 目录 1 无名管道 2 有名管道 3 管道读写规则 1 无名管道 管道是一种最基本的IPC机制 作用于父子进程之间 完成数据传递 管道有以下特性 1 其本质是一个伪文件 实为内核缓冲区 其本质是一个伪文件 实为内核缓冲
  • Vue 快速删除

    Vue 快速删除nodejs配置的快速删除node modules 删除文件夹及文件 cnpm i rimraf g 这个需要cmd管理员命令运行 删除文件及文件夹 rimraf f node modules
  • 微信小程序Markdonw、HTML富文本内容显示解决办法

    Towxml Towxml 是一个可将HTML markdown转换为WXML WeiXin Markup Language 的渲染库 由于微信小程序不能直接渲染HTML 因此富文本编辑器生成的HTML内容无法直接在小程序中展示 可能是出于
  • HTML网页入门之注释怎么写

    HTML网页入门之注释怎么写 为了增强网页的可读性注释是必不可少的 下面我们就来谈一谈 HTML网页的注释应该怎么写 HTML注释的作用 1 用注释的内容不会显示在浏览器中 注释标签用于在源代码中插入注释 注释的内容不会显示在浏览器中 对关
  • GoogLeNet网络详解与模型搭建

    文章目录 1 模型介绍 2 GoogLeNet详解 Inception模块 辅助分类器 3 GoogLeNet网络结构 4 Pytorch模型搭建代码 1 模型介绍 GoogLeNet是2014年Christian Szegedy等人在20
  • qmake source code 解读

    qmake 主要框架流程 qmake的主要功能执行入口在main cpp中的runQMake int argc char argv 中 其主要框架流程如下 runQMake int argc char argv QMakeVfs vfs 初
  • 2023Python该怎么学?我用这14张学习路线图,直观的告诉你

    我知道对于绝大多数的人来说 学习编程的第一目的其实就是想找一份有发展前景 并且薪资待遇还不错的工作 那么肯定是哪个编程语言的就业前景好 就越值得学习 Python作为当下最热的一门编程语言 刚好就符合这个条件 所以对于绝大部分人来说Pyth
  • java基于寄存器_基于栈的指令集与基于寄存器的指令集的区别,JVM指令集实例...

    现代JVM在执行Java代码的时候 通常都会将解释执行与编译执行两者结合起来 所谓解释执行 就是通过解释器来读取字节码 遇到相应的指令就去执行该指令 所谓编译执行 就是通过即时编译器 Just In Time JIT 将字节码转为本地机器码
  • 玩转ChatGPT:Custom instructions (vol. 1)

    一 写在前面 据说GPT 4又被削了 前几天让TA改代码 来来回回好几次才成功 可以看到之前3小时25条的限制 现在改成了3小时50条 可不可以理解为 以前一个指令能完成的任务 现在得两条指令 可能作为补偿 OpenAI对于Plus用户开放
  • 兼容和适配的区别

    兼容测试是app能否在不同品牌的手机上进行安装卸载等测试 适配测试是app能否在不同尺寸 不同分辨率的终端上能否正常显示的测试 转载于 https www cnblogs com bubutianshu p 11263395 html
  • 如何高逼格的写java代码

    记录一些了解的高逼格 好用的java代码 欢迎大家补充 共同学习 1 函数式接口 FunctionalInterface 好处 高逼格 代码收拢 解藕 统一处理 适用范围 具有共性的接口调用代码 举个栗子 在我们平时的微服务开发中 调用其他
  • vue计时器代码和倒计时代码

    计时器
  • Spring MVC拦截器和跨域请求

    一 拦截器简介 SpringMVC的拦截器 Interceptor 也是AOP思想的一种实现方式 它与Servlet的过滤器 Filter 功能类似 主要用于拦截用户的请求并做相应的处理 通常应用在权限验证 记录请求信息的日志 判断用户是否
  • easyui 获取并设置当前时间

    得到当前日期 formatterDate function date type var day date getDate gt 9 date getDate 0 date getDate var month date getMonth 1
  • Java基础复习之类与对象、封装、构造方法、String类

    个人觉得重点的部分会用彩色标出 面向对象思想 1 面向对象思想概述 面向过程思想 遇到一个问题 一步一步的去解决他 强调的是过程 典型代表语言是C语言 面向对象思想 遇到一个问题 找一个可以解决问题的对象 可以是人 也可以是别的 强调是对象
  • Windows7下IPV6设置方法详解

    Windows 7下配置IPV6的方法和Vista基本类似 需要注意的是 鉴于各个校园或其他场所的网络配置环境不同 如果按如下方法配置不成功可以进一步咨询相关网络管理人员 或重新选择连网客户端 下面来看具体的两个设置方法吧 步骤 方法 方法
  • %c与%s的区别与划分

    字符和字符串 c格式对应的是单个字符 s格式对应的是字符串 include
  • Elasticsearch Split和shrink API

    背景 尝试解决如下问题 单分片存在过多文档 超过lucene限制 分析 1 一般为日志数据或者OLAP数据 直接删除索引重建 2 尝试保留索引 生成新索引 数据写入新索引 查询时候包含 old index new index 3 尝试spl