public static void main(String[] args) throws IOException {
HttpHost httpHost = HttpHost.create("http://127.0.0.1:9200");
RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
restClientBuilder.setHttpClientConfigCallback(httpAsyncClientBuilder -> {
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "elas!@#"));
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return httpAsyncClientBuilder;
});
ElasticsearchClient client = new ElasticsearchClient(new RestClientTransport(restClientBuilder.build(),new JacksonJsonpMapper()));
CountResponse count = client.count(req->req.index("p7").q("docNo:*"));
System.out.println(count.count());
}