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放在同一個節點上
