一、问题:
UnavailableShardsException: at least one primary shard for the index [.security-7] is unavailable.
二、原因:
.security-7的索引分片未分配。
三、解决方法:
1、查看集群健康状态:
curl --cacert http_ca.crt -u username:passwd -X GET "http://elasticsearch-host-IP:elasticsearch-port/_cat/health?v&pretty"
其中,/_cat/health 表示获集群健康状态信息,?v 表示输出详细信息(verbose),&pretty 表示以易读的格式输出。
注意,请将上述username和passwd替换为你的用户名和密码,elasticsearch-host-IP 和elasticsearch-port替换为你的实际值。我是在elasticsearch-8.10.2/config/certs/目录下运行的,请确保http_ca.crt在此路径下。
结果如下:![]()
会发现集群状态为红色,unassign这一项为1,就是.security-7索引分片未分配。
2、查看.security-7索引的状态:
curl --cacert http_ca.crt -u username:passwd -X GET "http://elasticsearch-host-IP:elasticsearch-port/.security-7?v"
注意,请将上述username和passwd替换为你的用户名和密码,elasticsearch-host-IP 和elasticsearch-port替换为你的实际值。
结果如下:

会发现.security-7索引状态是unassigned,正常分配后的状态应该是这样:

3、尝试重新分配索引.security-7:
curl -u username:passwd -X POST "elasticsearch-host-IP:elasticsearch-port/_cluster/reroute" -H 'Content-Type: application/json' -d '{
"commands": [
{
"allocate": {
"index": ".security-7",
"shard": 0,
"node": "your_node_name",
"allow_primary": true
}
}
]
}'
还是失败。
4、最后,删除了所有节点data目录下的内容,重新启动ES后,问题解决了。
(.security-7存放在data目录下,强制删除数据后会重新分配索引)
9322

被折叠的 条评论
为什么被折叠?



