# Specifying default replicas and shards for an index

**URL:** https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515
**Category:** Elasticsearch
**Created:** [June 1, 2011, 7:17am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515 "2011-06-01T07:17:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![paranoiabla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paranoiabla/32/2160_2.png) [@paranoiabla](https://discuss.elastic.co/u/paranoiabla)
#### Post date: [June 1, 2011, 7:17am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/1 "2011-06-01T07:17:23Z")

</div>

Hi guys,

Initially if you just start an elastic search server and try to create  
an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
How can I configure this? I know that I can send a JSON / Text  
initially when I am creating a new index but I don't want every time  
when a new index is created to specify the shards/replicas I want  
initially to use different values than 5 shards and 2 replicas.

Thank you.

---

<div class="post-metadata">

### Author: ![Weiwei\_Wang](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@Weiwei\_Wang](https://discuss.elastic.co/u/Weiwei_Wang)
#### Post date: [June 1, 2011, 8:07am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/2 "2011-06-01T08:07:28Z")

</div>

{  
"cluster":{  
"name":"elasticsearch"  
},  
"gateway":{  
"recover\_after\_nodes": 1,  
"recover\_after\_time": "5m",  
"expected\_nodes": 2  
},  
"index" : {  
"number\_of\_shards":3,  
"number\_of\_replicas":2,  
}  
}

On Jun 1, 3:17 pm, paranoiabla [paranoia...@gmail.com](mailto:paranoia...@gmail.com) wrote:

> Hi guys,
> 
> Initially if you just start an Elasticsearch server and try to create  
> an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
> How can I configure this? I know that I can send a JSON / Text  
> initially when I am creating a new index but I don't want every time  
> when a new index is created to specify the shards/replicas I want  
> initially to use different values than 5 shards and 2 replicas.
> 
> Thank you.

---

<div class="post-metadata">

### Author: ![paranoiabla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paranoiabla/32/2160_2.png) [@paranoiabla](https://discuss.elastic.co/u/paranoiabla)
#### Post date: [June 1, 2011, 8:27am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/3 "2011-06-01T08:27:50Z")

</div>

Ok,

I saw that there is a config folder when you download the standalone  
Elasticsearch. And inside this config folder there is a file :  
elasticsearch.yml where I can specify these values. This all is great  
BUT in my case I am using a standalone server started from a Java  
class, like below:

======  
public static void main(String args) {  
System.out.println("Starting Elastic Search Server");

```
	Builder settings = ImmutableSettings.settingsBuilder();
	// here you can set the node and index settings via API
	settings.build();

	NodeBuilder nBuilder = nodeBuilder().settings(settings);
	nBuilder.local(true);

	// start it!
	Node node = nBuilder.build().start();

	System.out.println("Started Elastic Search Server");

```

=====

How can I pass these configuration options, when using the Java API  
directly?

Thanks.

On Jun 1, 11:07 am, Weiwei Wang [ww.wang...@gmail.com](mailto:ww.wang...@gmail.com) wrote:

> {  
> "cluster":{  
> "name":"elasticsearch"  
> },  
> "gateway":{  
> "recover\_after\_nodes": 1,  
> "recover\_after\_time": "5m",  
> "expected\_nodes": 2  
> },  
> "index" : {  
> "number\_of\_shards":3,  
> "number\_of\_replicas":2,  
> }
> 
> }
> 
> On Jun 1, 3:17 pm, paranoiabla [paranoia...@gmail.com](mailto:paranoia...@gmail.com) wrote:
> 
> > Hi guys,
> 
> > Initially if you just start an Elasticsearch server and try to create  
> > an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
> > How can I configure this? I know that I can send a JSON / Text  
> > initially when I am creating a new index but I don't want every time  
> > when a new index is created to specify the shards/replicas I want  
> > initially to use different values than 5 shards and 2 replicas.
> 
> > Thank you.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 1, 2011, 10:56am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/4 "2011-06-01T10:56:22Z")

</div>

Put in the the settings for the node.

On Wednesday, June 1, 2011 at 11:27 AM, paranoiabla wrote:

> Ok,
> 
> I saw that there is a config folder when you download the standalone  
> Elasticsearch. And inside this config folder there is a file :  
> elasticsearch.yml where I can specify these values. This all is great  
> BUT in my case I am using a standalone server started from a Java  
> class, like below:
> 
> ======  
> public static void main(String args) {  
> System.out.println("Starting Elastic Search Server");
> 
> Builder settings = ImmutableSettings.settingsBuilder();  
> // here you can set the node and index settings via API  
> settings.build();
> 
> NodeBuilder nBuilder = nodeBuilder().settings(settings);  
> nBuilder.local(true);
> 
> // start it!  
> Node node = nBuilder.build().start();
> 
> # System.out.println("Started Elastic Search Server");
> 
> How can I pass these configuration options, when using the Java API  
> directly?
> 
> Thanks.
> 
> On Jun 1, 11:07 am, Weiwei Wang \<[ww.wang...@gmail.com](mailto:ww.wang...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > {  
> > "cluster":{  
> > "name":"elasticsearch"  
> > },  
> > "gateway":{  
> > "recover\_after\_nodes": 1,  
> > "recover\_after\_time": "5m",  
> > "expected\_nodes": 2  
> > },  
> > "index" : {  
> > "number\_of\_shards":3,  
> > "number\_of\_replicas":2,  
> > }
> > 
> > }
> > 
> > On Jun 1, 3:17 pm, paranoiabla \<[paranoia...@gmail.com](mailto:paranoia...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Hi guys,
> > 
> > > Initially if you just start an Elasticsearch server and try to create  
> > > an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
> > > How can I configure this? I know that I can send a JSON / Text  
> > > initially when I am creating a new index but I don't want every time  
> > > when a new index is created to specify the shards/replicas I want  
> > > initially to use different values than 5 shards and 2 replicas.
> > 
> > > Thank you.

---

<div class="post-metadata">

### Author: ![paranoiabla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paranoiabla/32/2160_2.png) [@paranoiabla](https://discuss.elastic.co/u/paranoiabla)
#### Post date: [June 1, 2011, 1:56pm UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/5 "2011-06-01T13:56:57Z")

</div>

Hi Shay,

From node.settings() I can only read the settings values but I cannot  
change them - there are only getter methods. Can you show a snippet -  
maybe I don't understanding correctly.

Cheers, Petar.

On Jun 1, 1:56 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Put in the the settings for the node.
> 
> On Wednesday, June 1, 2011 at 11:27 AM, paranoiabla wrote:
> 
> > Ok,
> 
> > I saw that there is a config folder when you download the standalone  
> > Elasticsearch. And inside this config folder there is a file :  
> > elasticsearch.yml where I can specify these values. This all is great  
> > BUT in my case I am using a standalone server started from a Java  
> > class, like below:
> 
> > ======  
> > public static void main(String args) {  
> > System.out.println("Starting Elastic Search Server");
> 
> > Builder settings = ImmutableSettings.settingsBuilder();  
> > // here you can set the node and index settings via API  
> > settings.build();
> 
> > NodeBuilder nBuilder = nodeBuilder().settings(settings);  
> > nBuilder.local(true);
> 
> > // start it!  
> > Node node = nBuilder.build().start();
> 
> > # System.out.println("Started Elastic Search Server");
> 
> > How can I pass these configuration options, when using the Java API  
> > directly?
> 
> > Thanks.
> 
> > On Jun 1, 11:07 am, Weiwei Wang \<[ww.wang...@gmail.com](mailto:ww.wang...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > {  
> > > "cluster":{  
> > > "name":"elasticsearch"  
> > > },  
> > > "gateway":{  
> > > "recover\_after\_nodes": 1,  
> > > "recover\_after\_time": "5m",  
> > > "expected\_nodes": 2  
> > > },  
> > > "index" : {  
> > > "number\_of\_shards":3,  
> > > "number\_of\_replicas":2,  
> > > }
> 
> > > }
> 
> > > On Jun 1, 3:17 pm, paranoiabla \<[paranoia...@gmail.com](mailto:paranoia...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > > > Hi guys,
> 
> > > > Initially if you just start an Elasticsearch server and try to create  
> > > > an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
> > > > How can I configure this? I know that I can send a JSON / Text  
> > > > initially when I am creating a new index but I don't want every time  
> > > > when a new index is created to specify the shards/replicas I want  
> > > > initially to use different values than 5 shards and 2 replicas.
> 
> > > > Thank you.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 1, 2011, 2:27pm UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/6 "2011-06-01T14:27:29Z")

</div>

Its already in your code (the comment you have), I added a sample:

Builder settings = ImmutableSettings.settingsBuilder();  
// here you can set the node and index settings via API  
settings.put("index.number\_of\_shards", 1);  
settings.build();

NodeBuilder nBuilder = nodeBuilder().settings(settings);

On Wednesday, June 1, 2011 at 4:56 PM, paranoiabla wrote:

> Hi Shay,
> 
> From node.settings() I can only read the settings values but I cannot  
> change them - there are only getter methods. Can you show a snippet -  
> maybe I don't understanding correctly.
> 
> Cheers, Petar.
> 
> On Jun 1, 1:56 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > Put in the the settings for the node.
> > 
> > On Wednesday, June 1, 2011 at 11:27 AM, paranoiabla wrote:
> > 
> > > Ok,
> > 
> > > I saw that there is a config folder when you download the standalone  
> > > Elasticsearch. And inside this config folder there is a file :  
> > > elasticsearch.yml where I can specify these values. This all is great  
> > > BUT in my case I am using a standalone server started from a Java  
> > > class, like below:
> > 
> > > ======  
> > > public static void main(String args) {  
> > > System.out.println("Starting Elastic Search Server");
> > 
> > > Builder settings = ImmutableSettings.settingsBuilder();  
> > > // here you can set the node and index settings via API  
> > > settings.build();
> > 
> > > NodeBuilder nBuilder = nodeBuilder().settings(settings);  
> > > nBuilder.local(true);
> > 
> > > // start it!  
> > > Node node = nBuilder.build().start();
> > 
> > > # System.out.println("Started Elastic Search Server");
> > 
> > > How can I pass these configuration options, when using the Java API  
> > > directly?
> > 
> > > Thanks.
> > 
> > > On Jun 1, 11:07 am, Weiwei Wang \<[ww.wang...@gmail.com](mailto:ww.wang...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > > 
> > > > {  
> > > > "cluster":{  
> > > > "name":"elasticsearch"  
> > > > },  
> > > > "gateway":{  
> > > > "recover\_after\_nodes": 1,  
> > > > "recover\_after\_time": "5m",  
> > > > "expected\_nodes": 2  
> > > > },  
> > > > "index" : {  
> > > > "number\_of\_shards":3,  
> > > > "number\_of\_replicas":2,  
> > > > }
> > 
> > > > }
> > 
> > > > On Jun 1, 3:17 pm, paranoiabla \<[paranoia...@gmail.com](mailto:paranoia...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > > > Hi guys,
> > 
> > > > > Initially if you just start an Elasticsearch server and try to create  
> > > > > an index you will get 5 shards and 2 replicas (I hope I am not wrong).  
> > > > > How can I configure this? I know that I can send a JSON / Text  
> > > > > initially when I am creating a new index but I don't want every time  
> > > > > when a new index is created to specify the shards/replicas I want  
> > > > > initially to use different values than 5 shards and 2 replicas.
> > 
> > > > > Thank you.

---

<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 6, 2017, 4:05am UTC](https://discuss.elastic.co/t/specifying-default-replicas-and-shards-for-an-index/4515/7 "2017-07-06T04:05:01Z")

</div>


