Specifying default replicas and shards for an index


(paranoiabla) #1

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.


(Weiwei Wang) #2

{
"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 wrote:

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.


(paranoiabla) #3

Ok,

I saw that there is a config folder when you download the standalone
elastic search. 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 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 wrote:

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.


(Shay Banon) #4

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
elastic search. 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 (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 (http://gmail.com)> wrote:

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.


(paranoiabla) #5

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 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
elastic search. 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 (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 (http://gmail.com)> wrote:

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.


(Shay Banon) #6

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 (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
elastic search. 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 (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 (http://gmail.com)> wrote:

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.


(system) #7