【ElasticSearch】shards,replica,index之间的关系
作者:互联网
1.index 包含多个shard ,在创建index的时候可以自定义shards和replica的数量
例如: 新增一个index,手动指定shard和replica的数量
PUT demo_index { "settings": { "number_of_shards": 3, "number_of_replicas": 1 } }
添加完成后 GET demo_index 查询index的信息:
{ "demo_index" : { "aliases" : { }, "mappings" : { }, "settings" : { "index" : { "creation_date" : "1612777182130", "number_of_shards" : "3", "number_of_replicas" : "1", "uuid" : "JxC0KweOTZ-eYpLqM2uHXQ", "version" : { "created" : "7060099" }, "provided_name" : "demo_index" } } } }
ES7之前默认是5个shard,每1个shard都有1个replica
ES7及之后默认是1个shard,每1个shard都有一个replica
2.每个shard都是最小的工作单元,承载部分数据,lucene实例,完成的建立索引和处理请求的能力
3.增减节点时,shard会自动在nodes中负载均衡
4.primary shard和replica shard,每个document肯定只存在于某一个primary shard以及其对应的replica shard中,不可能存在于多个primary shard
5.replica shard是primary shard的副本,负责容错,以及承担读请求负载
6.primary shard的数量在创建索引的时候就固定了,replica shard的数量可以随时修改
修改副分片的数量
PUT demo_index/_settings { "number_of_replicas":2 }
修改主分片的数量(报错)
PUT demo_index/_settings { "number_of_replicas":2 }
错误信息如下:
{ "error" : { "root_cause" : [ { "type" : "illegal_argument_exception", "reason" : "Can't update non dynamic settings [[index.number_of_shards]] for open indices [[demo_index/JxC0KweOTZ-eYpLqM2uHXQ]]" } ], "type" : "illegal_argument_exception", "reason" : "Can't update non dynamic settings [[index.number_of_shards]] for open indices [[demo_index/JxC0KweOTZ-eYpLqM2uHXQ]]" }, "status" : 400 }
7.primary shard的默认数量是5,replica默认是1,默认有10个shard,5个primary shard,5个replica shard(ES7之前是这样,参考第一点)
8.primary shard不能和自己的replica shard放在同一个节点上(否则节点宕机,primary shard和副本都丢失,起不到容错的作用),但是可以和其他primary shard的replica shard放在同一个节点上
标签:index,shards,demo,number,primary,replica,shard 来源: https://www.cnblogs.com/july-sunny/p/14389832.html