1
1
[[docs-delete]]
2
2
=== Delete API
3
- ++++
4
- <titleabbrev>Delete</titleabbrev>
5
- ++++
6
3
7
- Removes a JSON document from the specified index.
4
+ The delete API allows to delete a JSON document from a specific
5
+ index based on its id. The following example deletes the JSON document
6
+ from an index called `twitter` with ID `1`:
8
7
9
- [[docs-delete-api-request]]
10
- ==== {api-request-title}
11
-
12
- `DELETE /<index>/_doc/<_id>`
8
+ [source,js]
9
+ --------------------------------------------------
10
+ DELETE /twitter/_doc/1
11
+ --------------------------------------------------
12
+ // CONSOLE
13
+ // TEST[setup:twitter]
13
14
14
- [[docs-delete-api-desc]]
15
- ==== {api-description-title}
15
+ The result of the above delete operation is:
16
16
17
- You use DELETE to remove a document from an index. You must specify the
18
- index name and document ID.
17
+ [source,js]
18
+ --------------------------------------------------
19
+ {
20
+ "_shards" : {
21
+ "total" : 2,
22
+ "failed" : 0,
23
+ "successful" : 2
24
+ },
25
+ "_index" : "twitter",
26
+ "_type" : "_doc",
27
+ "_id" : "1",
28
+ "_version" : 2,
29
+ "_primary_term": 1,
30
+ "_seq_no": 5,
31
+ "result": "deleted"
32
+ }
33
+ --------------------------------------------------
34
+ // TESTRESPONSE[s/"successful" : 2/"successful" : 1/]
35
+ // TESTRESPONSE[s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
36
+ // TESTRESPONSE[s/"_seq_no" : 5/"_seq_no" : $body._seq_no/]
19
37
20
38
[float]
21
39
[[optimistic-concurrency-control-delete]]
22
- ===== Optimistic concurrency control
40
+ ==== Optimistic concurrency control
23
41
24
42
Delete operations can be made conditional and only be performed if the last
25
- modification to the document was assigned the sequence number and primary
43
+ modification to the document was assigned the sequence number and primary
26
44
term specified by the `if_seq_no` and `if_primary_term` parameters. If a
27
45
mismatch is detected, the operation will result in a `VersionConflictException`
28
- and a status code of 409. See <<optimistic-concurrency-control>> for more details.
46
+ and a status code of 409. See <<optimistic-concurrency-control>> for more details.
29
47
30
48
[float]
31
49
[[delete-versioning]]
32
- ===== Versioning
50
+ ==== Versioning
33
51
34
52
Each document indexed is versioned. When deleting a document, the `version` can
35
53
be specified to make sure the relevant document we are trying to delete is
@@ -42,17 +60,11 @@ determined by the `index.gc_deletes` index setting and defaults to 60 seconds.
42
60
43
61
[float]
44
62
[[delete-routing]]
45
- ===== Routing
46
-
47
- If routing is used during indexing, the routing value also needs to be
48
- specified to delete a document.
49
-
50
- If the `_routing` mapping is set to `required` and no routing value is
51
- specified, the delete API throws a `RoutingMissingException` and rejects
52
- the request.
53
-
54
- For example:
63
+ ==== Routing
55
64
65
+ When indexing using the ability to control the routing, in order to
66
+ delete a document, the routing value should also be provided. For
67
+ example:
56
68
57
69
////
58
70
Example to delete with routing
@@ -75,29 +87,34 @@ DELETE /twitter/_doc/1?routing=kimchy
75
87
// CONSOLE
76
88
// TEST[continued]
77
89
78
- This request deletes the tweet with id `1`, but it is routed based on the
79
- user. The document is not deleted if the correct routing is not specified.
90
+ The above will delete a tweet with id `1`, but will be routed based on the
91
+ user. Note that issuing a delete without the correct routing will cause the
92
+ document to not be deleted.
93
+
94
+ When the `_routing` mapping is set as `required` and no routing value is
95
+ specified, the delete API will throw a `RoutingMissingException` and reject
96
+ the request.
80
97
81
98
[float]
82
99
[[delete-index-creation]]
83
- ===== Automatic index creation
100
+ ==== Automatic index creation
84
101
85
102
If an <<docs-index_,external versioning variant>> is used,
86
- the delete operation automatically creates the specified index if it does not
87
- exist. For information about manually creating indices, see
88
- <<indices-create-index,create index API>> .
103
+ the delete operation automatically creates an index if it has not been
104
+ created before (check out the << indices-create-index,create index API>>
105
+ for manually creating an index) .
89
106
90
107
[float]
91
108
[[delete-distributed]]
92
- ===== Distributed
109
+ ==== Distributed
93
110
94
111
The delete operation gets hashed into a specific shard id. It then gets
95
112
redirected into the primary shard within that id group, and replicated
96
113
(if needed) to shard replicas within that id group.
97
114
98
115
[float]
99
116
[[delete-wait-for-active-shards]]
100
- ===== Wait for active shards
117
+ ==== Wait For Active Shards
101
118
102
119
When making delete requests, you can set the `wait_for_active_shards`
103
120
parameter to require a minimum number of shard copies to be active
@@ -107,14 +124,15 @@ example.
107
124
108
125
[float]
109
126
[[delete-refresh]]
110
- ===== Refresh
127
+ ==== Refresh
111
128
112
129
Control when the changes made by this request are visible to search. See
113
130
<<docs-refresh>>.
114
131
132
+
115
133
[float]
116
134
[[delete-timeout]]
117
- ===== Timeout
135
+ ==== Timeout
118
136
119
137
The primary shard assigned to perform the delete operation might not be
120
138
available when the delete operation is executed. Some reasons for this
@@ -131,68 +149,3 @@ DELETE /twitter/_doc/1?timeout=5m
131
149
--------------------------------------------------
132
150
// CONSOLE
133
151
// TEST[setup:twitter]
134
-
135
- [[docs-delete-api-path-params]]
136
- ==== {api-path-parms-title}
137
-
138
- `<index>`::
139
- (Required, string) Name of the target index.
140
-
141
- `<_id>`::
142
- (Required, string) Unique identifier for the document.
143
-
144
- [[docs-delete-api-query-params]]
145
- ==== {api-query-parms-title}
146
-
147
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-seq-no]
148
-
149
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-primary-term]
150
-
151
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-pipeline]
152
-
153
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-refresh]
154
-
155
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-routing]
156
-
157
- include::{docdir}/rest-api/common-parms.asciidoc[tag=timeout]
158
-
159
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-version]
160
-
161
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-version-type]
162
-
163
- include::{docdir}/rest-api/common-parms.asciidoc[tag=doc-wait-for-active-shards]
164
-
165
- [[docs-delete-api-example]]
166
- ==== {api-examples-title}
167
-
168
- Delete the JSON document `1` from the `twitter` index:
169
-
170
- [source,js]
171
- --------------------------------------------------
172
- DELETE /twitter/_doc/1
173
- --------------------------------------------------
174
- // CONSOLE
175
- // TEST[setup:twitter]
176
-
177
- The API returns the following result:
178
-
179
- [source,js]
180
- --------------------------------------------------
181
- {
182
- "_shards" : {
183
- "total" : 2,
184
- "failed" : 0,
185
- "successful" : 2
186
- },
187
- "_index" : "twitter",
188
- "_type" : "_doc",
189
- "_id" : "1",
190
- "_version" : 2,
191
- "_primary_term": 1,
192
- "_seq_no": 5,
193
- "result": "deleted"
194
- }
195
- --------------------------------------------------
196
- // TESTRESPONSE[s/"successful" : 2/"successful" : 1/]
197
- // TESTRESPONSE[s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
198
- // TESTRESPONSE[s/"_seq_no" : 5/"_seq_no" : $body._seq_no/]
0 commit comments