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. Django:在OS X环境下连接MySQL数据库

    正常的安装只需要执行以下2条命令: $ brew install mysql-connector-c $ pip3 install mysqlclient 但在执行 pip3 install mysq ...

  2. 前端登录jq图形验证码

    <!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8" ...

  3. 转载 | SVG向下兼容优雅降级方法

    本文引自:http://www.zhangxinxu.com/wordpress/2013/09/svg-fallbacks/ 1.svg image标签降级技术 <svg width=&quo ...

  4. 基于 kubeadm 部署单控制平面的 k8s 集群

    单控制平面不符合 HA 要求,但用于开发/测试环境不会有任何问题,如果资源足够的话(10台以上服务器,3台用于APIserver.3台用于 etcd 存储.至少3台用于工作节点.1台作为负载均衡),可 ...

  5. 使用JMS接口接入WebSphere MQ消息

    在你的应用程序中利用IBM WebSphere MQ消息中间件提供Java消息服务开放接口. IBM WebSphere MQ(WMQ)是一套面向消息的中间件(message-oriented mid ...

  6. git:将代码提交到远程仓库(码云)

    初始化 进入一个任意的文件夹(如D:\aqin_test1\) git init # 初始化,让git将这个文件夹管理起来 git add . # 收集此文件夹下的所有文件 git config -- ...

  7. 消息中间件——RabbitMQ(二)各大主流消息中间件综合对比介绍!

    前言 消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.当今市面上有很多主流的消息中间件,如老牌的Act ...

  8. (二十八)c#Winform自定义控件-文本框(一)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  9. WebSocket和HTTP协议的区别

    HTTP: 1,无状态协议. 2,短连接.(Ajax轮询方式或Long  poll方式实现“持久连接”状态) 2,被动型.  客户端请求->服务器端响应.服务端不能主动联系客户端,只能有客户端发 ...

  10. adb 最常用最简单的命令-install/push/pull 使用

    以vivo测试机为例1.网上下载adb工具包,安装---网上有教程2.手机连接电脑后,进入手机设置--更多设置---开发者选项,打开开发者选项和USB调试: (不同手机开发者选项进入方式不同)3.打开 ...