集群分配解释 API
编辑集群分配解释 API编辑
提供对分片当前分配的解释。
resp = client.cluster.allocation_explain( body={ "index": "my-index-000001", "shard": 0, "primary": False, "current_node": "my-node", }, ) print(resp)
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: false, current_node: 'my-node' } ) puts response
GET _cluster/allocation/explain { "index": "my-index-000001", "shard": 0, "primary": false, "current_node": "my-node" }
描述编辑
集群分配解释 API 的目的是为集群中的分片分配提供解释。对于未分配的分片,解释 API 提供了分片未分配的原因的解释。对于已分配的分片,解释 API 提供了分片为何保留在其当前节点上以及未移动或重新平衡到另一个节点的解释。当尝试诊断分片为何未分配或分片为何在您可能期望的情况下继续保留在其当前节点上时,此 API 可能非常有用。
查询参数编辑
-
include_disk_info
- (可选,布尔值) 如果为
true
,则返回有关磁盘使用情况和分片大小的信息。默认为false
。 -
include_yes_decisions
- (可选,布尔值) 如果为
true
,则在解释中返回 YES 决策。默认为false
。
请求正文编辑
-
current_node
- (可选,字符串) 指定当前持有要解释的分片的节点的节点 ID 或节点名称。要解释未分配的分片,请省略此参数。
-
index
- (可选,字符串) 指定您想要解释的索引的名称。
-
primary
- (可选,布尔值) 如果为
true
,则返回给定分片 ID 的主分片的解释。 -
shard
- (可选,整数) 指定您想要解释的分片的 ID。
示例编辑
未分配的主分片编辑
以下请求获取未分配的主分片的分配解释。
resp = client.cluster.allocation_explain( body={"index": "my-index-000001", "shard": 0, "primary": True}, ) print(resp)
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: true } ) puts response
GET _cluster/allocation/explain { "index": "my-index-000001", "shard": 0, "primary": true }
API 响应表明分片只能分配到不存在的节点。
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "unassigned", "unassigned_info" : { "reason" : "INDEX_CREATED", "at" : "2017-01-04T18:08:16.600Z", "last_allocation_status" : "no" }, "can_allocate" : "no", "allocate_explanation" : "Elasticsearch isn't allowed to allocate this shard to any of the nodes in the cluster. Choose a node to which you expect this shard to be allocated, find this node in the node-by-node explanation, and address the reasons which prevent Elasticsearch from allocating this shard there.", "node_allocation_decisions" : [ { "node_id" : "8qt2rY-pT6KNZB3-hGfLnw", "node_name" : "node-0", "transport_address" : "127.0.0.1:9401", "roles" : ["data", "data_cold", "data_content", "data_frozen", "data_hot", "data_warm", "ingest", "master", "ml", "remote_cluster_client", "transform"], "node_attributes" : {}, "node_decision" : "no", "weight_ranking" : 1, "deciders" : [ { "decider" : "filter", "decision" : "NO", "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]" } ] } ] }
以下响应包含对先前已分配的未分配主分片的分配解释。
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "unassigned", "unassigned_info" : { "reason" : "NODE_LEFT", "at" : "2017-01-04T18:03:28.464Z", "details" : "node_left[OIWe8UhhThCK0V5XfmdrmQ]", "last_allocation_status" : "no_valid_shard_copy" }, "can_allocate" : "no_valid_shard_copy", "allocate_explanation" : "Elasticsearch can't allocate this shard because there are no copies of its data in the cluster. Elasticsearch will allocate this shard when a node holding a good copy of its data joins the cluster. If no such node is available, restore this index from a recent snapshot." }
未分配的副本分片编辑
以下响应包含对由于 延迟分配 而未分配的副本的分配解释。
{ "index" : "my-index-000001", "shard" : 0, "primary" : false, "current_state" : "unassigned", "unassigned_info" : { "reason" : "NODE_LEFT", "at" : "2017-01-04T18:53:59.498Z", "details" : "node_left[G92ZwuuaRY-9n8_tc-IzEg]", "last_allocation_status" : "no_attempt" }, "can_allocate" : "allocation_delayed", "allocate_explanation" : "The node containing this shard copy recently left the cluster. Elasticsearch is waiting for it to return. If the node does not return within [%s] then Elasticsearch will allocate this shard to another node. Please wait.", "configured_delay" : "1m", "configured_delay_in_millis" : 60000, "remaining_delay" : "59.8s", "remaining_delay_in_millis" : 59824, "node_allocation_decisions" : [ { "node_id" : "pmnHu_ooQWCPEFobZGbpWw", "node_name" : "node_t2", "transport_address" : "127.0.0.1:9402", "roles" : ["data_content", "data_hot"], "node_decision" : "yes" }, { "node_id" : "3sULLVJrRneSg0EfBB-2Ew", "node_name" : "node_t0", "transport_address" : "127.0.0.1:9400", "roles" : ["data_content", "data_hot"], "node_decision" : "no", "store" : { "matching_size" : "4.2kb", "matching_size_in_bytes" : 4325 }, "deciders" : [ { "decider" : "same_shard", "decision" : "NO", "explanation" : "a copy of this shard is already allocated to this node [[my-index-000001][0], node[3sULLVJrRneSg0EfBB-2Ew], [P], s[STARTED], a[id=eV9P8BN1QPqRc3B4PLx6cg]]" } ] } ] }
已分配的分片编辑
以下响应包含对已分配分片的分配解释。响应表明分片不允许保留在其当前节点上,必须重新分配。
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "started", "current_node" : { "id" : "8lWJeJ7tSoui0bxrwuNhTA", "name" : "node_t1", "transport_address" : "127.0.0.1:9401", "roles" : ["data_content", "data_hot"] }, "can_remain_on_current_node" : "no", "can_remain_decisions" : [ { "decider" : "filter", "decision" : "NO", "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]" } ], "can_move_to_other_node" : "no", "move_explanation" : "This shard may not remain on its current node, but Elasticsearch isn't allowed to move it to another node. Choose a node to which you expect this shard to be allocated, find this node in the node-by-node explanation, and address the reasons which prevent Elasticsearch from allocating this shard there.", "node_allocation_decisions" : [ { "node_id" : "_P8olZS8Twax9u6ioN-GGA", "node_name" : "node_t0", "transport_address" : "127.0.0.1:9400", "roles" : ["data_content", "data_hot"], "node_decision" : "no", "weight_ranking" : 1, "deciders" : [ { "decider" : "filter", "decision" : "NO", "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]" } ] } ] }
以下响应包含对必须保留在其当前节点上的分片的分配解释。将分片移动到另一个节点不会改善集群平衡。
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "started", "current_node" : { "id" : "wLzJm4N4RymDkBYxwWoJsg", "name" : "node_t0", "transport_address" : "127.0.0.1:9400", "roles" : ["data_content", "data_hot"], "weight_ranking" : 1 }, "can_remain_on_current_node" : "yes", "can_rebalance_cluster" : "yes", "can_rebalance_to_other_node" : "no", "rebalance_explanation" : "Elasticsearch cannot rebalance this shard to another node since there is no node to which allocation is permitted which would improve the cluster balance. If you expect this shard to be rebalanced to another node, find this node in the node-by-node explanation and address the reasons which prevent Elasticsearch from rebalancing this shard there.", "node_allocation_decisions" : [ { "node_id" : "oE3EGFc8QN-Tdi5FFEprIA", "node_name" : "node_t1", "transport_address" : "127.0.0.1:9401", "roles" : ["data_content", "data_hot"], "node_decision" : "worse_balance", "weight_ranking" : 1 } ] }
无参数编辑
如果您在没有参数的情况下调用 API,Elasticsearch 将检索任意未分配的主分片或副本分片的分配解释。
resp = client.cluster.allocation_explain() print(resp)
response = client.cluster.allocation_explain puts response
GET _cluster/allocation/explain
如果集群不包含任何未分配的分片,API 将返回 400
错误。