Is there any way to set number of shards for an Index's replica?(default is 1)

I am setting the index's shard to something other than 1. (Say 5). I was expecting to have 5 primary shards and 5 replica shards. But what I got is 5 primary shards and 1 replica shard.

Is there anyway to set the shard count for the replica?

I am using Elasticsearch v7.14

Replica shards are 1:1 with primary shards so if you have 5 primary shards and 1 replica shard configured each primary shard will have one replica. Use the cat shards API to list shards.

@Christian_Dahlqvist Unfortunately that is not the case. That is why I am asking the question. Please try it out yourself. I set shard count to 5 expecting primary 5 and replica 5. But I got 5 on primary and 1 on replica.

Please show this in the output from the cat shards api. The cat indices api will show the settings where 5 (number of primary shards) and 1 (number of replica shards per primary shard) represents 10 total shards.

Perhaps I am missing something.

You can dynmically change the number of replicas see here

Dynamic index settings

Below is a list of all dynamic index settings that are not associated with any specific index module:

index.number_of_replicas

The number of replicas each primary shard has. Defaults to 1.

Example : Replicas are dynamic, meaning it can be set after the index is created, number of shards is static and can only be set at creation.

If you have 5 shards and 1 replica you will have 5 primaries and 5 Replica Shards (1 replica for each Primary)

If you have 5 shards and 2 replicaa you will have 5 primaries and 10 Replica Shards (2 replicas for each Primary)

You can change replicas with this

PUT my-index/_settings
{
  "index.number_of_replicas": 2
}


I know how to change shard.(reindex) see above picture and tell me why replica is 1?

Because that is the default

The number of replicas each primary shard has. Defaults to 1.

If you don't want a replica or you need to set it explicitly in the mapping or template otherwise you will always get 1 replca

PUT my-index/_settings
{
  "index.number_of_replicas": 0
}

The information in your print screen is correct, this is the index management screen, it teels you that your index has 6 primary and 1 replica, it is not showing the total shards.

Try to run:

GET _cat/shards/index_name

And you will see that you have in total 12 shards for your index.

1 Like

That indicates that each index has 6 primary shards and that each primary shard in turn has 1 replica, resulting in 12 shards (6 primary and 6 replica) per index. You can see this if you look at the cat shards API.

1 Like

The number of replicas displayed is the number of replicas PER Primary Shard...

If you want total shards you have to do the math in your head

top Index

total shards = Number of Primaries Shards * (1 Primary + Number of Replicas)
12 = 6 primaries * (1 + 1 Replica)
12 = 6 * 2

1 Like

I got it now. The screen shot I have under Primary listed how many shards you have and under replica, the # is not how many replica shards it has. It is telling me how many replica the index has. Confusing screen.
GET _cat/shards/index_name did show it has 6 shard for replica.
Wrong screen to find shard info for replica.

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