索引分裂spitting操作

索引分裂可以将一个索引分裂为一个有更多分片的新索引

用法

POST /<index>/_split/<target-index>

PUT /<index>/_split/<target-index>

新索引的分片必须是原先索引分片数的整数倍,同时必须是原先索引配置项  index.number_of_routing_shards 整数倍。

示例

原索引   index.number_of_shards=5, index.number_of_routing_shards=30  

curl --location --request POST "http://localhost:9200/my-index-000001/_split/split-my-index-000001" \
--header "Content-Type: application/json" \
--data-raw "{
  \"settings\": {
    \"index.number_of_shards\": 20
  }
}"

会报错: 由于原先索引的配置  index.number_of_routing_shards=30 , 不是目标索引配置  index.number_of_shards=20  的整数倍

the number of routing shards [30] must be a multiple of the target shards [20]

目标索引的分片数不能大于 原索引 配置为 index.number_of_routing_shards=30   时,若目标索引  index.number_of_shards  设置为60时,也会报错

the number of routing shards [30] must be a multiple of the target shards [60]

 

更改  index.number_of_shards=30或 15 后,成功分片

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "split-my-index-000001"
}

查看新索引信息

curl --location --request GET "http://localhost:9200/split-my-index-000001/_settings"
{
    "split-my-index-000001": {
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        },
                        "initial_recovery": {
                            "_id": null
                        }
                    }
                },
                "number_of_shards": "30",
                "routing_partition_size": "1",
                "blocks": {
                    "write": "true"
                },
                "provided_name": "split-my-index-000001",
                "resize": {
                    "source": {
                        "name": "my-index-000001",
                        "uuid": "VEhhQp2XSU2o5xjXvZPikg"
                    }
                },
                "creation_date": "1654588690709",
                "number_of_replicas": "1",
                "uuid": "Z2HoYXr_Qn6vRzQO_6fycQ",
                "version": {
                    "created": "7160099"
                }
            }
        }
    }
}

 监控分裂过程

分裂过程可以通过  _cat recovery API 或者  cluster health API 来观测。

分裂API 会在目标索引在集群中创建后就返回,此时分片还没有分配。,所有分片信息都是 unassinged。一旦主分片被分配,状态转变为 initializing,开始分裂过程。分裂完成后,状态变成 active。此时Elasticserch 可以开始分配副本、或者在集群节点中重新分配主分片。

posted @ 2022-06-07 16:03  hhanhao  阅读(177)  评论(0)    收藏  举报