找到问题的解决办法了么?

在java中,使用RestHighLevelClient 怎么连接 search-guard

Elasticsearch | 作者 qiumingben | 发布于2019年01月18日 | 阅读数:4080


1547780450(1).jpg

search-guard 安装只有,不开启证书验证,现在测试之后,head 和 cerebro 都可以使用 admin 账号连接集群,但 java 中使用 RestHighLevelClient 还不能连接,有没有大佬做过的
已邀请:

rochy - rochy_he

赞同来自:

public static RestClientBuilder getRestClientBuilder(int port, String user, String pwd, String... ips) {
HttpHost[] httpHosts = new HttpHost[ips.length];
for (int i = 0; i < ips.length; i++) {
String ip = ips[i];
httpHosts[i] = new HttpHost(ip, port, "http");
}
String esAuth = "";
if (StrUtil.isNotBlank(user) && StrUtil.isNotBlank(pwd)) {
esAuth = "Basic " + Base64.encode(user + ":" + pwd);
}
Header[] defaultHeaders = new Header[]{new BasicHeader("Authorization", esAuth)};
RestClientBuilder clientBuilder = RestClient.builder(httpHosts);
clientBuilder.setDefaultHeaders(defaultHeaders);
clientBuilder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
.setConnectTimeout(5000)
.setSocketTimeout(150000))
.setMaxRetryTimeoutMillis(150000);
return clientBuilder;
}

要回复问题请先登录注册