Custom routing Java example

Hi,

Can anyone provide an example on how custom routing on a path can be
achieved via the java API?

Here is how I create my index:

HashMap<String, Object> settings = new HashMap<String, Object>();
settings.put("number_of_shards", noShards);
settings.put("number_of_replicas", noReplicas);
CreateIndexRequestBuilder createIndexRequestBuilder =
esClient.admin().indices().prepareCreate(name);
createIndexRequestBuilder.setSettings(settings);
CreateIndexResponse createIndexResponse =
createIndexRequestBuilder.execute().actionGet();
LOG.debug("Index " + name + " created: " +
createIndexResponse.isAcknowledged());

Thank you!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

You can specify a path for your custom routing in your mapping. The
documents will need to contain it in a specific field. Have a look at the routing
field http://www.elasticsearch.org/guide/reference/mapping/routing-field/docs, path section.
You need to add the mapping to your create index request using the
addMapping method.

On Tuesday, September 10, 2013 11:39:57 AM UTC+2, Elod Balazs wrote:

Hi,

Can anyone provide an example on how custom routing on a path can be
achieved via the java API?

Here is how I create my index:

HashMap<String, Object> settings = new HashMap<String, Object>();
settings.put("number_of_shards", noShards);
settings.put("number_of_replicas", noReplicas);
CreateIndexRequestBuilder createIndexRequestBuilder =
esClient.admin().indices().prepareCreate(name);
createIndexRequestBuilder.setSettings(settings);
CreateIndexResponse createIndexResponse =
createIndexRequestBuilder.execute().actionGet();
LOG.debug("Index " + name + " created: " +
createIndexResponse.isAcknowledged());

Thank you!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Luca - Actually I read somewhere that specifying a routing value using
"path" parameter is expensive since the document needs to be parsed to
retrieve that routing value (apart from the parsing that would be done when
putting it into index). Hence it was recommended to specify routing as a
query param in the url.

Pl let me know what you think!

-Amit.

On Tue, Sep 10, 2013 at 10:15 AM, Luca Cavanna cavannaluca@gmail.comwrote:

You can specify a path for your custom routing in your mapping. The
documents will need to contain it in a specific field. Have a look at the routing
fieldhttp://www.elasticsearch.org/guide/reference/mapping/routing-field/docs, path section.
You need to add the mapping to your create index request using the
addMapping method.

On Tuesday, September 10, 2013 11:39:57 AM UTC+2, Elod Balazs wrote:

Hi,

Can anyone provide an example on how custom routing on a path can be
achieved via the java API?

Here is how I create my index:

HashMap<String, Object> settings = new HashMap<String, Object>();
settings.put("number_of_**shards", noShards);
settings.put("number_of_**replicas", noReplicas);
CreateIndexRequestBuilder createIndexRequestBuilder =
esClient.admin().indices().prepareCreate(name);
createIndexRequestBuilder.setSettings(settings);
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.

execute().actionGet();
LOG.debug("Index " + name + " created: " + createIndexResponse.

isAcknowledged());

Thank you!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,
that is true. In a distributed environment, you can send your index
requests to any node in the cluster. Based on the id or the custom routing,
that node will forward the request to all the other nodes where the
document is supposed to be indexed (nodes that hold its primary shard and
all the replicas). That happens without needing to parse the document on
the node that receives the request, unless you have the id or the routing
specified as path in the document itself. It's just an additional step that
needs to happen to determine where the document needs to be sent, not a big
deal since we do pull parsing but still, if you can pass the routing as a
parameter, outside of your document, that's the most recommended way to do
it.

Cheers
Luca

On Wed, Sep 11, 2013 at 2:44 AM, Amit Soni amitsoni29@gmail.com wrote:

Hi Luca - Actually I read somewhere that specifying a routing value using
"path" parameter is expensive since the document needs to be parsed to
retrieve that routing value (apart from the parsing that would be done when
putting it into index). Hence it was recommended to specify routing as a
query param in the url.

Pl let me know what you think!

-Amit.

On Tue, Sep 10, 2013 at 10:15 AM, Luca Cavanna cavannaluca@gmail.comwrote:

You can specify a path for your custom routing in your mapping. The
documents will need to contain it in a specific field. Have a look at the routing
fieldhttp://www.elasticsearch.org/guide/reference/mapping/routing-field/docs, path section.
You need to add the mapping to your create index request using the
addMapping method.

On Tuesday, September 10, 2013 11:39:57 AM UTC+2, Elod Balazs wrote:

Hi,

Can anyone provide an example on how custom routing on a path can be
achieved via the java API?

Here is how I create my index:

HashMap<String, Object> settings = new HashMap<String, Object>();
settings.put("number_of_**shards", noShards);
settings.put("number_of_**replicas", noReplicas);
CreateIndexRequestBuilder createIndexRequestBuilder =
esClient.admin().indices().prepareCreate(name);
createIndexRequestBuilder.setSettings(settings);
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.

execute().actionGet();
LOG.debug("Index " + name + " created: " + createIndexResponse.

isAcknowledged());

Thank you!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/waIu6oZKghk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.