运用elasticsearch REST API操作elasticsearch5.3ITeye - 超凡娱乐

运用elasticsearch REST API操作elasticsearch5.3ITeye

2019-01-11 05:48:26 | 作者: 曜栋 | 标签: 查询,官方,地址 | 浏览: 1961

1.官方API地址

  https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-get.html

2.maven依靠

  dependency
           groupId org.elasticsearch.client /groupId
           artifactId rest /artifactId
           version 5.3.0 /version
        /dependency
        dependency
             groupId org.apache.httpcomponents /groupId
             artifactId httpclient /artifactId
            version 4.5.3 /version
        /dependency
        dependency
             groupId org.apache.httpcomponents /groupId
             artifactId httpasyncclient /artifactId
            version 4.1.3 /version
        /dependency
         dependency
             groupId org.apache.httpcomponents /groupId
             artifactId httpcore-nio /artifactId
            version 4.4.6 /version
        /dependency
        dependency
             groupId org.apache.httpcomponents /groupId
             artifactId httpcore /artifactId
            version 4.4.6 /version
        /dependency

3.简略查询

   (1)衔接

    RestClient restClient = RestClient.builder(
                new HttpHost("192.168.2.78", 9200, "http")).build();

    (2)GET查询(search url)

           Map String,String map=new HashMap String,String
            map.put("q", "name:lili");

            response = restClient.performRequest("GET", "/index/type/_search",
                map);

    (3)GET查询(search body)

        JSONObject job=new JSONObject();
        job.put("name","lili");
        JSONObject job1=new JSONObject();
        job1.put("term", job);
        JSONObject job2=new JSONObject();
        job2.put("query",job1);
        String json=job2.toString();
        HttpEntity entity = new NStringEntity(json);

        response = restClient.performRequest("GET", "/onekeymove/source_category/_search",
                Collections. String, String emptyMap(),entity);

关于其它查询,官网也给出了示例

    https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表超凡娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章