截至7.15前版本的Java api官网已废弃。
1、添加依赖2、账号密码连接集群co.elastic.clients elasticsearch-java7.16.2 com.fasterxml.jackson.core jackson-databind2.12.3
String nodes = "192.168.1.96:9200,192.168.1.97:9200,192.168.1.98:9200";//集群节点 HttpHost[] httpHosts = Arrays.stream(nodes.split(",")).map(x -> { String[] hostInfo = x.split(":"); return new HttpHost(hostInfo[0], Integer.parseInt(hostInfo[1])); }).toArray(HttpHost[]::new); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials("elastic", "123456"));//账号密码 RestClientBuilder builder = RestClient.builder(httpHosts) .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); RestClient restClient = builder.build(); ElasticsearchTransport transport = new RestClientTransport( restClient, new JacksonJsonpMapper()); ElasticsearchClient client = new ElasticsearchClient(transport);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)