# How change default number of shards

**URL:** https://discuss.elastic.co/t/how-change-default-number-of-shards/117985
**Category:** Elasticsearch
**Created:** [February 1, 2018, 9:36am UTC](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985 "2018-02-01T09:36:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dorinand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorinand/32/70521_2.png) [@dorinand](https://discuss.elastic.co/u/dorinand)
#### Post date: [February 1, 2018, 9:36am UTC](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985/1 "2018-02-01T09:36:47Z")

</div>

Hello, I am using ES 6.1. and I am trying to change default number of shards from 5 to , for example, 6. Is it possible in some way? When I add lines bellow to the elasticsearch.yaml file, the ES will not start.

```
index.number_of_replicas : 1
index.number_of_shards: 6

```

The error looks like this:

> Found index level settings on node level configuration.
> 
> Since elasticsearch 5.x index level settings can NOT be set on the nodes  
> configuration like the elasticsearch.yaml, in system properties or command line  
> arguments.In order to upgrade all indices the settings must be updated via the  
> /${index}/\_settings API. Unless all settings are dynamic all indices must be closed  
> in order to apply the upgradeIndices created in the future should use index templates  
> to set default values.
> 
> Please ensure all required values are updated on all indices by executing:
> 
> curl -XPUT '[http://localhost:9200/\_all/\_settings?preserve\_existing=true](http://localhost:9200/_all/_settings?preserve_existing=true)' -d '{  
> "index.number\_of\_replicas" : "1",  
> "index.number\_of\_shards" : "6"  
> }'

**My understandig:**  
If I have no indices or when all indices are closed, i can change default value via :  
curl -XPUT '[http://localhost:9200/\_all/\_settings?preserve\_existing=true](http://localhost:9200/_all/_settings?preserve_existing=true)' -d '{  
"index.number\_of\_replicas" : "1",  
"index.number\_of\_shards" : "6"  
}'

Otherwise I am not possible to change default number of shards.

I know I can't change number of shard after indices are created. I can create index like this

```
curl -XPUT "$(hostname -I):9200/myindex/_settings?pretty" -H 'Content-Type: application/json' -d'
{
    "index" : {
        "number_of_shards" : 2, 
        "number_of_replicas" : 0 
    }
}
'

```

I am sending data to ES from Logstash, and create indexes automatically with name depends on date and type, so I cannot create every index manually.

My questions are:

1. is there any way how to change default number of shard ? If yes, how?
2. May I have different indices with different number of shards?

---

<div class="post-metadata">

### Author: ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)
#### Post date: [February 1, 2018, 9:48am UTC](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985/2 "2018-02-01T09:48:09Z")

</div>

you have to use index templates: [https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

with this you can set a default for all indices as follows

```auto
POST _template/default
{
  "template": ["*"]
  "order": -1
  "settings": {
    "number_of_shards": "6",
    "number_of_replicas": "1"
  }
}

```

with the same api you can change the values also index specific

```auto
POST _template/<templatename>
{
  "template": [<indexpattern>]
  "order": 1
  "settings": {
    "number_of_shards": "6",
    "number_of_replicas": "1"
  }
}

```

---

<div class="post-metadata">

### Author: ![dorinand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorinand/32/70521_2.png) [@dorinand](https://discuss.elastic.co/u/dorinand)
#### Post date: [February 1, 2018, 10:18am UTC](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985/3 "2018-02-01T10:18:11Z")

</div>

Thank you for fast reply, it really helps. I just change "template" line to "index\_patterns" like this:

```
PUT _template/default
{
  "index_patterns": ["*"],
  "order": -1,
  "settings": {
    "number_of_shards": "6",
    "number_of_replicas": "1"
  }
}
```

---

<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 1, 2018, 10:18am UTC](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985/4 "2018-03-01T10:18:36Z")

</div>

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