elasticsearch6.2.4 DSL java API 插入和获取数据

版权声明:本文为博主原创文章,未经博主允许不得转载。交流请联系:351605040 https://blog.csdn.net/Arvinzr/article/details/83187191

创建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 = restClient.performRequest("GET", "/logstash-2015.05.20/_search", params, entity);
System.out.println(EntityUtils.toString(response.getEntity()));
logstash-2015.05.20为索引名称,json为DSL查询json语句,可在head中验证后直接查询

猜你喜欢

转载自blog.csdn.net/Arvinzr/article/details/83187191