{"error":{"root_cause":[{"type":"named_object_not_found_exception","reason":"[6:22] unknown field [allocate]"}],"type":"x_content_parse_exception","reason":"[6:22] [cluster_reroute] failed to parse field [commands]","caused_by":{"type":"named_object_not_found_exception","reason":"[6:22] unknown field [allocate]"}},"status":400}
------------------------------
UNASSIGNED
Try adding a set -x at the top to enable a bit of debugging.
However you should't need a script to fix things like this. If you are having issues with allocation, perhaps digging into it further will fix the underlying issue?
Yes this script has some bug probably
this is the output:
+ for line in '$(curl -u elastic:pass http://10.220.111.200:9203/_cat/shards | grep UNASSIGNED)'
++ echo UNASSIGNED
++ awk '{print $1}'
+ INDEX=UNASSIGNED
++ echo UNASSIGNED
++ awk '{print $2}'
+ SHARD=
I have a lot of unassigned shards some I need to fix it by reroute with allow_primary": true parameter.
current_state" : "unassigned",
"unassigned_info" : {
"reason" : "CLUSTER_RECOVERED",
"at" : "2022-09-08T17:15:35.604Z",
"last_allocation_status" : "no_valid_shard_copy"
},
"can_allocate" : "no_valid_shard_copy",
"allocate_explanation" : "cannot allocate because a previous copy of the primary shard existed but can no longer be found on the nodes in the cluster",
@INS - I agree with @warkolm , you should not need a script like this. Identifying the reason of these unassigned shards using the cluster allocation explain API should be the recommended approach. This will help you to identify why these shards are unassigned and you can address the problem accordingly.
It was pointed out why this shards have not been assigned " "allocate_explanation" : "cannot allocate because a previous copy of the primary shard existed but can no longer be found on the nodes in the cluster"," Do You have any ideas, preferences ?
That is why we highlighted that you should dig into the allocation failure and address the root cause.
Elasticsearch reports that no_valid_shard_copy and cannot allocate because a previous copy of the primary shard existed but can no longer be found on the nodes in the cluster - so the question would be to understand what happened to the primary shard? Has the corresponding node left the cluster? temporarily (e.g instability, performance issues) or definitively (hardware failure, node is forever gone, etc.)?
You would need to look as well whether your indices are configured with at least 1 replica shard. Indices without replica shards are not highly available.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.