# Writing API update for setting number of replicas to 0

**URL:** https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595
**Category:** Elasticsearch
**Created:** [January 19, 2021, 10:00pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595 "2021-01-19T22:00:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![txmrlevine](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@txmrlevine](https://discuss.elastic.co/u/txmrlevine)
#### Post date: [January 19, 2021, 10:00pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/1 "2021-01-19T22:00:08Z")

</div>

We are trying to eliminate replicas in our non-prod environment to save space and we do not need the replicas. we know this is counter to the fault tolerance but it is something we must do. I found this on the documentation but not sure where to invoke it because I am not an API guy \_

```auto
curl -H "Content-Type: application/json" -XPUT localhost:9200/*/_settings -d '{ "index" : { "number_of_replicas" : 0 } }'

```

is this run the Kibana dev tools? also we need to use -

```auto
 preserve_existing
(Optional, Boolean) If true, existing index settings remain unchanged. Defaults to false. 

```

to preserve what is there - what does the entire command actually look like or is there a FILE where I can change the setting and restart services to accomplish this.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 19, 2021, 10:38pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/2 "2021-01-19T22:38:35Z")

</div>

The below command in Dev Tools will set every index to 0.

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

```

---

<div class="post-metadata">

### Author: ![txmrlevine](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@txmrlevine](https://discuss.elastic.co/u/txmrlevine)
#### Post date: [January 19, 2021, 11:03pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/3 "2021-01-19T23:03:15Z")

</div>

I saw that but do you just put the preserve\_existing in like this?

![image001.jpg](https://us1.discourse-cdn.com/elastic/original/2X/6/64f616983d5e1c5697da3e3dc3eb37d7d031eebf.jpg)

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 19, 2021, 11:41pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/4 "2021-01-19T23:41:40Z")

</div>

Sorry, I don't really understand `preserve_existing` or have used it.

From the documentation though it sounds like you want to keep this false. If you set as true then nothing at all will change.

---

<div class="post-metadata">

### Author: ![txmrlevine](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@txmrlevine](https://discuss.elastic.co/u/txmrlevine)
#### Post date: [January 20, 2021, 3:42pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/5 "2021-01-20T15:42:14Z")

</div>

Can you find out what the syntax is for the option since you are there at elastic. From what I understand the option is to KEEP the setting for the shards that already exist and any new shards would be created without replicas. Our Security team will also want to know the risk of having no replicas. what is the average fault rate for shards itself. We keep all data on an NFS partition so shards are all kept in the same place.

I tried this .

```auto
PUT /_settings
{
  "index" : {
    "number_of_replicas" : 0,
   "preserve_existing" : True
  }
}

```

but received an error in the dev tools- I just need to know how to use options. Thanks for any help you can provide.

---

<div class="post-metadata">

### Author: ![mark54g](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mark54g](https://discuss.elastic.co/u/mark54g)
#### Post date: [January 27, 2021, 11:13pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/6 "2021-01-27T23:13:42Z")

</div>

My recommendation, here, would be to use a template, rather than using `preserve_existing` since it gets you more in line with what you're after, if you want new indices to not have replicas.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates-v1.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates-v1.html) has some explanations on how to do that, and you can have anything that's created under that pattern have the settings you specify. You'd want to set `number_of_replicas` to a numeric value like 0 for your use case.

Alternatively, you can alter the number of replicas by using ILM and tiering with hot/warm/cold etc.

> **[ILM: Manage the index lifecycle | Elasticsearch Reference \[7.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html)**

While the shards themselves may not fail, though they can and do at times, you are more likely to lose a node and incur data loss, so it is not recommended, and I do hope you have snapshots in place and configured.

> **[Snapshot and restore | Elasticsearch Reference \[7.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html)**

Also, NFS tends to be a poor choice due to the overhead from attribute hits, though it can be alleviated, to a degree, with some mount time settings, I would still steer away from it if you can.

---

<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: [February 24, 2021, 11:13pm UTC](https://discuss.elastic.co/t/writing-api-update-for-setting-number-of-replicas-to-0/261595/7 "2021-02-24T23:13:45Z")

</div>

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