2017-02-17 82 views

回答

0

您需要从nuget软件包管理器安装ElasticSearch.net和Nest,两者必须具有相同的版本。

这里是使用Nest Elastic Client检查状态的方法。

public string HealthCheck(WaitForStatus waitForStatus = WaitForStatus.Red, bool logResults = false) 
    { 
      var response = this._client.ClusterHealth(new ClusterHealthRequest() { WaitForStatus = waitForStatus }); 

      var healthColor = response.Status.ToLower(); 

      // this will give you the color code of the elastic search server health. 

      switch (healthColor) 
        { 
         case "green": 
         var message = "ElasticSearch Server health check returned [GREEN]"; 
         break; 

        case "yellow": 
         var message = "ElasticSearch Server health check returned [YELLOW] (yellow is normal for single node clusters) "; 
         break; 

        default: // Includes "red" 
         var message = "ElasticSearch Server health check returned [{0}]".FormatInLine(response.Status.ToUpper()); 
         break; 

       } 

     return message; 
    } 

您可以通过获得的消息来识别服务器的运行状况。 绿色和黄色都可以接受,红色可能会导致一些问题。

谢谢............