【背景信息】

ES一直以来对于已经创建好的索引的分片是不可以进行分割的,简单的说,当你创建了一个索引,并指定了number_of_shards为2,当随着数据量的不断增大,是无法将索引的shard扩充为4个或者8个的,当然,你可以通过重新创建索引,这个的前提是你的数据关联性并不大,业务上允许出现多个索引存在的场景。

在ES6.1版本之后,支持了索引shard的切分,与其说是支持了切分,不如说是提供了一个接口,将原有的数据可以快速复制到新的索引下,并保持数据结构的不变,仅仅是增加了索引分片。

【使用前提】

  • 使用该功能的前提是ES版本必须升级至6.1之后的版本。
  • 集群状态为green。
  • 磁盘空间允许复制一份新的索引数据。
  • 在使用前,索引配置中必须配置number_of_routing_shards。
  • 重新分片后的索引是不存在的
  • 重新分配后的shard数必须是number_of_routing_shards的因数,同时是number_of_shards的倍数,简单说,如果指定了number_of_routing_shards为10,number_of_shards为2,则你的增加shard的情况就有了2 → 10 (split by 5)

【功能验证】

首先,创建索引test_split_index,并指定number_of_shards为2,number_of_routing_shards为10,由于单节点集群,因此指定number_of_replicas为0,保证集群状态为green。

curl -XPUT localhost:9200/test_split_index -H 'Content-Type: application/json' -d '
{
"settings": {
"index.number_of_shards" : 2,
"index.number_of_routing_shards" : 10,
"index.number_of_replicas": 0
}
}
'

插入数据

curl -XPOST localhost:9200/test_split_index/split_index/_bulk?pretty -H 'Content-Type: application/json' -d '
{ "index": {}}
{ "user":"zhangsan", "age":"12"}
{ "index": {}}
{ "user":"lisi", "age":"25"}
{ "index": {}}
{ "user":"wangwu", "age":"21"}
{ "index": {}}
{ "user":"zhaoliu", "age":"16"}
{ "index": {}}
{ "user":"sunjiu", "age":"40"}
'

由于在切分过程中,避免有数据写入,因此,需要先关闭写数据的写入。

关闭索引
curl -XPOST localhost:9200/test_split_index/_close

防止在切分过程中有数据写入
curl -XPUT 'localhost:9200/test_split_index/_settings?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"index.blocks.write": true
}
}
'

打开索引
curl -XPOST localhost:9200/test_split_index/_open

进行数据的shard的切分。

curl -XPOST 'localhost:9200/test_split_index/_split/split_index_target?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"index.number_of_shards": 10
}
}
'

你就会发现在数据目录下,多出了一个新的索引,通过查询数据,和原索引下的数据是一致的。

参考链接:

https://www.elastic.co/guide/en/elasticsearch/reference/6.x/indices-split-index.html

最新文章

  1. 统计iOS项目的总代码行数的方法
  2. Windows 10 LTSB
  3. 实现服务器端与客户端的实时通信 SignalR(1)
  4. Linux 内核同步机制
  5. Large-Scale Deployment of SharePoint Team Services
  6. iOS 深入理解RunLoop
  7. 【转】 .NET中STAThread和MTAThread
  8. 基于jQuery的上下无缝滚动应用(单行或多行)
  9. B. Gerald is into Art
  10. 【转】分享JavaScript监听全部Ajax请求事件的方法
  11. shell脚本解压多个jar包
  12. Build Assimp library for Android
  13. Docker 简单部署 ElasticSearch
  14. 平方根的C语言实现(一) —— 浮点数的存储
  15. web font
  16. 《jQuery精品教程视频》-每天的复习笔记
  17. poi操作Excel的封装类
  18. scala学习笔记-面向对象编程之Trait
  19. Palindrome Number leetcode java
  20. BZOJ 2330 糖果 差分约束求最小值

热门文章

  1. IDEA 2018.2破解
  2. 设置HTML5的video播放速度
  3. 在python3下使用OpenCV 抓取摄像头图像并实时显示3色直方图
  4. MVC 中的家常事
  5. DATETIME与TIMESTAMP
  6. 学号20145303 《Java程序设计》第一周学习总结
  7. Tomcat热部署,Web工程中线程没有终止
  8. 重新想,重新看——CSS3变形,过渡与动画④
  9. python-集合、字典
  10. iOS开发值得学习的Demo