Check if elasticsearch nodes are alive on startup using nest


#1

Hi,

I'm using Nest 5.x as a part of an application to communicate with ES. When my application starts up, the following code is executed

List<Node> nodes = new List<Node>();

nodes.AddRange(config.Nodes.Select(nodeUri => CreateNode(nodeUri)));

var connectionPool = new SniffingConnectionPool(nodes);
var settings = new ConnectionSettings(connectionPool);
    			
settings.DefaultFieldNameInferrer(p => p);

Nest.ElasticClient esClient = new Nest.ElasticClient(settings);

If my ES instance (nodeUri) is not up and running, the above code will not throw any exception during the startup, but when I actually try to index a document, then it throws an exception.

Is there any way I can ensure that nodes I'm trying to connect are active during start up itself?

Thanks


(Russ Cam) #2

With SniffingConnectionPool

  1. the state of the cluster is sniffed on startup and the pool of nodes that the client can use to make requests against is reseeded with the nodes returned in the sniffing response.
  2. A node is pinged when it is used for the first time as a quick way of ascertaining it is healthy.

So the default behaviour of the client with SniffingConnectionPool should already be doing what you'd like to do. Is this not what you're seeing? If not, what does the audit trail look like for indexing the document?


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.