使用RestHighLevelClient 连接带有用户名密码ES机器
HttpHost host=new HttpHost(“IP地址”, “端口号”, HttpHost.DEFAULT_SCHEME_NAME);
RestClientBuilder builder=RestClient.builder(host);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(“用户名”, “密码”));
builder.setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider));
RestHighLevelClient restClient = new RestHighLevelClient( builder);
文章来自:https://www.cnblogs.com/pxinhai/p/12685424.html