2017-02-17 84 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; 
    } 

您可以通過獲得的消息來識別服務器的運行狀況。 綠色和黃色都可以接受,紅色可能會導致一些問題。

謝謝............