elasticsearch关于索引切分的实现
【背景信息】
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
elasticsearch关于索引切分的实现的更多相关文章
- ElasticSearch+Kibana 索引操作
ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...
- ES 10 - Elasticsearch的索引别名和索引模板
目录 1 索引模板概述 1.1 什么是索引模板 1.2 索引模板中的内容 1.3 索引模板的用途 2 创建索引模板 3 查看索引模板 4 删除索引模板 5 模板的使用建议 5.1 一个index中不能 ...
- elasticsearch的索引操作和文档操作总结
参考文档:https://es.xiaoleilu.com/010_Intro/00_README.html 一.索引操作 1.查看当前节点的所有的index 查看当前节点的所有的index [roo ...
- elasticsearch的索引自动清理及自定义清理
近发现elasticsearch近期索引文件大的吓人,清理了下之前的索引文件,发现服务器性能大大的减轻了一半,想一直保留近一个月的索引文件,但是又不想每个月手动清楚,在此写了一个小脚本 查询索引: c ...
- ELK学习笔记之ElasticSearch的索引详解
0x00 ElasticSearch的索引和MySQL的索引方式对比 Elasticsearch是通过Lucene的倒排索引技术实现比关系型数据库更快的过滤.特别是它对多条件的过滤支持非常好,比如年龄 ...
- elasticsearch删除索引报错【原】
如果elasticsearch删除索引报错 curl -X DELETE 'http://10.73.26.66:9200/httpd-34-2017.08.15' {"error" ...
- Spring Boot + Elasticsearch 实现索引的日常维护
全文检索的应用越来越广泛,几乎成了互联网应用的标配,商品搜索.日志分析.历史数据归档等等,各种场景都会涉及到大批量的数据,在全文检索方面,方案无外乎Lucene.Solr.Elasticsearch三 ...
- Spring Boot + Elasticsearch 实现索引批量写入
在使用Eleasticsearch进行索引维护的过程中,如果你的应用场景需要频繁的大批量的索引写入,再使用上篇中提到的维护方法的话显然效率是低下的,此时推荐使用bulkIndex来提升效率.批写入数据 ...
- 数组如何在ElasticSearch中索引
一.简介 在ElasticSearch里没有专门的数组类型,任何一个字段都可以有零个和多个值.当字段值的个数大于1时,字段类型就变成了数组. 下面以视频数据为例,介绍ElasticSearch如何索引 ...
随机推荐
- iOS开发之NSUserDefaults
在ios中偏好设置保存用户配置的对象 //NSUserDefaults读取 //获取标准函数对象 //通过对象获取名称下NSMutableDictionary数据 NSUserDefaults *de ...
- GRUB2 分析 (一)
GRUB是目前较流行启动引导程序.其第二版被主流Linux发行版所包括.本文将探索和分析GRUB的设计和实现机制. boot.S是第一个研究对象,因为boot.S将被编译成boot.img(512字节 ...
- 虚拟中没有eth0
进行虚拟机的软拷贝和硬拷贝,或直接从一台机器上拷贝虚拟机硬盘文件到另一台机子的虚拟机上时,发现通过修改/etc/network/interfaces配置的IP没用,输入ifconfig,发现根本就没有 ...
- CSS Backgrounds(背景)
CSS Backgrounds(背景) CSS 背景属性用于定义HTML元素的背景. CSS 属性定义背景效果: background-color background-image backgroun ...
- 运行bat时隐藏cmd窗口
运行bat时隐藏cmd窗口 新建一个shrjj.vbs文件,文件内容为: Set ws = CreateObject("Wscript.Shell") ws.run "c ...
- Python3.6 安装、后续终端pip 安装模块命令
1. 下载安装包 https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe 2. 安装python3.6 增加环境变量(打钩.红框很 ...
- How to Enable RPMForge Repository in RHEL/CentOS 7.x/6.x/5.x
RPMforge repository is a utility that is used to install third party software packages under Red Hat ...
- MySQL 删除重复记录
==========A really easy way to do this is to add a UNIQUE index on the 3 columns. When you write the ...
- LeetCode——Longest Repeating Character Replacement
1. Question Given a string that consists of only uppercase English letters, you can replace any lett ...
- 商品详情页,banner滚动点击加载效果,js,jquary
<script language="javascript"> $(document).ready(function () { //purchase ...