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

Opster Team

Aug-23, Version: 1-2.9

Before you dig into reading this guide, have you tried asking OpsGPT what this log means? You’ll receive a customized analysis of your log.

Try OpsGPT now for step-by-step guidance and tailored insights into your OpenSearch operation.

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

For a complete solution to your to your search operation, try for free AutoOps for Elasticsearch & OpenSearch . With AutoOps and Opster’s proactive support, you don’t have to worry about your search operation – we take charge of it. Get improved performance & stability with less hardware.

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 OpenSearch concepts: shard, replication.

Log Context

Log “actual shard is not a primary” class name is TransportReplicationAction.java. We extracted the following from OpenSearch 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;

 

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Get expert answers on Elasticsearch/OpenSearch