【发布时间】:2020-01-23 15:32:21
【问题描述】:
当我启动我的程序时,我运行 ElasticSearch 服务并检查索引是否存在以及是否有任何文档,假设我只是运行 ES 服务并且我有这两个功能:
public ElasticClient getElasticSearchClient()
{
ConnectionSettings connectionSettings = new Nest.ConnectionSettings(new Uri("http://localhost:9200"))
.DefaultIndex("myindex")
.DisableDirectStreaming();
ElasticClient client = new ElasticClient(connectionSettings);
//var health = client.Cluster.Health("myindex", a => (a.WaitForStatus(WaitForStatus.Yellow)).Timeout(50));
return client;
}
public void checkElasticsearchIndex()
{
var client = getElasticSearchClient();
var health = this.client.Cluster.Health("myindex", a => (a.WaitForStatus(WaitForStatus.Yellow)));
CountResponse count = client.Count<myobject>();
if (!client.Indices.Exists("myindex").IsValid || count.Count == 0)
{
BulkWriteAllToIndexES(client);
}
}
在 checkElasticsearchIndex 函数内部,
-
计数操作失败并显示以下错误消息:
OriginalException:Elasticsearch.Net.ElasticsearchClientException:远程服务器返回错误:(503)服务器不可用。调用:状态码 503 来自:GET /myindex/_count。 ServerError:类型:search_phase_execution_exception 原因:“所有分片失败”---> System.Net.WebException:远程服务器返回错误:(503)服务器不可用。
-
Health 也失败了:
OriginalException:Elasticsearch.Net.ElasticsearchClientException:无法连接到远程服务器。调用:状态码未知来自:GET /_cluster/health/myindex?wait_for_status=yellow ---> System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException:无法连接是因为目标机器主动拒绝了它 127.0.0.1:9200
如您所见,我尝试了 Cluster WaitForStatus,但没有成功。
我的问题:有什么方法可以等到客户端/集群/节点准备好而不出现任何异常?
【问题讨论】:
标签: c# elasticsearch nest elasticsearch-7