Detecting Master_Not_Discovered faster

Hello,

I have a 2 node cluster - and that means that there is a chance, that i will run into the situation where one node remains but it can't elect a master. That's OK.

But what i want is to be able to detect this faster - at the moment using the code bellow i get the exception back in around 30 seconds.

  RestClientBuilder builder = RestClient.builder(httpHost).setRequestConfigCallback(ESConnectionProfile.FAST.getRequestConfigCallback());
        RestHighLevelClient client = new RestHighLevelClient(builder);


 FAST(new RestClientBuilder.RequestConfigCallback()
     {
         @Override
         public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder)
         {
             return requestConfigBuilder.setConnectTimeout(2000).setSocketTimeout(30000);
         }
     });


  final Request request = new Request("GET", "/_cluster/state");
        request.addParameter("format", "json");
        
        try
        {
            client.getLowLevelClient().performRequest(request);
        }

If i do lower the setSocketTimeout(30000) above - i no longer see the master_not_discovere exception, i get the SocketTimeout.

So basically what i want is to lower the server side timeout for this call - any ideas would be appreciated.

Thanks,
Nicu

I found a solution :slight_smile:

        ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest();
        clusterHealthRequest.waitForStatus();
        clusterHealthRequest.timeout("1s");
        try
        {
            ClusterHealthResponse healthResponse = client.cluster().health(clusterHealthRequest,
                                                                           RequestOptions.DEFAULT);
        }
        catch ( ElasticsearchStatusException e)
        {
            System.out.println("StatusException");
            e.printStackTrace();
        }

This will return in the 1s I need.
Do you see any issues with this approach ?