我尝试设置2个elasticsearch节点并进行测试,它们是在本地计算机上设置的。有了这个设置。
cluster.name: TestCluster
node.name: "Node1"
node.master: true
node.data: true
network.host: 127.0.0.1
http.port: 9200
cluster.name: CMTCluster
node.name: "Node2"
node.master: true
node.data: true
network.host: 127.0.0.1
http.port: 9201
使用普通连接时,指向任一节点时一切正常。
var node1 = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node1, "document");
var client = new ElasticClient(settings);
var result = client.Search<Customer>(s => s
.Query(q => q.Match(m => m.Query("Abse").OnField(p => p.FullName))));
当使用具有静态连接池的客户端时,一切都会分崩离析。
var node1 = new Uri("http://localhost:9200");
var node2 = new Uri("http://localhost:9201");
var connectionPool = new StaticConnectionPool(new[] { node1, node2 });
var settings = new ConnectionSettings(connectionPool, "cmt-zurich-steva");
var client = new ElasticClient(settings);
var result = client.Search<Customer>(s => s
.Query(q => q.Match(m => m.Query("Abse").OnField(p => p.FullName))));
例外是:
Failed after retrying 1 times: 'POST document/customer/_search'.
InnerException: PingException, InnerMessage: Pinging http://localhost:9201/ caused an exception, InnerStackTrace: at Elasticsearch.Net.Connection.Transport.Elasticsearch.Net.Connection.ITransportDelegator.Ping(ITransportRequestState requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 108
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.SelectNextNode[T](TransportRequestState`1 requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 45
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.CoordinateRequest[T](TransportRequestState`1 requestState, Int32 maxRetries, Int32 retried, Boolean& aliveResponse) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 117
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.DoRequest[T](TransportRequestState`1 requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 149
InnerException: PingException, InnerMessage: Pinging http://localhost:9200/ caused an exception, InnerStackTrace: at Elasticsearch.Net.Connection.Transport.Elasticsearch.Net.Connection.ITransportDelegator.Ping(ITransportRequestState requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 108
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.SelectNextNode[T](TransportRequestState`1 requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 45
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.CoordinateRequest[T](TransportRequestState`1 requestState, Int32 maxRetries, Int32 retried, Boolean& aliveResponse) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 117
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.DoRequest[T](TransportRequestState`1 requestState) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 149
最奇怪的是,如果我让程序继续运行,在异常被抛出之后它会给我正确的结果。
我错过了什么,但不知道是什么。