zoukankan      html  css  js  c++  java
  • ElasticSearch(十四) Cluster Administration

    ClusterAdminClient clusterAdminClient = client.admin().cluster();

    Cluster Health

    ClusterHealthResponse healths = client.admin().cluster().prepareHealth().get(); 
    String clusterName = healths.getClusterName();              
    int numberOfDataNodes = healths.getNumberOfDataNodes();     
    int numberOfNodes = healths.getNumberOfNodes();             
    for (ClusterIndexHealth health : healths.getIndices().values()) { 
        String index = health.getIndex();                       
        int numberOfShards = health.getNumberOfShards();        
        int numberOfReplicas = health.getNumberOfReplicas();    
        ClusterHealthStatus status = health.getStatus();        
    }

    Wait for status

    You can use the cluster health API to wait for a specific status for the whole cluster or for a given index:

    client.admin().cluster().prepareHealth()            
            .setWaitForYellowStatus()                   
            .get();
    client.admin().cluster().prepareHealth("company")   
            .setWaitForGreenStatus()                    
            .get();
    
    client.admin().cluster().prepareHealth("employee")  
            .setWaitForGreenStatus()                    
            .setTimeout(TimeValue.timeValueSeconds(2))  
            .get();

    If the index does not have the expected status and you want to fail in that case, you need to explicitly interpret the result:

    ClusterHealthResponse response = client.admin().cluster().prepareHealth("company")
            .setWaitForGreenStatus()    
            .get();
    
    ClusterHealthStatus status = response.getIndices().get("company").getStatus();
    if (!status.equals(ClusterHealthStatus.GREEN)) {
        throw new RuntimeException("Index is in " + status + " state"); 
    }



  • 相关阅读:
    hdu 4115 石头剪子布(2-sat问题)
    AFNetWorking POST Multi-Part Request 上传图片
    左右c++与java中国的垃圾问题的分析与解决
    ACM核武器
    MAX2323E
    cocos2d-x 发动机分析:程序如何开始和结束?
    STL 源代码分析 算法 stl_heap.h
    Android 4.4(KitKat)表格管理子系统
    Swift
    Swift
  • 原文地址:https://www.cnblogs.com/xiaocandou/p/8127462.html
Copyright © 2011-2022 走看看