Configuring number of shards and replica using Java API

Hello,

How do I configure the above using Java API just before the below
statement is called ?

IndexResponse response = _client.prepareIndex(obj.get_srch_index(),
obj.get_srch_name(),obj.get_srch_Id())
.setSource(sourceString)
.execute()
.actionGet();
System.out.println(response.id());

Percival

--

The number of shards and replicas are part of the source object you
pass in. I prefer to use CreateIndexRequests over using the
IndexRequestBuilder directly. The number of shards and replicas are
specified in the settings object that is passed into the
CreateIndexRequest.

Settings settings =
ImmutableSettings.settingsBuilder().put("number_of_shards",
shards).build();

client.admin().indices().create(createIndexRequest).actionGet();

Cheers,

Ivan

P.S. When using Java, you should follow the Java Style Guidelines.

On Tue, Sep 25, 2012 at 4:56 AM, Percival Xavier
xavier.percival@gmail.com wrote:

Hello,

How do I configure the above using Java API just before the below statement
is called ?

IndexResponse response = _client.prepareIndex(obj.get_srch_index(),
obj.get_srch_name(),obj.get_srch_Id())
.setSource(sourceString)
.execute()
.actionGet();
System.out.println(response.id());

Percival

--

--

Percival,

Here is another example that uses CreateIndexRequestBuilder that Ivan
mentioned:

client.admin().indices().prepareCreate("test")

.setSettings(ImmutableSettings.settingsBuilder().put("number_of_shards",
2).put("number_of_replicas", "0"))
.execute().actionGet();

By the way, you can learn a lot about using Java API by looking at the
integration tests of elasticsearch.

Igor

On Tuesday, September 25, 2012 12:23:02 PM UTC-4, Ivan Brusic wrote:

The number of shards and replicas are part of the source object you
pass in. I prefer to use CreateIndexRequests over using the
IndexRequestBuilder directly. The number of shards and replicas are
specified in the settings object that is passed into the
CreateIndexRequest.

Settings settings =
ImmutableSettings.settingsBuilder().put("number_of_shards",
shards).build();

client.admin().indices().create(createIndexRequest).actionGet();

Cheers,

Ivan

P.S. When using Java, you should follow the Java Style Guidelines.

On Tue, Sep 25, 2012 at 4:56 AM, Percival Xavier
<xavier....@gmail.com <javascript:>> wrote:

Hello,

How do I configure the above using Java API just before the below
statement
is called ?

IndexResponse response = _client.prepareIndex(obj.get_srch_index(),
obj.get_srch_name(),obj.get_srch_Id())
.setSource(sourceString)
.execute()
.actionGet();
System.out.println(response.id());

Percival

--

--

Thanks for demonstrating another way with the API. My example code is
actually incomplete since I did not show how to create the actual
request with the settings!

createIndexRequest = new CreateIndexRequest(indexName, settings);

--
Ivan

On Tue, Sep 25, 2012 at 11:56 AM, Igor Motov imotov@gmail.com wrote:

Percival,

Here is another example that uses CreateIndexRequestBuilder that Ivan
mentioned:

client.admin().indices().prepareCreate("test")
.setSettings(ImmutableSettings.settingsBuilder().put("number_of_shards",
2).put("number_of_replicas", "0"))
.execute().actionGet();

By the way, you can learn a lot about using Java API by looking at the
integration tests of elasticsearch.

Igor

On Tuesday, September 25, 2012 12:23:02 PM UTC-4, Ivan Brusic wrote:

The number of shards and replicas are part of the source object you
pass in. I prefer to use CreateIndexRequests over using the
IndexRequestBuilder directly. The number of shards and replicas are
specified in the settings object that is passed into the
CreateIndexRequest.

Settings settings =
ImmutableSettings.settingsBuilder().put("number_of_shards",
shards).build();

client.admin().indices().create(createIndexRequest).actionGet();

Cheers,

Ivan

P.S. When using Java, you should follow the Java Style Guidelines.

On Tue, Sep 25, 2012 at 4:56 AM, Percival Xavier
xavier....@gmail.com wrote:

Hello,

How do I configure the above using Java API just before the below
statement
is called ?

IndexResponse response = _client.prepareIndex(obj.get_srch_index(),
obj.get_srch_name(),obj.get_srch_Id())
.setSource(sourceString)
.execute()
.actionGet();
System.out.println(response.id());

Percival

--

--

--