ES学习三 -- delete

Delete

Request

DELETE /<index>/_doc/<_id>

前置条件

如果ES开启了安全模式,操作者必须有删除或者写入对应 index 或者 index alisa 的权限。

1.描述

删除必须指定 index name 和 document ID。

Versioning

Each document indexes is versioned. 当删除一个文档时, version可以来确保要删除的文档是我们实际要删除的版本。每次操作文档时,文档的number都是增长的。(实际项目中使用雪花算法)

Timeout

主要shard节点执行这个动作时,其节点状态可能是不可以执行状态。默认情况,主节点会等待1分钟直到失败返回错误。

DELETE /my-index-000001/_doc/1?timeout=5m

2.Query parameters

if_seq_no

(Optional, integer) Only perform the operation if the document has this sequence number. See Optimistic concurrency control.

if_primary_term

(Optional, integer) Only perform the operation if the document has this primary term. See Optimistic concurrency control.

refresh

(Optional, enum) If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Default: false.

routing

(Optional, string) Target the specified primary shard.

timeout

(Optional, time units) Period to wait for active shards. Defaults to 1m (one minute).

version

(Optional, integer) Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

version_type

(Optional, enum) Specific version type: internal, external, external_gte.

wait_for_active_shards

(Optional, string) The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: 1, the primary shard.

See Active shards.

Delete by query API

Request

POST /<target>/_delete_by_query
POST /my-index-000001/_delete_by_query
{
  "query": {
    "match": {
      "user.id": "elkbee"
    }
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容