Source:
<code>public HttpClient httpClient() { List<String> hosts = hostsSupplier().get(); if (hosts.isEmpty()) throw new IllegalArgumentException("no hosts configured"); final String clientUrl; if (hosts.size() == 1) { clientUrl = hosts.get(0); } else { List<URL> urls = hosts.stream() .map(host -> { try { return new URL(host); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid host: " + host, e); } }) .collect(Collectors.toList()); List<Endpoint> endpoints = urls.stream() .map(url -> Endpoint.parse(url.getAuthority())) .collect(Collectors.toList()); EndpointGroup group = HttpHealthCheckedEndpointGroup.of( new StaticEndpointGroup(endpoints), "/_cluster/health"); EndpointGroupRegistry.register("elasticsearch", group, EndpointSelectionStrategy.ROUND_ROBIN); <START> clientUrl = urls.get(0).getProtocol() + "://group:elasticsearch" + urls.get(0).getPath(); <END> } HttpClientBuilder client = new HttpClientBuilder(clientUrl) .factory(clientFactory()) .decorator(HttpDecodingClient.newDecorator()); clientCustomizer().accept(client); return client.build(); }</code><technical_language>this work round-robin https port endpoints? if solves requested issues. Ex #2340 #1422 cc @gquintana @maoling</technical_language>

Target:
public HttpClient httpClient() { List<String> hosts = hostsSupplier().get(); if (hosts.isEmpty()) throw new IllegalArgumentException("no hosts configured"); List<URL> urls = hosts.stream() .map(host -> { try { return new URL(host); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid host: " + host, e); } }) .collect(Collectors.toList()); final EndpointGroup endpointGroup; if (urls.size() == 1) { URL url = urls.get(0); if (isIpAddress(url.getHost())) { endpointGroup = null; } else { DnsAddressEndpointGroupBuilder dnsEndpoint = new DnsAddressEndpointGroupBuilder(url.getHost()); if (url.getPort() != -1) { dnsEndpoint.port(url.getPort()); } endpointGroup = dnsEndpoint.build(); } } else { List<EndpointGroup> endpointGroups = new ArrayList<>(); List<Endpoint> staticEndpoints = new ArrayList<>(); for (URL url : urls) { if (isIpAddress(url.getHost())) { staticEndpoints.add(Endpoint.parse(url.getAuthority())); } else { endpointGroups.add(url.getPort() == -1 ? DnsAddressEndpointGroup.of(url.getHost()) : DnsAddressEndpointGroup.of(url.getHost(), url.getPort())); } } if (!staticEndpoints.isEmpty()) { endpointGroups.add(new StaticEndpointGroup(staticEndpoints)); } if (endpointGroups.size() == 1) { endpointGroup = endpointGroups.get(0); } else { endpointGroup = new CompositeEndpointGroup(endpointGroups); } } final String clientUrl; if (endpointGroup != null) { HttpHealthCheckedEndpointGroup healthChecked = new HttpHealthCheckedEndpointGroupBuilder( endpointGroup, "/_cluster/health") .clientFactory(clientFactory()) .build(); EndpointGroupRegistry.register( "elasticsearch", healthChecked, EndpointSelectionStrategy.ROUND_ROBIN); try { healthChecked.awaitInitialEndpoints(30, TimeUnit.SECONDS); } catch (InterruptedException | TimeoutException e) { } clientUrl = urls.get(0).getProtocol() + "://group:elasticsearch" + urls.get(0).getPath(); } else { clientUrl = hosts.get(0); } HttpClientBuilder client = new HttpClientBuilder(clientUrl) .factory(clientFactory()) .decorator(HttpDecodingClient.newDecorator()); clientCustomizer().accept(client); return client.build(); }