# Set shards and replicas when creating index?

**URL:** https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772
**Category:** Elasticsearch
**Created:** [February 21, 2012, 4:48pm UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772 "2012-02-21T16:48:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)
#### Post date: [February 21, 2012, 4:48pm UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772/1 "2012-02-21T16:48:47Z")

</div>

Hi,

I have some Java code that creates an index using CreateIndexRequest.

I would like to specify the number of shards and replicas per shard  
when I create the index, however I cannot see any way to set these  
properties on CreateIndexRequest.

I do see a generic "settings" property, but there is no documentation  
in the Javadocs to tell me what the valid settings are, so I have no  
way of knowing what to put here.

Can someone help me out?

Thanks,  
Frank

---

<div class="post-metadata">

### Author: ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)
#### Post date: [February 21, 2012, 4:54pm UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772/2 "2012-02-21T16:54:02Z")

</div>

Is this the right way?

CreateIndexRequest createRequest = new CreateIndexRequest(INDEX\_NAME);  
Settings indexSettings =  
ImmutableSettings.settingsBuilder().put("number\_of\_shards",  
NUMBER\_OF\_SHARDS).put("number\_of\_replicas",  
NUMBER\_OF\_REPLICAS).build();  
createRequest.settings(indexSettings);

On Feb 21, 10:48 am, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:

> Hi,
> 
> I have some Java code that creates an index using CreateIndexRequest.
> 
> I would like to specify the number of shards and replicas per shard  
> when I create the index, however I cannot see any way to set these  
> properties on CreateIndexRequest.
> 
> I do see a generic "settings" property, but there is no documentation  
> in the Javadocs to tell me what the valid settings are, so I have no  
> way of knowing what to put here.
> 
> Can someone help me out?
> 
> Thanks,  
> Frank

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [February 21, 2012, 4:55pm UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772/3 "2012-02-21T16:55:25Z")

</div>

On Tue, 2012-02-21 at 08:48 -0800, Frank LaRosa wrote:

> Hi,
> 
> I have some Java code that creates an index using CreateIndexRequest.
> 
> I would like to specify the number of shards and replicas per shard  
> when I create the index, however I cannot see any way to set these  
> properties on CreateIndexRequest.
> 
> I do see a generic "settings" property, but there is no documentation  
> in the Javadocs to tell me what the valid settings are, so I have no  
> way of knowing what to put here.

Have a look at  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/) plus the  
other pages linked to in the right column menu

clint

---

<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: [February 22, 2012, 12:04am UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772/4 "2012-02-22T00:04:57Z")

</div>

Yes, this will work.

On Tuesday, February 21, 2012 at 6:54 PM, Frank LaRosa wrote:

> Is this the right way?
> 
> CreateIndexRequest createRequest = new CreateIndexRequest(INDEX\_NAME);  
> Settings indexSettings =  
> ImmutableSettings.settingsBuilder().put("number\_of\_shards",  
> NUMBER\_OF\_SHARDS).put("number\_of\_replicas",  
> NUMBER\_OF\_REPLICAS).build();  
> createRequest.settings(indexSettings);
> 
> On Feb 21, 10:48 am, Frank LaRosa \<[fr...@studyblue.com](mailto:fr...@studyblue.com) ([http://studyblue.com](http://studyblue.com))\> wrote:
> 
> > Hi,
> > 
> > I have some Java code that creates an index using CreateIndexRequest.
> > 
> > I would like to specify the number of shards and replicas per shard  
> > when I create the index, however I cannot see any way to set these  
> > properties on CreateIndexRequest.
> > 
> > I do see a generic "settings" property, but there is no documentation  
> > in the Javadocs to tell me what the valid settings are, so I have no  
> > way of knowing what to put here.
> > 
> > Can someone help me out?
> > 
> > Thanks,  
> > Frank

---

<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, 3:38am UTC](https://discuss.elastic.co/t/set-shards-and-replicas-when-creating-index/6772/5 "2017-07-06T03:38:38Z")

</div>


