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節(jié)點執(zhí)行這個動作時,其節(jié)點狀態(tài)可能是不可以執(zhí)行狀態(tài)。默認情況,主節(jié)點會等待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"
}
}
}