gpt4 book ai didi

elasticsearch - 通过代理在公司防火墙后面的Elasticsearch RestHighLevelClient

转载 作者:行者123 更新时间:2023-12-03 02:10:50 25 4
gpt4 key购买 nike

我正在尝试从需要访问外部请求代理的网络中访问Cloud Elasticsearch安装。这是我用来传递Elasticsearch凭证和我们的代理设置的代码片段:
CredentialsProvider certificateProvider =新的BasicCredentialsProvider();
certificateProvider.setCredentials(AuthScope.ANY,新的UsernamePasswordCredentials(elasticUser,elasticPassword));
RestClientBuilder restClientBuilder = RestClient.builder(新HttpHost(hostName,port,“https”))。setHttpClientConfigCallback(httpClientBuilder-> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))。setHttpClientConfigCallback(httpClientBuilder-> httpClientBuilder.setProxy(新HttpHost(proxyURL“,ProxyURL) “http”)));
RestHighLevelClient客户端=新的RestHighLevelClient(restClientBuilder);
这导致来自ES的以下响应:
“线程“主”中的异常” ElasticsearchStatusException [Elasticsearch异常
[类型= security_exception,原因=操作[索引:数据/读取/搜索]需要身份验证]]“”
似乎出于某种原因未通过Elasticsearch凭证。

最佳答案

应该这样做:

RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName, port, "https"))
.setHttpClientConfigCallback(clientBuilder -> {
clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
clientBuilder.setProxy(new HttpHost(proxyURL, proxyPort, "http"));
return clientBuilder;
});

关于elasticsearch - 通过代理在公司防火墙后面的Elasticsearch RestHighLevelClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64732951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com