# Setting index.number\_of\_replicas =\> 0 by default in ES \>= 5

**URL:** https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195
**Category:** Elasticsearch
**Created:** [July 2, 2018, 11:57am UTC](https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195 "2018-07-02T11:57:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Harvey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_harvey/32/32183_2.png) [@Alex\_Harvey](https://discuss.elastic.co/u/Alex_Harvey)
#### Post date: [July 2, 2018, 11:57am UTC](https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195/1 "2018-07-02T11:57:50Z")

</div>

I am trying to build a single-node all-in-one ELK 6 cluster for development and testing. To do this and get a cluster that goes into green state, I need to ensure that all indices inherit a setting index.number\_of\_replicas =\> 0.

I have read threads on this site that explained that after ES \>= 5, it is no longer possible to define this setting in the elasticsearch.yml. And I know how to manually change the index settings using the REST API.

But how can I do this in an automated way now? I don't know the names of the indices until the ELK cluster builds.

After building I see a bunch of templates:

```
$ curl 0.0.0.0:9200/_template | jq keys
[
  ".ml-anomalies-",
  ".ml-meta",
  ".ml-notifications",
  ".ml-state",
  ".monitoring-alerts",
  ".monitoring-beats",
  ".monitoring-es",
  ".monitoring-kibana",
  ".monitoring-logstash",
  ".triggered_watches",
  ".watch-history-7",
  ".watches",
  "logstash",
  "logstash-index-template",
  "security-index-template",
  "security_audit_log"
]

```

and one index for logstash:

```
$ curl 0.0.0.0:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open logstash-2018.07.02 ppxqmtMCR5SZUmXMwdVJtA 5 1 3114 0 1.1mb 1.1mb

```

Many thanks.

---

<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: [July 2, 2018, 12:44pm UTC](https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195/2 "2018-07-02T12:44:31Z")

</div>

To prevent new indices from having replica shards you will need to create an [Index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) in your 1-node cluster, which is automatically applied during index creation.

For instance, if you want to set the number of replicas to 0 for new logstash indices you will have to add something like this:

```
curl -XPUT "localhost:9200/_template/logstash_template" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["logstash*"],
  "settings": {
    "number_of_replicas": 0
  }
}
'

```

The crucial element here is "index\_patterns" which must match the start of the index names. If you want this setting to work for all indices (though I haven't tried this myself), you should be able to do:

```
curl -XPUT "localhost:9200/_template/default_template" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["*"],
  "settings": {
    "number_of_replicas": 0
  }
}
'

```

Here the asterisk should match all new index names.

---

<div class="post-metadata">

### Author: ![Alex\_Harvey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_harvey/32/32183_2.png) [@Alex\_Harvey](https://discuss.elastic.co/u/Alex_Harvey)
#### Post date: [July 2, 2018, 4:52pm UTC](https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195/3 "2018-07-02T16:52:39Z")

</div>

Right, that did fix it, although for the record the command was:

```
curl -XPUT "localhost:9200/_template/default_template" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["*"],
  "settings": {
    "index": {
      "number_of_replicas": 0
    }
  }
}
'

```

Key point (for me anyway) is that this needs to be issued before Logstash starts, as it won't affect any templates already created. (I had tried it earlier with the Puppet module and an ordering problem meant that it ran after Logstash started.)

---

<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: [July 30, 2018, 5:05pm UTC](https://discuss.elastic.co/t/setting-index-number-of-replicas-0-by-default-in-es-5/138195/4 "2018-07-30T17:05:20Z")

</div>

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