# Detecting Master\_Not\_Discovered faster

**URL:** <https://discuss.elastic.co/t/detecting-master-not-discovered-faster/248047>\
**Category:** Elasticsearch\
**Created:** [September 9, 2020, 5:04pm UTC](https://discuss.elastic.co/t/detecting-master-not-discovered-faster/248047 "2020-09-09T17:04:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolaet](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@nicolaet](https://discuss.elastic.co/u/nicolaet)\
**Post date:** [September 9, 2020, 5:04pm UTC](https://discuss.elastic.co/t/detecting-master-not-discovered-faster/248047/1 "2020-09-09T17:04:10Z")

</div>

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.

```auto
  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

---

<div class="post-metadata">

**Author:** ![nicolaet](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@nicolaet](https://discuss.elastic.co/u/nicolaet)\
**Post date:** [September 9, 2020, 7:16pm UTC](https://discuss.elastic.co/t/detecting-master-not-discovered-faster/248047/2 "2020-09-09T19:16:30Z")

</div>

I found a solution 🙂

```auto
        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 ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 7, 2020, 7:16pm UTC](https://discuss.elastic.co/t/detecting-master-not-discovered-faster/248047/3 "2020-10-07T19:16:52Z")

</div>

Closed on October 7, 2020, 7:16pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
