ES学习三 -- delete

Delete

Request

DELETE //_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 //_delete_by_query
POST /my-index-000001/_delete_by_query
{
  "query": {
    "match": {
      "user.id": "elkbee"
    }
  }
}

你可能感兴趣的:(ES学习三 -- delete)