How to search in many cluster name?


(Ngọc Phạm) #1

sorry , im newbie and i have one question.
Default cluster name is "elasticsearch",i run and get transtport in port :9300 like this:

     Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true)
        				.put("cluster.name", "elasticsearch").build();
        		transportClient = new TransportClient(settings);
Client client = transportClient.addTransportAddress(new InetSocketTransportAddress("192.168.1.25", 9300))

But now i change cluster name is : "elasticsearch1" and i run in port :9302.

Settings settings2 = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true)
			.put("cluster.name", "elasticsearch1").build();
	transportClient2 = new TransportClient(settings2);
Client client2 = transportClient2.addTransportAddress(new InetSocketTransportAddress("192.168.1.25", 9302));

My question is : how to search in 2 client in one time if i have same index,same type, search _all field and only different database?

Thanks for your help!


(Christoph) #2

Hi,
afaik with this setup (two clients, two clusters) you need to run request on each of them independently. There is something called a Tribe Node which can connect to multiple clusters, but for your particular case this won't help much, it cannot handle indices with the same name in multiple clusters.


(Ngọc Phạm) #3

Thanks , i created cluster elasticsearch in port 9200, elasticsearch1 in 9201 and i change cluster name defaul in .yml to :elasticsearch2. After i use terminal

bin/elasticsearch --tribe.elasticsearch1.cluster.name elasticsearch1 --tribe.elasticsearch.cluster.name elasticsearch --tribe.elasticsearch.cluster.name elasticsearch 

i success creat cluster in port 9202 like you say, i can see index in cluster elasticsearch and elasticsearch1.
I can check all index exist in curl 'localhost:9202/_cat/indices?v' .

But i cant search with java , this is code i used

Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true)
				.put("cluster.name", "elasticsearch2").build();
		transportClient = new TransportClient(settings);

		Client client = transportClient.addTransportAddress(new InetSocketTransportAddress("192.168.1.25", 9301));

it only search index in one cluster.
but if i remove .put("client.transport.sniff", true)
it can search all index in 2 cluster like normal.

I readed in https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/transport-client.html . It have

  • The client allows to sniff the rest of the cluster, and add those
    into its list of machines to use. In this case, note that the IP
    addresses used will be the ones that the other nodes were started
    with (the "publish" address). In order to enable it, set the
    client.transport.sniff to true:

But i cant understand what really happen. Pls explain me :smile:

Thanks for your help !


(system) #4