Elasticsearch增删改查 之 —— Delete删除
删除文档也算是常用的操作了...如果把Elasticsearch当做一款普通的数据库,那么删除操作自然就很常用了。如果仅仅是全文检索,可能就不会太常用到删除。
Delete API
删除API,可以根据特定的ID删除文档。
$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1'
会返回下面的消息:
{
"_shards" : {
"total" : 10,
"failed" : 0,
"successful" : 10
},
"found" : true,
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_version" : 2
}
版本
每个索引都通过版本来维护。当想要删除某个文档的时候,版本可以用来确认删除的文档。而想要删除一个已经被删除的文档,则不会发生任何变化。
路由
如果在索引的时候提供了路由,那么删除的时候,也需要指定相应的路由:
$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?routing=kimchy'
上面的例子中,想要删除id为1的索引,会通过固定的路由查找文档。如果路由不正确,可能查不到相关的文档。对于某种情况,需要使用_routing参数,但是却没有任何的值,那么删除请求会广播到每个分片,执行删除操作。
Parent
删除操作也可以指定父文档。再删除父文档的时候,不会删除子文档。有一种删除子文档的方法,就是使用delete-by-query。
自动创建索引
在执行删除操作时,如果没有创建过索引,则会自动创建。类型也是一样。
分布式
对于分布式的环境,主分片和副分片会维护一个共同的组ID,执行删除操作会向这个组ID发送请求。
Write Consistency
Control if the operation will be allowed to execute based on the number of active shards within that partition (replication group). The values allowed are one, quorum, and all. The parameter to set it isconsistency, and it defaults to the node level setting of action.write_consistency which in turn defaults toquorum.
For example, in a N shards with 2 replicas index, there will have to be at least 2 active shards within the relevant partition (quorum) for the operation to succeed. In a N shards with 1 replica scenario, there will need to be a single shard active (in this case, one and quorum is the same).
refresh
refresh参数设置为true,可以在删除操作执行后,立即刷新分片,保证其数据可以立即被查询。不过要慎用!
timeout
The primary shard assigned to perform the delete operation might not be available when the delete operation is executed. Some reasons for this might be that the primary shard is currently recovering from a store or undergoing relocation. By default, the delete operation will wait on the primary shard to become available for up to 1 minute before failing and responding with an error.
当分片不可用的时候,删除操作会等待一段时间执行。可以设置其timeout
$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?timeout=5m'
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Kubernetes 为什么需要策略支持
- iOS富文本之数字小角标
- 50. Vue名称案例-使用keyup事件监听
- 浅谈树形结构的特性和应用(上):多叉树,红黑树,堆,Trie树,B树,B+树...
- 腾讯云-轻量应用服务器SaaS交付Discuz! Q
- LeetCode 刷题技巧与学习方法
- IntelliJ IDEA 2020.2正式发布,诸多亮点总有几款能助你提效
- SQL之单表查询
- Ubuntu19.10 编译运行C语言程序
- Linux 中杀死指定端口的进程
- Python:将给定字符串中的大写英文字母按以下对应规则替换
- 数据库原理02——关系数据库
- 计算机网络02——物理层
- 面试官你好,我已经掌握了MySQL主从配置和读写分离,你看我还有机会吗?
- 虚拟机中安装双系统