elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient" /> elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient" />

Spring boot 使用弹性搜索代理配置Rest High客户端

Spring boot 使用弹性搜索代理配置Rest High客户端,spring-boot,elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient,是否有任何方法可以将我的rest high客户端配置为使用代理与es连接。我的配置是 @Override @Bean public RestHighLevelClient elasticsearchClient() { return new RestHighLevelClient(RestClient.builder(HttpHost.create(elasticSearchUrl)));} 我的弹性搜索url是:aaa.bbbb.ccc.company.com/api/ela

是否有任何方法可以将我的rest high客户端配置为使用代理与es连接。我的配置是

    @Override
@Bean
public RestHighLevelClient elasticsearchClient() {
    return new RestHighLevelClient(RestClient.builder(HttpHost.create(elasticSearchUrl)));}
我的弹性搜索url是:aaa.bbbb.ccc.company.com/api/elastic-search-proxy
在这种情况下,我得不到已知的aaa.bbbbbb.ccc.company.com/api/elastic-search-proxy这样的主机。我很清楚,但有没有配置它的选项?

的Elasticsearch文档中提到了它,请使用以下代码:

RestClientBuilder builder = RestClient.builder(
    new HttpHost("localhost", 9200, "http"));
builder.setHttpClientConfigCallback(new HttpClientConfigCallback() {
        @Override
        public HttpAsyncClientBuilder customizeHttpClient(
                HttpAsyncClientBuilder httpClientBuilder) {
            return httpClientBuilder.setProxy(
                new HttpHost("proxy", 9000, "http"));  
        }
    });
设置允许修改http客户端配置的回调,例如通过ssl进行加密通信,或org.apache.http.impl.nio.client.HttpAsyncClientBuilder允许设置的任何内容

因此,在您的情况下,您需要在下面的代码中提供您的原始主机

new HttpHost("localhost", 9200, "http"));
然后需要在setHttpClientConfigCallback回调中定义对代理服务器的回调

new HttpHost("proxy", 9000, "http"));  

我的回答有问题吗?