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

创建MAVEN项目,maven依赖如下:


    org.elasticsearch
    elasticsearch
    6.2.4



    org.elasticsearch.client
    transport
    6.2.4

 

查询方式如下:

RestClient restClient = RestClient.builder(new HttpHost("192.168.43.22", 9200, "http")).build();
System.out.println(123);
Map params = new HashMap();

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中验证后直接查询

elasticsearch6.2.4 DSL java API 插入和获取数据_第1张图片 

你可能感兴趣的:(elasticsearch)