This documentation contains work-in-progress information for future Elastic Stack and Cloud releases. Use the version selector to view supported release docs. It also contains some Elastic Cloud serverless information. Check out our serverless docs for more details.
Timeouts
editTimeouts
editConfiguring requests timeouts can be done by providing an instance of
RequestConfigCallback
while building the RestClient
through its builder.
The interface has one method that receives an instance of
org.apache.http.client.config.RequestConfig.Builder
as an argument and has the same return type. The request config builder can
be modified and then returned. In the following example we increase the
connect timeout (defaults to 1 second) and the socket timeout (defaults to 30
seconds).
RestClientBuilder builder = RestClient.builder( new HttpHost("localhost", 9200)) .setRequestConfigCallback( new RestClientBuilder.RequestConfigCallback() { @Override public RequestConfig.Builder customizeRequestConfig( RequestConfig.Builder requestConfigBuilder) { return requestConfigBuilder .setConnectTimeout(5000) .setSocketTimeout(60000); } });
Timeouts also can be set per request with RequestOptions, which overrides RestClient customizeRequestConfig.
RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(5000) .setSocketTimeout(60000) .build(); RequestOptions options = RequestOptions.DEFAULT.toBuilder() .setRequestConfig(requestConfig) .build();