Java ElasticsearchClient ping timeout

Hi,

We are caching the created connection, and use ping often to ensure that the connection is still valid and would like it to fail quickly if not so we can create a new one.

With the Java High Level REST Client we can provide RequestOptions allowing us to set a short timeout for the ping.

boolean response = client.ping(myPingRequestOptions);

This was very helpful as you could have different timeouts for searches and pings.

With the new Java API Client it looks like you cannot pass such custom request options and only set timeouts when creating the connection:

Is there anyway to reuse the same connection but set a different timeout for the ping?

Thanks

This isn't possible at the moment. However there is a workaround: ping is a very simple API endpoint and it's easy to call it with the low level REST client used to create the Java API client:

RequestOptions options = RequestOptions.DEFAULT.toBuilder()
	.setRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(1000).build())
	.build();
Request request = new Request("HEAD", "/");
request.setOptions(options);
restClient.performRequest(request);

However I'm wondering why the connection would become invalid.

Thanks.

Unfortunately the connection sometimes drops, terminates etc.