Set shards and replicas when creating index?


(Frank LaRosa) #1

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


(Frank LaRosa) #2

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 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


(Clinton Gormley) #3

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
http://www.elasticsearch.org/guide/reference/index-modules/ plus the
other pages linked to in the right column menu

clint


(Shay Banon) #4

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 (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


(system) #5