Jimmy
Jimmy

Reputation: 27

Curl call for PUT and GET query on multi-node es cluster

I would like to know on a multi-node Elasticsearch cluster (3 nodes), to which node we can send curl call to fetch some results (by running query)?

If we can use any node IP what is can be the best practice? , for example, if I am using node 1's URL from "node 1, node 2, and node 3", let's say node 1 goes down, I have to manually update the query URL to "node 2 or node 3" is their way so that I can have one centralized URL which does itself.

Do I have to manually do it using Nginx or load balancer, Or there is something in the elastic search itself

Upvotes: 0

Views: 248

Answers (1)

Amit
Amit

Reputation: 32376

Although in ES if you send the request to any node, that is part of a valid ES cluster, it will route the request internally and provide you the result.

But You shouldn't use the directly node ip to communicate with the Elasticsearch for obvious reasons and one of that you already mentioned. You can use the load balancer, ngnix or DNS for your Elasticsearch cluster.

But if you are accessing it programmatically you don't need this also, while creating the Elasticsearch clients, you can specify all the nodes ip in Elasticsearch client, this way even when some nodes are down still your request will not fail.

RestClientBuilder restClientBuilder = RestClient.builder(
                new HttpHost(esConfig.getHost(), esConfig.getPort()), new HttpHost(esConfig.getHost2(), esConfig.getPort2()));

As you can see i created my Elasticsearch client(works with Elasticsearch 8.5) WITH two Elasticsearch hosts.

Upvotes: 1

Related Questions