Skip to content

Commit f0a380b

Browse files
committed
Add examples for delete API
1 parent c5de191 commit f0a380b

File tree

7 files changed

+126
-52
lines changed

7 files changed

+126
-52
lines changed

output/openapi/elasticsearch-openapi.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/openapi/elasticsearch-serverless-openapi.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/schema.json

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_doc_ids/table.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ dissect-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branc
140140
distance-units,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/api-conventions.html#distance-units
141141
docs-bulk,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-bulk.html
142142
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
143-
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
144143
docs-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete.html
145144
docs-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-get.html
146145
docs-index,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-index_.html

specification/_global/delete/DeleteRequest.ts

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,50 @@ import { Duration } from '@_types/Time'
3333

3434
/**
3535
* Delete a document.
36-
* Removes a JSON document from the specified index.
36+
*
37+
* Remove a JSON document from the specified index.
38+
*
39+
* NOTE: You cannot send deletion requests directly to a data stream.
40+
* To delete a document in a data stream, you must target the backing index containing the document.
41+
*
42+
* **Optimistic concurrency control**
43+
*
44+
* Delete operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the `if_seq_no` and `if_primary_term` parameters.
45+
* If a mismatch is detected, the operation will result in a `VersionConflictException` and a status code of `409`.
46+
*
47+
* **Versioning**
48+
*
49+
* Each document indexed is versioned.
50+
* When deleting a document, the version can be specified to make sure the relevant document you are trying to delete is actually being deleted and it has not changed in the meantime.
51+
* Every write operation run on a document, deletes included, causes its version to be incremented.
52+
* The version number of a deleted document remains available for a short time after deletion to allow for control of concurrent operations.
53+
* The length of time for which a deleted document's version remains available is determined by the `index.gc_deletes` index setting.
54+
*
55+
* **Routing**
56+
*
57+
* If routing is used during indexing, the routing value also needs to be specified to delete a document.
58+
*
59+
* If the `_routing` mapping is set to `required` and no routing value is specified, the delete API throws a `RoutingMissingException` and rejects the request.
60+
*
61+
* For example:
62+
*
63+
* ```
64+
* DELETE /my-index-000001/_doc/1?routing=shard-1
65+
* ```
66+
*
67+
* This request deletes the document with ID 1, but it is routed based on the user.
68+
* The document is not deleted if the correct routing is not specified.
69+
*
70+
* **Distributed**
71+
*
72+
* The delete operation gets hashed into a specific shard ID.
73+
* It then gets redirected into the primary shard within that ID group and replicated (if needed) to shard replicas within that ID group.
3774
* @rest_spec_name delete
3875
* @availability stack stability=stable
3976
* @availability serverless stability=stable visibility=public
77+
* @index_privileges delete
4078
* @doc_tag document
79+
* @doc_id docs-delete
4180
*/
4281
export interface Request extends RequestBase {
4382
urls: [
@@ -48,50 +87,58 @@ export interface Request extends RequestBase {
4887
]
4988
path_parts: {
5089
/**
51-
* Unique identifier for the document.
90+
* A unique identifier for the document.
5291
*/
5392
id: Id
5493
/**
55-
* Name of the target index.
94+
* The name of the target index.
5695
*/
5796
index: IndexName
5897
}
5998
query_parameters: {
6099
/**
61100
* Only perform the operation if the document has this primary term.
101+
* @ext_doc_id optimistic-concurrency
62102
*/
63103
if_primary_term?: long
64104
/**
65105
* Only perform the operation if the document has this sequence number.
106+
* @ext_doc_id optimistic-concurrency
66107
*/
67108
if_seq_no?: SequenceNumber
68109
/**
69-
* 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.
70-
* Valid values: `true`, `false`, `wait_for`.
110+
* If `true`, Elasticsearch refreshes the affected shards to make this operation visible to search.
111+
* If `wait_for`, it waits for a refresh to make this operation visible to search.
112+
* If `false`, it does nothing with refreshes.
71113
* @server_default false
72114
*/
73115
refresh?: Refresh
74116
/**
75-
* Custom value used to route operations to a specific shard.
117+
* A custom value used to route operations to a specific shard.
76118
*/
77119
routing?: Routing
78120
/**
79-
* Period to wait for active shards.
121+
* The period to wait for active shards.
122+
*
123+
* This parameter is useful for situations where the primary shard assigned to perform the delete operation might not be available when the delete operation runs.
124+
* Some reasons for this might be that the primary shard is currently recovering from a store or undergoing relocation.
125+
* 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.
80126
* @server_default 1m
81127
*/
82128
timeout?: Duration
83129
/**
84-
* Explicit version number for concurrency control.
85-
* The specified version must match the current version of the document for the request to succeed.
130+
* An explicit version number for concurrency control.
131+
* It must match the current version of the document for the request to succeed.
86132
*/
87133
version?: VersionNumber
88134
/**
89-
* Specific version type: `external`, `external_gte`.
135+
* The version type.
90136
*/
91137
version_type?: VersionType
92138
/**
93-
* The number of shard copies that must be active before proceeding with the operation.
94-
* Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
139+
* The minimum number of shard copies that must be active before proceeding with the operation.
140+
* You can set it to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
141+
* The default value of `1` means it waits for each primary shard to be active.
95142
* @server_default 1
96143
*/
97144
wait_for_active_shards?: WaitForActiveShards
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# summary:
2+
description: A successful response from `DELETE /my-index-000001/_doc/1`, which deletes the JSON document 1 from the `my-index-000001` index.
3+
# type: response
4+
# response_code: ''
5+
value: |-
6+
{
7+
"_shards": {
8+
"total": 2,
9+
"failed": 0,
10+
"successful": 2
11+
},
12+
"_index": "my-index-000001",
13+
"_id": "1",
14+
"_version": 2,
15+
"_primary_term": 1,
16+
"_seq_no": 5,
17+
"result": "deleted"
18+
}

specification/_global/index/IndexRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { Duration } from '@_types/Time'
7474
* **Optimistic concurrency control**
7575
*
7676
* Index operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the `if_seq_no` and `if_primary_term` parameters.
77-
* If a mismatch is detected, the operation will result in a `VersionConflictException` and a status code of 409.
77+
* If a mismatch is detected, the operation will result in a `VersionConflictException` and a status code of `409`.
7878
*
7979
* **Routing**
8080
*

0 commit comments

Comments
 (0)