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(
"{\n" +
" \"user\" : \"大美女\",\n" +
" \"post_date\" : \"2009-02-15T14:12:12\",\n" +
" \"message\" : \"trying begin Elasticsearch\"\n" +
"}", 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(
"{\n" +
" \"query\": { \n" +
" \"match\": {\n" +
" \"message\": \"begin\"\n" +
" }\n" +
" }\n" +
"}", 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(
"{\n" +
" \"query\": { \n" +
" \"match\": {\n" +
" \"message\": \"trying begin Elasticsearch\"\n" +
" }\n" +
" }\n" +
"}", ContentType.APPLICATION_JSON);
Response response = restClient.performRequest(method,endpoint, Collections.<String, String>emptyMap(),entity);
System.out.println(EntityUtils.toString(response.getEntity()));
} }

Java中ElasticSearch的删除示例的更多相关文章

  1. Hash Map 在java中的解释及示例

    目录 HashMap在java中的应用及示例 HashMap的内部结构 HashMap的性能 同步HashMap HashMap的构造函数 HashMap的时间复杂度 HashMap的方法 1. vo ...

  2. Java中的构造函数——通过示例学习Java编程(14)

      作者:CHAITANYA SINGH 来源:https://www.koofun.com//pro/kfpostsdetail?kfpostsid=25 构造函数是用来初始化新创建的对象的代码块. ...

  3. Java中ArrayList的删除元素总结

    Java中循环遍历元素,一般有for循环遍历,foreach循环遍历,iterator遍历. 先定义一个List对象 List<String> list = new ArrayList&l ...

  4. Java中的变量——通过示例学习Java编程(4)

    作者:CHAITANYA SINGH 来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=14&cid= 变量是用来存放可以更改的值的容 ...

  5. Java中的数据类型——通过示例学习Java编程(5)

    作者:CHAITANYA SINGH 来源:https://www.koofun.com//pro/kfpostsdetail?kfpostsid=15 数据类型用来定义变量可以采用的值,例如,如果变 ...

  6. ref:关于JAVA中一些安全漏洞示例说明及如何规避方法代码示例总结分享

    ref:http://www.xwood.net/_site_domain_/_root/5870/5874/t_c268166.html 标签:安全,漏洞,健壮,java,SQL注入,SS及CSRF ...

  7. java中的IO 的示例

    字符流 package jd_1; import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileNot ...

  8. java中List遍历删除元素-----不能直接 list.remove()

    https://blog.csdn.net/github_2011/article/details/54927531 这是List接口中的方法,List集合调用此方法可以得到一个迭代器对象(Itera ...

  9. 【坑】Java中遍历递归删除List元素

    运行环境 idea 2017.1.1 需求背景 需要做一个后台,可以编辑资源列表用于权限管理 资源列表中可以有父子关系,假设根节点为0,以下以(父节点id,子节点id)表示 当编辑某个资源时,需要带出 ...

随机推荐

  1. Letters Shop

    B. Letters Shop time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. LeetCode——540. Single Element in a Sorted Array

    题目:Given a sorted array consisting of only integers where every element appears twice except for one ...

  3. Spark 系列(十五)—— Spark Streaming 整合 Flume

    一.简介 Apache Flume 是一个分布式,高可用的数据收集系统,可以从不同的数据源收集数据,经过聚合后发送到分布式计算框架或者存储系统中.Spark Straming 提供了以下两种方式用于 ...

  4. 世纪龙校招java开发一、二面 面经

    头一天做的笔试,涉及到计组基本知识,还有几道智力题.java部分很简单(真的很简单有点基础就划过了) 第二天收简历 在隔壁教室等 叫到你 你就去面试 一面:先自我介绍 1 == 和 equals区别( ...

  5. 2017版 Jetbrains 系列软件激活方法

    1. 到网站 http://idea.lanyus.com/ 获取注册码. 2.填入下面的license server: http://intellij.mandroid.cn/ http://ide ...

  6. Hive 系列(八)—— Hive 数据查询详解

    一.数据准备 为了演示查询操作,这里需要预先创建三张表,并加载测试数据. 数据文件 emp.txt 和 dept.txt 可以从本仓库的resources 目录下载. 1.1 员工表 -- 建表语句 ...

  7. urllib.request.urlretrieve()用于下载制定url内容到本地

    函数:urllib.urlretrieve(url[, filename[, reporthook[, data]]]) 参数说明: url:外部或者本地url ,url中不要含有中文,好像会出错.f ...

  8. Rest构建分布式 SpringCloud微服务架构项目

    一.开发环境:jdk  1.8.Maven  3.x.IDEA  2019.1.4.SpringBoot   2.0.7.spring Cloud  最新的稳定版  Finchley SR2   搭配 ...

  9. Okhttp3源码解析(5)-拦截器RetryAndFollowUpInterceptor

    ### 前言 回顾: [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析](htt ...

  10. 设计模式(C#)——02工厂模式

    推荐阅读:  我的CSDN  我的博客园  QQ群:704621321       在简单工厂模式中讲到简单工厂模式的缺点:难以扩展,一旦添加新运算就必须修改简单工厂方法.       工厂方法模式: ...