Index Routing does not work with Transport Client


(Amit) #1

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 or index.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"));

		}
		bulkRequest.execute().actionGet();
	}

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


(system) #2