• Java中ElasticSearch的删除示例


    public class DeleteElasticAPI {
        private static RestClient restClient;
    
        static {
            restClient=RestClient.builder(new HttpHost("localhost",9200,"http")).build();
        }
    
        /**
         * 创建文档
         * @throws Exception
         */
        @Test
        public void CreateDocument()throws Exception{
    
            String method = "PUT";
            String endpoint = "/delete-index/test/2";
            HttpEntity entity = new NStringEntity(
                    "{
    " +
                            "    "user" : "大美女",
    " +
                            "    "post_date" : "2009-02-15T14:12:12",
    " +
                            "    "message" : "trying begin Elasticsearch"
    " +
                            "}", ContentType.APPLICATION_JSON);
    
            Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    
        /**
         * 获取文档
         * @throws Exception
         */
        @Test
        public void getDocument()throws Exception{
            String method = "GET";
            String endpoint = "/delete-index/test/1";
            Response response = restClient.performRequest(method,endpoint);
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    
        /**
         * 删除文档
         * @throws IOException
         */
        @Test
        public void delete () throws IOException {
            String method = "DELETE";
            String endpoint = "/delete-index/test/1";
            Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap());
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    
        /**
         * 删除文档,按查询api
         * @throws IOException
         */
        @Test
        public void deleteBySearch () throws IOException {
            String method = "POST";
            String endpoint = "/delete-index/_delete_by_query";
            HttpEntity entity = new NStringEntity(
                    "{
    " +
                            "  "query": { 
    " +
                            "    "match": {
    " +
                            "      "message": "begin"
    " +
                            "    }
    " +
                            "  }
    " +
                            "}", ContentType.APPLICATION_JSON);
            Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    
        /**
         * 查询匹配,message为条件
         * @throws IOException
         */
        @Test
        public void search () throws IOException {
            String method = "POST";
            String endpoint = "/delete-index/_search/";
            HttpEntity entity = new NStringEntity(
                    "{
    " +
                            "  "query": { 
    " +
                            "    "match": {
    " +
                            "      "message": "trying begin Elasticsearch"
    " +
                            "    }
    " +
                            "  }
    " +
                            "}", ContentType.APPLICATION_JSON);
            Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    
    }
  • 相关阅读:
    监听Windows消息
    把遇到过的对.Net线程的一些问题和误解集中起来和大家分享,也希望大家能一起补充,热烈欢迎讨论(转)
    推荐一个好工具:P/Invoke Interop Assistant (转)
    其它操作EDM的方式 (转载)
    DotNet(C#)自定义运行时窗体设计器 一
    通过监听Windows消息对复合控件进行整体控制(C#)一
    DotNet(C#)自定义运行时窗体设计器Runtime FormDesigner(转载)
    C# 枚举中的位运算
    Linux下cat 命令
    小端字节序与大端字节序
  • 原文地址:https://www.cnblogs.com/heqiyoujing/p/11148220.html
Copyright © 2020-2023  润新知