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

**URL:** https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606
**Category:** Elasticsearch
**Created:** [August 26, 2021, 6:30pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606 "2021-08-26T18:30:40Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)
#### Post date: [August 26, 2021, 6:30pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/1 "2021-08-26T18:30:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 26, 2021, 8:30pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/2 "2021-08-26T20:30:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)
#### Post date: [August 27, 2021, 2:46pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/3 "2021-08-27T14:46:20Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 27, 2021, 2:56pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/4 "2021-08-27T14:56:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 27, 2021, 2:58pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/5 "2021-08-27T14:58:23Z")

</div>

Perhaps I am missing something.

You can dynmically change the number of replicas see [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#dynamic-index-settings)

> ### 
> 
> 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

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

```

---

<div class="post-metadata">

### Author: ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)
#### Post date: [August 27, 2021, 3:13pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/6 "2021-08-27T15:13:04Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/d/3/d37b0d9305b900ddcaa47ce7d3a3b2026febbc38.png)  
I know how to change shard.(reindex) see above picture and tell me why replica is 1?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 27, 2021, 3:17pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/7 "2021-08-27T15:17:35Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [August 27, 2021, 3:19pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/8 "2021-08-27T15:19:01Z")

</div>

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:

```auto
GET _cat/shards/index_name

```

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

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 27, 2021, 3:19pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/9 "2021-08-27T15:19:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 27, 2021, 3:21pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/10 "2021-08-27T15:21:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)
#### Post date: [August 27, 2021, 3:24pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/11 "2021-08-27T15:24:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 24, 2021, 3:24pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-set-number-of-shards-for-an-indexs-replica-default-is-1/282606/12 "2021-09-24T15:24:55Z")

</div>

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