创建MAVEN项目,maven依赖如下:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.2.4</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.2.4</version>
</dependency>
查询方式如下:
RestClient restClient = RestClient.builder(new HttpHost("192.168.43.22", 9200, "http")).build();
System.out.println(123);
Map<String,String> params = new HashMap<String, String>();
HttpEntity entity = new NStringEntity("{\"query\":{\"bool\":{\"must\":[{\"term\":{\"host.keyword\":\"media-for-the-masses.theacademyofperformingartsandscience.org\"}}],\"must_not\":[],\"should\":[]}},\"from\":0,\"size\":10,\"sort\":[],\"aggs\":{}}",
ContentType.APPLICATION_JSON);
Response response = rest