At least one primary shard for the index [.security-7] is unavailable issue

I have a two-node cluster with IP "" , "". One of my VMs "" suddenly stopped, and when I start it, the cluster health was RED. Then I restart both VMs again and below message has been found in their log and I could not login in and

[2022-10-08T08:40:07,003][ERROR][o.e.x.m.c.c.ClusterStatsCollector] [node-1] collector [cluster_stats] failed to collect data
org.elasticsearch.action.UnavailableShardsException: at least one primary shard for the index [.security-7] is unavailable
	at ~[?:?]
	at ~[?:?]
	at$usageStats$1( ~[?:?]
	at org.elasticsearch.action.ActionListener$1.onResponse( ~[elasticsearch-7.16.1.jar:7.16.1]
	at$usageStats$5( ~[?:?]
	at org.elasticsearch.action.ActionListener$1.onResponse( ~[elasticsearch-7.16.1.jar:7.16.1]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at org.elasticsearch.xpack.core.action.TransportXPackUsageAction.lambda$masterOperation$2( ~[?:?]
	at org.elasticsearch.xpack.core.common.IteratingActionListener.onResponse( ~[?:?]
	at org.elasticsearch.action.ActionRunnable.lambda$supply$0( ~[elasticsearch-7.16.1.jar:7.16.1]
	at org.elasticsearch.action.ActionRunnable$2.doRun( ~[elasticsearch-7.16.1.jar:7.16.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun( ~[elasticsearch-7.16.1.jar:7.16.1]
	at ~[elasticsearch-7.16.1.jar:7.16.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]
	at java.util.concurrent.ThreadPoolExecutor$ [?:?]
	at [?:?]

Then based on this link I did below steps to resolve issue:

1- define a new user
elasticsearch-users useradd restore_user -p xxxxxxx -r superuser
2- delete corrupt index:

curl -u restore_user -k -X DELETE "https://localhost:9200/.security-*"

3- restart all nodes

when I did these steps, I was able to login to elasticsearch node which I defined new user, by new user. but all previous roles and users have been vanished and I had to define them manauly agarin.
How can I handle this issue without the need of defining users and roles again?
also, the cluster health is RED and there are two unassigned shard in kibana monitoring but in the indices part, the status of all indices are green.


When you delete the index you delete all the existing users and roles.

We would need to figure out why your nodes "suddenly stopped" to try to understand what caused the index to be unrecoverable. Sharing some more logs would help.

Hi, thanks for your answer. The VM has been stopped so the elastic node stopped too.
how can we prevent such disastrous?

How were the hosts stopped exactly? Did Elasticsearch have the chance to gracefully shutdown?

actually the VM which the software group gave us was just for a limited time and after that time the VM automatically stopped but elasticsearch has been defined as windows service so it is expected that stopped correctly.
What is the best way to stop Elasticsearch to prevent this problem. And, when this issue happened, is there any way to resolve above error except deleting security index?

Also, is there a way to make a daily backup of roles and users and when this issue happened just insert the backup to inhibit the definition of users and roles manually ?

I will be so appreciated if you consider my comments. Thanks.

You can take snapshots of your indices and then restore them, yes.

I mean taking backup of defined roles and users, not indices. Can we take backup of roles and users?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.