Reputation: 55
I am new in Elastic search. I want to know how the cluster failover works in ES using NEST. I went through available links http://nest.azurewebsites.net/elasticsearch-net/cluster-failover.html and http://nest.azurewebsites.net/elasticsearch-net/connecting.html. But it is not much clear for me.
Suppose i have two nodes. Node1(10.20.2.1:9203) and node2(10.20.2.2:9204). Both nodes are connected to single cluster 'TestCluster'. My requirement is that, if any of the node is down, i want to get the data from live node.
My config file for Node1(10.20.2.1:9203) is as follows
cluster.name: TestCluster
node.name: "Node1"
node.master: true
node.data: true
network.host: 10.20.2.1
http.port: 9203
My config file for Node2(10.20.2.2:9204) is as follows
cluster.name: TestCluster
node.name: "Node2"
node.master: false
node.data: true
network.host: 10.20.2.2
http.port: 9204
I am accessing the ES client as follows
private static ElasticClient ElasticClientNew
{
get
{
var node = new Uri("http://10.20.2.1:9203");
var node1 = new Uri("http://10.20.2.2:9204");
var connectionPool = new SniffingConnectionPool(new[] { node, node1 });
var setting = new ConnectionSettings(connectionPool)
.SniffOnConnectionFault(false)
.SniffOnStartup(false)
.SniffLifeSpan(TimeSpan.FromMinutes(1));
return new ElasticClient(setting);
}
}
I am using this ES client for searching as follows
var result = ElasticClientNew.Search<Attendance>(s => s
.From(0)
.Size(5000)
.Index("attendance").Type("Worker"));
I am running the MVS application from node1, and elasticsearch service is stopped in this machine. But the ES service is running in node2. When i try to search, am getting error as follows
Failed after retrying 1 times: 'POST attendance/Worker/_search'.
InnerException: PingException, InnerMessage: Pinging http://10.20.2.1:9203 caused an exception, InnerStackTrace: at Elasticsearch.Net.Connection.Transport.Ping(ITransportRequestState requestState) in c:\Users\gmarz\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 96
at Elasticsearch.Net.Connection.Transport.DoRequest[T](TransportRequestState`1 requestState) in c:\Users\gmarz\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 334
Please suggest how the cluster failover can be achieved in my application.
Upvotes: 2
Views: 2425
Reputation: 1
I have similar issue:
When I tried connecting using StaticConnection pool, I am getting following error:
An unhandled exception of type 'Elasticsearch.Net.Exceptions.MaxRetryException' occurred in Elasticsearch.Net.dll
Additional information: Failed after retrying 0 times: 'POST els_logentries/logentries/_search'.
AS I Run again, It works fine.
var node1 = new Uri("http://192.168.115.102:9200");
var node2 = new Uri("http://192.168.115.102:9200");
var connectionPool = new StaticConnectionPool(new List<Uri>() { node1,node2});
var settings = new ConnectionSettings(connectionPool, defaultIndex: "els_logentries");
ElasticClient client = new ElasticClient(settings);
var results = client.Search<Logentries>(s => s
.Type("logentries")
.Query(q=>q
.Bool(bq=>bq
.Must(
mq=>mq.MatchAll()
) )));
Upvotes: 0
Reputation: 13536
The problem is that only one of the nodes has
node.master: true
set so when that node goes down the other node is masterless
and turns off as well.
Upvotes: 1