ES 遇到 unassigned shard如何处理?
解决方法:(1)如果是红色的,可以直接分片shard给你认为有最新(或最多)数据的节点。见下:
摘自:https://discuss.elastic.co/t/how-to-resolve-the-unassigned-shards/87635
Use the reroute command to assign the unassigned shard to a node.
If your cluster is red then you probably have primary shards unassigned. The command below will allow you to reassign a shard that has gone "stale"(腐烂不新鲜的). This means that ES is not sure which copy of the shard has the most recent data and it will not assign one as primary because if another shard with newer data connects to the cluster later it will be overwritten. If your confident that the shard has all of the data you need then you can assign it to a node with the command below. Just be wary of data loss。
curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -H 'Content-Type: application/json' -d'
{
"commands" : [
{
"allocate_stale_primary" : {
"index" : "test", "shard" : 1,
"node" : "node3",
"accept_data_loss" : true
}
}
]
}
'
https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html
(2)如果集群是黄色的,可以等其恢复
The status may be one of three values:
green
- All primary and replica shards are allocated. Your cluster is 100% operational.
yellow
- All primary shards are allocated, but at least one replica is missing. No data is missing, so search results will still be complete. However, your high availability is compromised to some degree. If moreshards disappear, you might lose data. Think of
yellow
as a warning that should prompt investigation. red
- At least one primary shard (and all of its replicas) is missing. This means that you are missing data: searches will return partial results, and indexing into that shard will return an exception.
The green
/yellow
/red
status is a great way to glance at your cluster and understand what’s going on. The rest of the metrics give you a general summary of your cluster:
number_of_nodes
andnumber_of_data_nodes
are fairly self-descriptive.active_primary_shards
indicates the number of primary shards in your cluster. This is an aggregate total across all indices.active_shards
is an aggregate total of all shards across all indices, which includes replica shards.relocating_shards
shows the number of shards that are currently moving from one node to another node(现网中遇到,因为kill -9重启es的方法不对,导致node下线,集群重新分配shard). This number is often zero, but can increase when Elasticsearch decides a cluster is not properly balanced, a new node is added, or a node is taken down, for example(原因).initializing_shards
is a count of shards that are being freshly created. For example, when you first create an index, the shards will all briefly reside ininitializing
state. This is typically a transient event, and shards shouldn’t linger ininitializing
too long. You may also see initializing shards when a node is first restarted: as shards are loaded from disk, they start asinitializing
.(现网遇到过)unassigned_shards
are shards that exist in the cluster state, but cannot be found in the cluster itself. A common source of unassigned shards are unassigned replicas. For example, an index with five shards and one replica will have five unassigned replicas in a single-node cluster. Unassigned shards will also be present if your cluster isred
(since primaries are missing).
Imagine something goes wrong one day, and you notice that your cluster health looks like this:
{ "cluster_name": "elasticsearch_zach", "status": "red", "timed_out": false, "number_of_nodes": 8, "number_of_data_nodes": 8, "active_primary_shards": 90, "active_shards": 180, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 20 }
OK, so what can we deduce from this health status? Well, our cluster is red
, which means we are missing data (primary + replicas). We know our cluster has 10 nodes, but see only 8 data nodes listed in the health. Two of our nodes have gone missing. We see that there are 20 unassigned shards.
That’s about all the information we can glean. The nature of those missing shards are still a mystery. Are we missing 20 indices with 1 primary shard each? Or 1 index with 20 primary shards? Or 10 indices with 1 primary + 1 replica? Which index?
To answer these questions, we need to ask cluster-health
for a little more information by using the level
parameter:
GET _cluster/health?level=indices
This parameter will make the cluster-health
API add a list of indices in our cluster and details about each of those indices (status, number of shards, unassigned shards, and so forth):
{ "cluster_name": "elasticsearch_zach", "status": "red", "timed_out": false, "number_of_nodes": 8, "number_of_data_nodes": 8, "active_primary_shards": 90, "active_shards": 180, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 20 "indices": { "v1": { "status": "green", "number_of_shards": 10, "number_of_replicas": 1, "active_primary_shards": 10, "active_shards": 20, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0 }, "v2": { "status": "red",

"number_of_shards": 10, "number_of_replicas": 1, "active_primary_shards": 0, "active_shards": 0, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 20

}, "v3": { "status": "green", "number_of_shards": 10, "number_of_replicas": 1, "active_primary_shards": 10, "active_shards": 20, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0 }, .... } }
Once we ask for the indices output, it becomes immediately clear which index is having problems: the v2
index. We also see that the index has 10 primary shards and one replica, and that all 20 shards are missing. Presumably these 20 shards were on the two nodes that are missing from our cluster.
摘自:https://www.elastic.co/guide/en/elasticsearch/guide/current/_cluster_health.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
2016-08-31 C++构造函数和析构函数调用虚函数时都不会使用动态联编
2016-08-31 C++调用父类的构造函数规则
2016-08-31 C++迟后联编和虚函数表