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(
"{\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的删除示例的更多相关文章
- Hash Map 在java中的解释及示例
目录 HashMap在java中的应用及示例 HashMap的内部结构 HashMap的性能 同步HashMap HashMap的构造函数 HashMap的时间复杂度 HashMap的方法 1. vo ...
- Java中的构造函数——通过示例学习Java编程(14)
作者:CHAITANYA SINGH 来源:https://www.koofun.com//pro/kfpostsdetail?kfpostsid=25 构造函数是用来初始化新创建的对象的代码块. ...
- Java中ArrayList的删除元素总结
Java中循环遍历元素,一般有for循环遍历,foreach循环遍历,iterator遍历. 先定义一个List对象 List<String> list = new ArrayList&l ...
- Java中的变量——通过示例学习Java编程(4)
作者:CHAITANYA SINGH 来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=14&cid= 变量是用来存放可以更改的值的容 ...
- Java中的数据类型——通过示例学习Java编程(5)
作者:CHAITANYA SINGH 来源:https://www.koofun.com//pro/kfpostsdetail?kfpostsid=15 数据类型用来定义变量可以采用的值,例如,如果变 ...
- ref:关于JAVA中一些安全漏洞示例说明及如何规避方法代码示例总结分享
ref:http://www.xwood.net/_site_domain_/_root/5870/5874/t_c268166.html 标签:安全,漏洞,健壮,java,SQL注入,SS及CSRF ...
- java中的IO 的示例
字符流 package jd_1; import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileNot ...
- java中List遍历删除元素-----不能直接 list.remove()
https://blog.csdn.net/github_2011/article/details/54927531 这是List接口中的方法,List集合调用此方法可以得到一个迭代器对象(Itera ...
- 【坑】Java中遍历递归删除List元素
运行环境 idea 2017.1.1 需求背景 需要做一个后台,可以编辑资源列表用于权限管理 资源列表中可以有父子关系,假设根节点为0,以下以(父节点id,子节点id)表示 当编辑某个资源时,需要带出 ...
随机推荐
- fatal: remote origin already exists.解决方法
git remote add origin1 http://github.com/xxx/xxx.git origin名字冲突,换一个名字 遇到这种问题时表示已经有一个origin,冲突了,可能原因是 ...
- Javascript中的基本数据类型,如何判断数据类型,作用域链的理解
第一部分:Javascript中的数据类型 javascript中 基本数据类型有 五种, 数字 number 字符串 string 布尔 boolean 未定义 undefined 空值 nul ...
- 三角函数与JavaScript
1. 三角函数 sin&(求对边与斜边的比值) cos&(邻边与斜边的比值) tan&(对边与邻边的比值) 2.JavaScript的函数的使用 Math.sin() Mat ...
- 教你用原生CSS写炫酷页面切换效果,跟第三方组件说拜拜
因为项目需要,别人想让我给他写一个个人博客,并且给了我一个其他人的网页,可以点此查看.有的同学可能说了,第三方博客框架这么多,为什么还要去手写的,你说这个有可能是没有看到打开这个博客. 样式介绍 给大 ...
- 12.源码分析—如何为SOFARPC写一个序列化?
SOFARPC源码解析系列: 1. 源码分析---SOFARPC可扩展的机制SPI 2. 源码分析---SOFARPC客户端服务引用 3. 源码分析---SOFARPC客户端服务调用 4. 源码分析- ...
- iOS 视图渲染数据转CVPixelBuffer
近两年一直从事视频行业的开发, 加班也比较严重, 好久没有写文章了, 最近稍微有些时间, 前来写点文章, 记录一些开发中遇到的问题, 和解决方法! 做视频会议项目, 当然是离不开音视频啦, 也常常和W ...
- 去掉input框的数字箭头
input::-webkit-outer-spin-button,input::-webkit-inner-spin-button { -webkit-appearance: none;}input[ ...
- unity_小功能实现(敌人追踪主角)
1.敌人发现主角有两种形式: a.看见主角(主角出现在敌人的视野之内) b.听见主角(听见主角走路声或者是跑步声) a:看(see) 首先判断主角是否在敌人视野角度内,那么我们只需要判断B<0. ...
- 2020届京东秋招正式批一面记录-Java开发-2019.08.31
京东一面总结 总共时间持续时间约40分钟 1.你用过集合类里面哪些是线程安全的,哪些是线程不安全的?分别举两个例子? 线程安全:HashTable以及ConcurrentHashMap 非线程安全:A ...
- SpringBoot_@valid_参数校验
SpringBoot @valid 参数校验 空检查 @Null 验证对象是否为null @NotNull 验证对象是否不为null, 无法查检长度为0的字符串 @NotBlank 检查约束字符串是不 ...