Actual shard is not a primary – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-8.9

Briefly, this error occurs when an operation is attempted on a non-primary shard in Elasticsearch. Primary shards hold the original data and non-primary (replica) shards hold copies of this data. Certain operations can only be performed on primary shards. To resolve this issue, you can either reroute the operation to the primary shard or promote the replica shard to primary. However, promoting a replica to primary should be done cautiously as it can lead to data inconsistency. Another solution could be to ensure that the cluster health is green, indicating all primary shards are active.

This guide will help you check for common problems that cause the log ” actual shard is not a primary ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: shard, replication.

Log Context

Log “actual shard is not a primary” class name is TransportReplicationAction.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 final ShardRouting shardRouting = indexShard.routingEntry();
 // we may end up here if the cluster state used to route the primary is so stale that the underlying
 // index shard was replaced with a replica. For example - in a two node cluster; if the primary fails
 // the replica will take over and a replica will be assigned to the first node.
 if (shardRouting.primary() == false) {
 throw new ReplicationOperation.RetryOnPrimaryException(shardId; "actual shard is not a primary " + shardRouting);
 }
 final String actualAllocationId = shardRouting.allocationId().getId();
 if (actualAllocationId.equals(primaryRequest.getTargetAllocationID()) == false) {
 throw new ShardNotFoundException(
 shardId;

 

 [ratemypost]