Elasticsearch增删改查 之 —— Delete删除

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介:

删除文档也算是常用的操作了...如果把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'
本文转自博客园xingoo的博客,原文链接:Elasticsearch增删改查 之 —— Delete删除,如需转载请自行联系原博主。
相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
4月前
|
API 网络架构 索引
Elasticsearch索引中数据的增删改查与并发控制
Elasticsearch索引中数据的增删改查与并发控制
|
3月前
|
Linux Docker 索引
ElasticSearch 通过 Kibana 与 ElasticSearch-head 完成增删改查
ElasticSearch 通过 Kibana 与 ElasticSearch-head 完成增删改查
48 0
|
索引 缓存
阿里云ElasticSearch入门基础-增删改查
阿里云ElasticSearch入门基础-增删改查,基于阿里云全托管ElasticSearch,版本6.7
|
5月前
|
NoSQL Java API
SpringBoot【ElasticSearch集成 02】Java HTTP Rest client for ElasticSearch Jest 客户端集成(依赖+配置+增删改查测试源码)推荐使用
SpringBoot【ElasticSearch集成 02】Java HTTP Rest client for ElasticSearch Jest 客户端集成(依赖+配置+增删改查测试源码)推荐使用
100 0
|
SQL JSON 搜索推荐
java操作ElasticSearch(包含增删改查及基础语法操作)(一)
java操作ElasticSearch(包含增删改查及基础语法操作)
402 0
java操作ElasticSearch(包含增删改查及基础语法操作)(一)
elasticsearch 怎么删除过期的数据
使用elasticsearch收集日志进行处理,时间久了,很老的数据就没用了或者用途不是很大,这个时候就要对过期数据进行清理.但是es5.0之后就不支持ttl,那怎么办呢? 1,请使用官方的工具elasticsearch-curator 2,使用delete-by-query方法删除特定时间范围的数据 第一种这里不再介绍了,直接看官网吧,主要说下第二种
|
PHP 索引
php es Elasticsearch 索引增删改查
php es Elasticsearch 索引增删改查
234 0
|
存储 安全 关系型数据库
ElasticSearch学习笔记(二)-增删改查操作的详细讲解
ElasticSearch学习笔记(二)-增删改查操作的详细讲解
ElasticSearch学习笔记(二)-增删改查操作的详细讲解
|
存储 JSON 自然语言处理
Elasticsearch——创建/查看/删除索引、创建/查看/修改/删除文档、映射关系
Elasticsearch——创建/查看/删除索引、创建/查看/修改/删除文档、映射关系
1304 0
Elasticsearch——创建/查看/删除索引、创建/查看/修改/删除文档、映射关系
Elasticsearch数组Array类型增加、删除
Elasticsearch数组Array类型增加、删除
308 0
下一篇
无影云桌面