# How to change number\_of\_shards and number\_of\_replica in elasticseatch template

**URL:** https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855
**Category:** Elasticsearch
**Created:** [February 11, 2019, 12:46pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855 "2019-02-11T12:46:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Debashis\_Adak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashis_adak/32/46087_2.png) [@Debashis\_Adak](https://discuss.elastic.co/u/Debashis_Adak)
#### Post date: [February 11, 2019, 12:46pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/1 "2019-02-11T12:46:04Z")

</div>

Hi All,

ELK Version: 6.4.0  
System Details: Windows  
Host: Localhost

I am trying to create a new index in Elasticsearch via Logstash where I need to change the default index settings. By default 5 shards and 1 replica gets created but I want to change the default setting.

I have read some of the blogs and implemented the below in elasticsearch:

PUT \_template/logstash-index-template  
{  
"index\_patterns": ["sample\_index\*"],  
"settings": {  
"index.refresh\_interval": "10s",  
"number\_of\_shards": "1",  
"number\_of\_replicas": "0"  
}  
}

But when I am creating any new index with the same index pattern it is going for the default settings.

yellow open sample\_index-2019.02 A1FbzwvaT7uOSmeGf4wSDw 5 1 10 0 120.1kb 120.1kb

My output filter of Logstash is..

output {  
elasticsearch {  
hosts =\> localhost  
index =\> "sample\_index-%{+YYYY.MM}"  
}  
}

Not sure what is needed to be done to change the default settings.

Thanks in advanced...

Regards,  
Debashis Adak

---

<div class="post-metadata">

### Author: ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)
#### Post date: [February 11, 2019, 1:11pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/2 "2019-02-11T13:11:38Z")

</div>

> [@Debashis\_Adak](#):
>
> Not sure what is needed to be done to change the default settings.

You could have a default order 0 template overriding it since you didn't specify the order. Index templates are always applied in increasing order, with order 0 first, then order 1, order 2 etc.

Could you try to add it as an **order 1** template like this:

```
PUT _template/logstash-index-template
{
   "index_patterns" : ["sample_index*"],
   "order" : 1
   "settings" : {
       "index.refresh_interval" : "10s",
       "number_of_shards" : "1",
       "number_of_replicas" : "0"
   }
}

```

---

<div class="post-metadata">

### Author: ![Debashis\_Adak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashis_adak/32/46087_2.png) [@Debashis\_Adak](https://discuss.elastic.co/u/Debashis_Adak)
#### Post date: [February 12, 2019, 1:08pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/3 "2019-02-12T13:08:07Z")

</div>

Hi Bernt,

Thanks for your valuable input. The problem is resolved now.

But I faced one problem. I tried to update the template with with your parameter. But it was not getting updated. It was holding the previous template only.

I tried to delete the existing template by " **DELETE /\_template/logstash-index-template**" and acknowledgement was coming TRUE but template was not getting deleted.

Post delete command whenever I was running "GET /\_template/logstash-test-template" it was giving me the result. So, the summary is though I was trying to delete the existing template it was not getting deleted. Not even it was getting updated.

Have you faced similar problem? Also, I will be really thankful if you can explain the ordering a little. I am not sure what is the order of the default template of any index.

---

<div class="post-metadata">

### Author: ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)
#### Post date: [February 12, 2019, 1:44pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/4 "2019-02-12T13:44:23Z")

</div>

> [@Debashis\_Adak](#):
>
> I tried to update the template with with your parameter. But it was not getting updated. It was holding the previous template only.

I'm sorry, I should have tested the example before I posted it. I see now that it fails with parser error and there are two things that fail: Index template names can't contain dashes ("-") and I forgot a comma after the order field.

This should work better:

```
PUT _template/logstash_index_template
{
   "index_patterns" : ["sample_index*"],
   "order" : 1,
   "settings" : {
       "index.refresh_interval" : "10s",
       "number_of_shards" : "1",
       "number_of_replicas" : "0"
   }
}

```

> [@Debashis\_Adak](#):
>
> Have you faced similar problem

No, I can overwrite the old index template with a new one, as long as I provide the same valid name 🙂

---

<div class="post-metadata">

### Author: ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)
#### Post date: [February 12, 2019, 2:04pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/5 "2019-02-12T14:04:43Z")

</div>

> [@Debashis\_Adak](#):
>
> if you can explain the ordering a little

The **order** field is very useful because it allows you to build an index template hierarchy, where the lowest order template has the most general settings and the higher orders more specialized.

Let us say you have three index templates like these in your cluster:

```
PUT _template/general_template
{
   "index_patterns" : ["*"],
   "order" : 0,
   "settings" : {
       "number_of_shards" : "2",
       "number_of_replicas" : "1"
   }
}

PUT _template/myorg_template
{
   "index_patterns" : ["myorg*"],
   "order" : 1,
   "settings" : {
       "number_of_shards" : "3",
   }
}

PUT _template/myorg_weekly_template
{
   "index_patterns" : ["myorg_weekly*"],
   "order" : 2,
   "settings" : {
       "number_of_shards" : "1",
       "number_of_replicas" : "0",
   }
}

```

Any index name you specify will match the "\*" index\_pattern of the order 0 template, which means that with this setup all indices in your cluster will by default be created with 2 primary and 1 replica shard.

But, if you create an index with a name starting with "myorg", then the order 1 template kicks in because the name matches its index\_pattern. In that case the order 1 template overrides the "number\_of\_shards" so that new myorg-indices will be created with 3 primary shards (but keeping the "number\_of\_replicas").

Finally, if you create an index named for instance "myorg\_weekly\_2019\_06" then that name will match the index\_pattern of your order 2 template, overriding both "number\_of\_shards" and "number\_of\_replicas" setting them to 1 and 0 respectively for that index.

You can go on and add more specialized templates in this manner, the main point is to use more and more precise index\_patterns for the higher order templates.

---

<div class="post-metadata">

### Author: ![Debashis\_Adak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashis_adak/32/46087_2.png) [@Debashis\_Adak](https://discuss.elastic.co/u/Debashis_Adak)
#### Post date: [February 28, 2019, 1:58pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/6 "2019-02-28T13:58:01Z")

</div>

Wow!!!! The example was simply awesome. Thanks for the valuable input. Now everything is in order..

---

<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: [March 28, 2019, 1:58pm UTC](https://discuss.elastic.co/t/how-to-change-number-of-shards-and-number-of-replica-in-elasticseatch-template/167855/7 "2019-03-28T13:58:03Z")

</div>

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