Home > Back-end >  Curl call for PUT and GET query on multi-node es cluster
Curl call for PUT and GET query on multi-node es cluster

Time:12-12

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

CodePudding user response:

In a multi-node Elasticsearch cluster, you can send curl requests to any of the nodes in the cluster to fetch results by running a query. The best practice is to use the IP address of the node that is designated as the "master" node in the cluster. The master node is responsible for managing the cluster and coordinating the actions of the other nodes, so it is usually the best choice for sending queries to the cluster.

If the master node goes down, Elasticsearch will automatically elect a new master node from the remaining nodes in the cluster. In this case, you can continue to use the same IP address to send queries to the cluster, and Elasticsearch will route the queries to the new master node.

There is no need to use a load balancer or reverse proxy such as Nginx to manage the routing of queries to the Elasticsearch cluster. Elasticsearch itself is designed to handle the routing of queries to the appropriate node in the cluster, and it will automatically handle the case where the master node goes down and a new one is elected

CodePudding user response:

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.

  • Related