elasticsearch NoShardAvailableActionException
1. 检查健康状态
curl --user 用户名:密码 -XGET http://本机ip:端口/_cluster/health\?pretty
我不加–user 用户名:密码 会报错,还有如果使用127.0.0.1或者localhost,可能会报错not route to host,反正我是遇到了。
{
"cluster_name" : "elasticsearch",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 1201,
"active_shards" : 1201,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 50,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 96.00319744204636
}
green为健康状态,red为不健康,yellow在两者之间,但仍不健康。
2. 查看unassigned类型的索引名字
可以看到有很多unssigned,就是此类导致的报错。
authentication-2021.02.20 3 p STARTED 72 169.1kb 96.0.193.57 LasG0MY
authentication-2021.02.20 1 p STARTED 65 104.8kb 96.0.193.57 LasG0MY
authentication-2021.02.20 2 p STARTED 58 124.9kb 96.0.193.57 LasG0MY
authentication-2021.02.20 4 p STARTED 64 141.1kb 96.0.193.57 LasG0MY
authentication-2021.02.20 0 p STARTED 81 149.8kb 96.0.193.57 LasG0MY
mobile01-2021.03.02 3 p STARTED 3 33kb 96.0.193.57 LasG0MY
mobile01-2021.03.02 3 r UNASSIGNED
mobile01-2021.03.02 1 p STARTED 5 46.6kb 96.0.193.57 LasG0MY
mobile01-2021.03.02 1 r UNASSIGNED
mobile01-2021.03.02 2 p STARTED 7 96.6kb 96.0.193.57 LasG0MY
由于我的是单机环境,没有启用副本分片,可以将副本设置为0 。
curl --user 用户名:密码 -XGET http://本机ip:端口/_settings' -H 'content-Type:application/json' -d' {"number_of_replicas":0}'
3. 删除unassigned状态的索引
curl --user 用户名:密码 -XGET http://本机ip:端口/authentication-2021.02.20
等等。。。
其中,authentication-2021.02.20 为unassigned 状态的名字。