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

The delete API allows one to delete a typed JSON document from a specificindex based on its id. The following example deletes the JSON documentfrom an index called twitter, under a type called tweet, with id valued1:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();

For more information on the delete operation, check out thedelete API docs.

Operation Threadingedit

The delete API allows to set the threading model the operation will beperformed when the actual execution of the API is performed on the samenode (the API is executed on a shard that is allocated on the sameserver).

The options are to execute the operation on a different thread, or toexecute it on the calling thread (note that the API is still async). Bydefault, operationThreaded is set to true which means the operationis executed on a different thread. Here is an example that sets it tofalse:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").setOperationThreaded(false).get();

demo源码:

package es.documentApi;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.action.DocWriteResponse.Result;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class ElasticSearchDelete {

public static void main(String[] args) {
        try {
            // 设置集群名称
            Settings settings = Settings.builder().put("cluster.name", "my-elasticsearch")
                    .put("client.transport.sniff", true).build();
            // 创建client
            TransportClient client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.140"), 9300))
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.141"), 9300))
                    .addTransportAddress(
                            new InetSocketTransportAddress(InetAddress.getByName("192.168.224.142"), 9300));
            DeleteResponse response = client.prepareDelete("blog", "article", "AVvYUN6QAl9waYY55JSH").get();
            /*DeleteResponse response1 = client.prepareDelete("blog", "article", "1")
                    .setOperationThreaded(false)
                    .get();*/
            
            Result res = response.getResult();
            System.out.print(res);
            client.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

}

}

最后结果:

no modules loaded
loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
loaded plugin [org.elasticsearch.transport.Netty3Plugin]
loaded plugin [org.elasticsearch.transport.Netty4Plugin]
DELETED

elasticsearch api中的delete操作相关推荐

  1. elasticsearch api中的Delete By Query API操作

    官网:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-delete-by-query.h ...

  2. elasticsearch api中的get操作

    官网:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-index.html The ge ...

  3. java peek函数_Java 8 Stream Api 中的 peek 操作

    1. 前言 我在 Java 8 Stream API中的 map 和flatMap 中讲述了Java8 Stream API中 map 操作和 flatMap 操作的区别.然后有小伙伴告诉我 peek ...

  4. elasticsearch api中的Bulk API操作

    在elasticsearch中bulk的概念,其实和sql中的group by有异曲同工的作用. The bulk API allows one to index and delete several ...

  5. elasticsearch api中的Multi Get API操作

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

  6. elasticsearch api中的Buckets(桶)及Metrics(指标)

    和查询DSL一样,聚合(Aggregations)也拥有一种可组合(Composable)的语法:独立的功能单元可以被混合在一起来满足你的需求.这意味着需要学习的基本概念虽然不多,但是它们的组合方式是 ...

  7. MySQL中DELETE操作磁盘空间不会减少的原因

    MySQL中delete操作 在InnoDB中,delete操作并不会真的删除数据,mysql实际上只是给要删除的数据打了标记,标记为删除.磁盘所占空间不会变小,即表空间并没有真正被释放. 这样设计的 ...

  8. 为什么mysql的delete操作不释放磁盘空间

    在 InnoDB 中,delete 操作并不会真的删除数据,mysql 实际上只是给要删除的数据打了标记,标记为删除.磁盘所占空间不会变小,即表空间并没有真正被释放. 一. MySQL 删除数据几种情 ...

  9. 【ES】CURL在windows中对ElasticSearch的一些简单的操作

    上一节说了CURL在windows中的安装方式,现在就简单的记录下CURL在windows中对ElasticSearch的一些简单的操作 直接上操作命令 首先我们打开cmd命令行 输入curl -he ...

最新文章

  1. sqoop架构_SQOOP架构的深入介绍
  2. Pipenv – 超好用的 Python 包管理工具
  3. ORM 和 JDBC有何不一样
  4. [POJ 3345] Bribing FIPA
  5. C语言数组作为传入参数
  6. 音视频技术开发周刊 | 156
  7. [大数据]PySpark原理与基本操作
  8. mysql导入表结构命令是_mysql,命令导入\导出表结构或数据
  9. 经典排序算法(12)——总结
  10. PL/SQL Developer连接Oracle 11g在Win8 64位系统下乱码
  11. 抛砖引玉,终于完成了自己的客户端校验提示Extender
  12. 【linux】——环境变量
  13. 跨浏览器确定一个窗口的大小
  14. clickhouse bitmap入门
  15. svchost.exe进程内存占用过高案例解决方案一例
  16. ctrl键失灵的问题-记kali 1.0升级kali 2.0
  17. Unity UGUI-Canvas
  18. 星系炸弹(2015年蓝桥杯省赛第2题)
  19. 如何防御DDoS攻击与CC攻击?
  20. 《系统》是南方周末2007年度最好的特稿

热门文章

  1. 原理详解与标准解法——蓝桥杯_2016年省赛B组 第七题 剪邮票(暴力+迷宫变形)
  2. idea新建springboot后端到前端_码云开源项目:利用SpringBoot+Vue 实现留言版
  3. 将函数当做参数 matlab,Matlab中如何将(自定义)函数作为参数传递给另一个函数...
  4. mysql 5.6升级8.0_Mysql数据库从5.6.28版本升到8.0.11版本部署项目时遇到的问题及解决方法...
  5. android 字体渲染机制,Android:字体渲染问题.ttf 3MB
  6. python读写xlsx文件_python读写Excel文件--使用xlrd模块读取,xlwt模块写入
  7. mysql utf8 cmd,MySQL Windows下cmd显示中文乱码
  8. python动态规划图解_动态规划案例之python实现(一)
  9. postgresql update使用别名_PostgreSQL逻辑复制之pglogical
  10. python特性 property_python 特性 property