# Index Routing does not work with Transport Client

**URL:** <https://discuss.elastic.co/t/index-routing-does-not-work-with-transport-client/9109>\
**Category:** Elasticsearch\
**Created:** [September 23, 2012, 12:06pm UTC](https://discuss.elastic.co/t/index-routing-does-not-work-with-transport-client/9109 "2012-09-23T12:06:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Amit](https://discuss.elastic.co/u/Amit)\
**Post date:** [September 23, 2012, 12:06pm UTC](https://discuss.elastic.co/t/index-routing-does-not-work-with-transport-client/9109/1 "2012-09-23T12:06:39Z")

</div>

All,

I am using elastic search version 0.19.4.

My requirement is to index the documents to a particular node and exclude  
the rest of the nodes. Hence for multiple index requests. I would manage  
which node the index should go to.

I tried the index routing mechanism but this does not seem to work with the  
version mentioned above.

My test scenario;  
1- started 3 ES nodes with node.tag: node1 , node.tag: node2 and node.tag:  
node3 respectively.  
2- I am using transport client to communicate the ES nodes.  
3- I am using bulk index api to index the document.  
4- None of the api available with Transport Client or Bulk request allow me  
to hook the index.routing.allocation.include.tag orindex.routing  
.allocation.exclude.tag.  
5- Used UpdateSettingsRequest but it did not help either.

Sample code;  
Settings s =  
ImmutableSettings.settingsBuilder().put("testRouting").put("client.transport.sniff",  
true).build();  
TransportClient tc = new TransportClient(s);  
tc.addTransportAddress(new  
InetSocketTransportAddress("192.168.1.2", 9300));  
tc.addTransportAddress(new  
InetSocketTransportAddress("192.168.1.2", 9301));  
tc.addTransportAddress(new  
InetSocketTransportAddress("192.168.1.2", 9302));

```
            UpdateSettingsRequest updateSettings = new 

```

UpdateSettingsRequest();  
HashMap\<String, String\> hashMap = new HashMap\<String,  
String\>();  
hashMap.put("index.routing.allocation.include.tag","node1"  
) ;  
hashMap.put("index.routing.allocation.exclude.tag","node2,node3"  
) ;  
hashMap.put("index.routing.allocation.total\_shards\_per\_node",  
"3");  
String[] indices = new String[1];  
indices[0] ="test\*";  
updateSettings.indices(indices);  
updateSettings.settings(hashMap);

```
            while (true) { 
                    BulkRequestBuilder bulkRequest = tc.prepareBulk(); 
                    for (int i = 0; i < 3; i++) { 
                            System.out.println( "------" + i); 
                            bulkRequest.add(Requests.indexRequest("test" 

```

- i).type("type").source("field", "value"));

Please suggest if I am missing something or the feature is not in 0.19.4.  
If not how can I make to work with the available scenario.

Thanks  
Amit

I have tried the other option as well to update the settings via  
client\>admin\>indices\>updatesettings but even than I am not able to rout;

UpdateSettingsRequest updateSettings = new UpdateSettingsRequest();  
HashMap\<String, String\> hashMap = new HashMap\<String,  
String\>();  
hashMap.put("index.routing.allocation.include.tag","node1"  
) ;  
hashMap.put("index.routing.allocation.exclude.tag","node2,node3"  
) ;  
hashMap.put("index.routing.allocation.total\_shards\_per\_node",  
"3");  
updateSettings.settings(hashMap);  
String[] indices = new String[3];  
indices[0] ="test0";  
indices[1] ="test1";  
indices[2] ="test2";  
updateSettings.indices(indices);

tc.admin().indices().updateSettings(updateSettings).actionGet();

--

---

<div class="post-metadata">

**Author:** ![Amit](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Amit](https://discuss.elastic.co/u/Amit)\
**Post date:** [September 24, 2012, 2:54pm UTC](https://discuss.elastic.co/t/index-routing-does-not-work-with-transport-client/9109/2 "2012-09-24T14:54:04Z")

</div>

Hello Shay,

I further explored the ES documents( ES site and google search results) and  
the ES google group but I could not find a direct example/sample of  
Transport client , Bulk Indexing and index allocation routing combination .

I looked into the test classes and tried other way what ever I can. To  
build the above mentioned scenario.

I tried IndexMetaBuilder to build the new index meta and pass it to create  
Index api. I also tried Routing api, as follows;

//IndexMetaData metaData = new IndexMetaData();

MetaData metaData = _newMetaDataBuilder_()

.put(_newIndexMetaDataBuilder_("test13").settings(_settingsBuilder_()

.put("index.number\_of\_shards", 4)

.put("index.number\_of\_replicas", 0)

//.put("index.routing.allocation.include.tag", "node3")

.put("index.routing.allocation.exclude.\_ip", "192.168.1.102")

.build()))

.build();

//metaData.

AllocationService strategy = _new_ AllocationService(_settingsBuilder_()

.build());

RoutingTable routingTable = _routingTable_()

.add(_indexRoutingTable_("test13").initializeEmpty(metaData.index("test13"  
)))

.build();

ClusterState clusterState = _newClusterStateBuilder_  
().metaData(metaData).routingTable(routingTable).build();

BulkRequestBuilder bulkRequest = tc.prepareBulk();

_for_ (_int_ i = 0; i \< 3; i++) {

System._out_.println( "------" + i);

IndexRequest source = Requests._indexRequest_("test-13" ).type("type"  
).source("field", "value");

MappingMetaData mappingMd = _null_;

_if_ (metaData.hasIndex(source.index())) {

mappingMd = metaData.index(source.index()).mapping(source.type());

}

source.process(metaData, "test-13" , mappingMd, _false_);

bulkRequest.add(source);

}

bulkRequest.execute().actionGet();  
But none of the option seems to work. The index is created in all the nodes  
and shards distribute across the all the nodes.

I apologizes if my question is very basic, And I am overlooking or  
misunderstood the concept. Please suggest.

Thanks  
Amit

On Sunday, September 23, 2012 5:36:39 PM UTC+5:30, Amit Singh wrote:

> All,
> 
> I am using Elasticsearch version 0.19.4.
> 
> My requirement is to index the documents to a particular node and exclude  
> the rest of the nodes. Hence for multiple index requests. I would manage  
> which node the index should go to.
> 
> I tried the index routing mechanism but this does not seem to work with  
> the version mentioned above.
> 
> My test scenario;  
> 1- started 3 ES nodes with node.tag: node1 , node.tag: node2 and  
> node.tag: node3 respectively.  
> 2- I am using transport client to communicate the ES nodes.  
> 3- I am using bulk index api to index the document.  
> 4- None of the api available with Transport Client or Bulk request allow  
> me to hook the index.routing.allocation.include.tag orindex.routing  
> .allocation.exclude.tag.  
> 5- Used UpdateSettingsRequest but it did not help either.
> 
> Sample code;  
> Settings s =  
> ImmutableSettings.settingsBuilder().put("testRouting").put("client.transport.sniff",  
> true).build();  
> TransportClient tc = new TransportClient(s);  
> tc.addTransportAddress(new  
> InetSocketTransportAddress("192.168.1.2", 9300));  
> tc.addTransportAddress(new  
> InetSocketTransportAddress("192.168.1.2", 9301));  
> tc.addTransportAddress(new  
> InetSocketTransportAddress("192.168.1.2", 9302));
> 
> ```
> UpdateSettingsRequest updateSettings = new 
> 
> ```
> 
> UpdateSettingsRequest();  
> HashMap\<String, String\> hashMap = new HashMap\<String,  
> String\>();  
> hashMap.put("index.routing.allocation.include.tag","node1"  
> ) ;  
> hashMap.put("index.routing.allocation.exclude.tag","node2,node3"  
> ) ;  
> hashMap.put("index.routing.allocation.total\_shards\_per\_node",  
> "3");  
> String indices = new String[1];  
> indices[0] ="test\*";  
> updateSettings.indices(indices);  
> updateSettings.settings(hashMap);
> 
> ```
> while (true) { 
> BulkRequestBuilder bulkRequest = tc.prepareBulk(); 
> for (int i = 0; i < 3; i++) { 
> System.out.println( "------" + i); 
> bulkRequest.add(Requests.indexRequest("test" 
> 
> ```
> 
> - i).type("type").source("field", "value"));
> 
> Please suggest if I am missing something or the feature is not in 0.19.4.  
> If not how can I make to work with the available scenario.
> 
> Thanks  
> Amit
> 
> I have tried the other option as well to update the settings via  
> client\>admin\>indices\>updatesettings but even than I am not able to rout;
> 
> UpdateSettingsRequest updateSettings = new UpdateSettingsRequest();  
> HashMap\<String, String\> hashMap = new HashMap\<String,  
> String\>();  
> hashMap.put("index.routing.allocation.include.tag","node1"  
> ) ;  
> hashMap.put("index.routing.allocation.exclude.tag","node2,node3"  
> ) ;  
> hashMap.put("index.routing.allocation.total\_shards\_per\_node",  
> "3");  
> updateSettings.settings(hashMap);  
> String indices = new String[3];  
> indices[0] ="test0";  
> indices[1] ="test1";  
> indices[2] ="test2";  
> updateSettings.indices(indices);
> 
> tc.admin().indices().updateSettings(updateSettings).actionGet();

--

---

<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, 3:11am UTC](https://discuss.elastic.co/t/index-routing-does-not-work-with-transport-client/9109/3 "2017-07-06T03:11:43Z")

</div>


