• 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"); 
    }



  • 相关阅读:
    种子爆破&[GWCTF 2019]枯燥的抽奖
    Springboot学习笔记(三)
    Springboot学习笔记(二)
    Springboot学习笔记(一)
    深入理解java虚拟机阅读笔记(二)对象是否存活与垃圾收集算法
    深入理解java虚拟机阅读笔记(一)java内存区域
    OOP和AOP的区别
    浅谈对spring的理解
    mybatis逆向工程配置文件
    mybatis中${}和#{}的区别
  • 原文地址:https://www.cnblogs.com/xiaocandou/p/8127462.html
Copyright © 2020-2023  润新知