Skip to content
Advertisement

Multiple Elasticsearch connections in a program

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?

Advertisement

Answer

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

JavaScript

Create client B

JavaScript

You should have 2 configurations for cluster A and B, which is read by client creation code.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement