I was working on a service in which I get a searchHit from elastic cluster A and then use a field obtained from A to fetch details from elastic cluster B. I have created a class ClientFactory, which creates ES client based on values that I send. (A's or B's) But after getting details from A, I'm not able to create connection to B. I can either fetch details from A or B at one time. Any idea how to solve this problem?
Asked
Active
Viewed 1,122 times
1 Answers
1
You can create two resthighlevelclient
one which talks to cluster A
and another which talks to cluster B
, below is the sample code to show :
Create client A
RestHighLevelClient restHighLevelClientA = new RestHighLevelClient(
RestClient.builder(new HttpHost(configuration.getClusteAConfig().getHost(),
configuration.getClusteAConfig().getPort(),
"http")));
Create client B
RestHighLevelClient restHighLevelClientB = new RestHighLevelClient(
RestClient.builder(new HttpHost(configuration.getClusteBConfig().getHost(),
configuration.getClusteBConfig().getPort(),
"http")));
You should have 2 configurations for cluster A and B, which is read by client creation code.
ClusterA:
host: cluste A hosts
port: 9200
ClusterB:
host: cluste B hosts
port: 9200
-
Just a stupid doubt. Won't same port affect the connection? – Nipun Soni May 27 '20 at 03:14
-
1it's a different cluster so same port on different host won't affect each other as port is specific to a host(node) and in your case its different cluster all together. – May 27 '20 at 03:38
-
@NipunSoni also it would be great if you can upvote and accept the answer, as it solves the issue. – May 27 '20 at 03:45