Elasticsearch Rest5Client Proxy Configuration with HttpClient 5
Set the intermediary on Rest5Client’s asynchronous HTTP builder while keeping Apache 4 and 5 imports consistent.
Elasticsearch’s Rest5Client exposes its Apache HttpClient 5 builder through a configuration callback:
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
import org.apache.hc.core5.http.HttpHost;
var proxy = new HttpHost("http", "proxy.example.net", 8080);
var rest = Rest5Client.builder(
new HttpHost("https", "search.example.net", 9200))
.setHttpClientConfigCallback(httpBuilder -> {
httpBuilder.setProxy(proxy);
})
.build();
Supply rest to the application’s Elasticsearch transport setup and close it when that component shuts down. The search host stays HTTPS; the proxy’s http scheme describes the intermediary connection. For a permitted public-proxy route to a publicly reachable search host, the HTTP proxy list supplies endpoint candidates; confirm that the chosen proxy permits the search host and port.
For proxy authentication, attach an appropriately scoped Apache 5 credentials provider in the same callback. Retain the Elasticsearch account separately.
The callback accepts a Consumer: configure the supplied builder inside the block without returning a replacement. RestHighLevelClient examples using org.apache.http belong to an older generation; Apache 5 uses org.apache.hc packages.