# How to change numer of shards and put mapping before bulk operation using java api?

**URL:** https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054
**Category:** Elasticsearch
**Created:** [March 7, 2013, 12:13pm UTC](https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054 "2013-03-07T12:13:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)
#### Post date: [March 7, 2013, 12:13pm UTC](https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054/1 "2013-03-07T12:13:56Z")

</div>

Hi guys,

I'm using BulkRequestBuilder api to create index in bulk, but I want to  
change default number of shards and put mapping for the index, who can tell  
me which api should I choose?

My bulk code is attached:  
XContentBuilder xb = json string;  
bulkRequest.add(client.prepareIndex("test","kba", id).setSource(xb));  
\*  
\*  
I have tried the following api to change number of shards, but it will  
result some exception.  
client.admin().indices().prepareCreate("trec")  
.setSettings(ImmutableSettings.settingsBuilder().put("number\_of\_shards",  
10).put("number\_of\_replicas", "1"))  
.execute().actionGet();

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [March 7, 2013, 1:33pm UTC](https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054/2 "2013-03-07T13:33:58Z")

</div>

try "index.number\_of\_shards" and "index.number\_of\_replicas" instead.

simon

On Thursday, March 7, 2013 1:13:56 PM UTC+1, Jingang Wang wrote:

> Hi guys,
> 
> I'm using BulkRequestBuilder api to create index in bulk, but I want to  
> change default number of shards and put mapping for the index, who can tell  
> me which api should I choose?
> 
> My bulk code is attached:  
> XContentBuilder xb = json string;  
> bulkRequest.add(client.prepareIndex("test","kba", id).setSource(xb));  
> \*  
> \*  
> I have tried the following api to change number of shards, but it will  
> result some exception.  
> client.admin().indices().prepareCreate("trec")  
> .setSettings(ImmutableSettings.settingsBuilder().put("number\_of\_shards",  
> 10).put("number\_of\_replicas", "1"))  
> .execute().actionGet();
> 
> Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)
#### Post date: [March 8, 2013, 1:48pm UTC](https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054/3 "2013-03-08T13:48:01Z")

</div>

Thanks for your reply.  
I have resolved this problem.

On Thursday, March 7, 2013 9:33:58 PM UTC+8, simonw wrote:

> try "index.number\_of\_shards" and "index.number\_of\_replicas" instead.
> 
> simon
> 
> On Thursday, March 7, 2013 1:13:56 PM UTC+1, Jingang Wang wrote:
> 
> > Hi guys,
> > 
> > I'm using BulkRequestBuilder api to create index in bulk, but I want to  
> > change default number of shards and put mapping for the index, who can tell  
> > me which api should I choose?
> > 
> > My bulk code is attached:  
> > XContentBuilder xb = json string;  
> > bulkRequest.add(client.prepareIndex("test","kba", id).setSource(xb));  
> > \*  
> > \*  
> > I have tried the following api to change number of shards, but it will  
> > result some exception.  
> > client.admin().indices().prepareCreate("trec")  
> > .setSettings(ImmutableSettings.settingsBuilder().put("number\_of\_shards",  
> > 10).put("number\_of\_replicas", "1"))  
> > .execute().actionGet();
> > 
> > Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:47am UTC](https://discuss.elastic.co/t/how-to-change-numer-of-shards-and-put-mapping-before-bulk-operation-using-java-api/11054/4 "2017-07-06T02:47:32Z")

</div>


