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'
Elasticsearch增删改查 之 —— Delete删除的更多相关文章
- elasticsearch增删改查crudp-----1
Elasticsearch一些增删改查的总结 环境Centos7+Es 5.x 简单介绍下ES的原理: 1,索引 --相当于传统关系型数据库的database或schema 2,类型 --相当于传 ...
- elasticsearch 增删改查底层原理
elasticsearch专栏:https://www.cnblogs.com/hello-shf/category/1550315.html 一.预备知识 在对document的curd进行深度分析 ...
- 关于C#三层架构增删改查中的“删除”问题
序: 刚学习C#,经过一段时间学习,现在正在做一个简单的前后台联通的项目(主要是C#三层架构实现增删改查).分享一点儿小经验,也供自己以后可以回头看看自己的码农之路. 内容: 主要分享的是一条删除会用 ...
- Elasticsearch增删改查 之 —— mget多文档查询
之前说过了针对单一文档的增删改查,基本也算是达到了一个基本数据库的功能.本篇主要描述的是多文档的查询,通过这个查询语法,可以根据多个文档的查询条件,返回多个文档集合. 更多内容可以参考我整理的ELK文 ...
- ES 17 - (底层原理) Elasticsearch增删改查索引数据的过程
目录 1 增删改document的流程 1.1 协调节点 - Coordinating Node 1.2 增删改document的流程 2 查询document的流程 1 增删改document的流程 ...
- C# 顺序表---增删改查--逆至--删除最小值
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ElasticSearch 增删改查
HTTP 协议本身语义:GET 获取资源.POST 新建资源(也可以用于更新资源).PUT 更新资源.DELETE 删除资源. ES通过HTTP Restful方式管理数据:1.格式:#操作 /ind ...
- Java之Elasticsearch 增删改查
<!--ELK --> <dependency> <groupId>org.elasticsearch.client</groupId> <art ...
- Elasticsearch增删改查 之 —— Get查询
GET API是Elasticsearch中常用的操作,一般用于验证文档是否存在:或者执行CURD中的文档查询.与检索不同的是,GET查询是实时查询,可以实时查询到索引结果.而检索则是需要经过处理,一 ...
随机推荐
- [leetcode 27]Implement strStr()
1 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ...
- C#的函数柯里化
前面说到了C#的泛型委托和闭包函数,在函数是程序设计里还有一个重要特征是柯里化... 柯里化就是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结 ...
- Snmp协议应用-扫描局域网内打印机
.h2cls { background: #6fa833 none repeat scroll 0 0 !important; color: #fff; font-family: "微软雅黑 ...
- Newtonsoft.Json中的时间格式详解.
Newtonsoft.json是一款不错的序列化反序列化第三方组件,具体如何使用属于基础知识,此处不再讲解.看以下代码: public class OutgameEntity { public str ...
- 一天一小段js代码(no.3)
//遍历属性,返回名值对 function outputAttributes(element){ var pairs = new Array(), attrName, attrValue, i, le ...
- Jquery相册插件(开源下载)
一,导言 上次 “不定义JQuery插件,不要说会JQuery” 的博客写的肤浅,漏洞百出,而且最重要的是从理论上说如何定义一个jQuery插件,没有实质性的写一个jQuery插件出来,这未免是纸上谈 ...
- (翻译)正确实施DevOps-The Lay of the Land
原文地址:http://www.drdobbs.com/architecture-and-design/getting-devops-right-the-lay-of-the-land/2400626 ...
- linux expect详解(ssh自动登录)
shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:&quo ...
- linux service
有些东西真是难得搞懂,一旦懂了就容易记住了. 说到service 就不能不说 daemon, 他们两者看起来不相关.其实是紧密相连的两个概念. —— 就像两个同心的正五边形和正六边形放在一起时候的样子 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...