1
1
[[docs-delete]]
2
2
=== Delete API
3
+ ++++
4
+ <titleabbrev>Delete</titleabbrev>
5
+ ++++
3
6
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`:
7
+ Removes a JSON document from the specified index.
7
8
8
- [source,js]
9
- --------------------------------------------------
10
- DELETE /twitter/_doc/1
11
- --------------------------------------------------
12
- // CONSOLE
13
- // TEST[setup:twitter]
9
+ [[docs-delete-api-request]]
10
+ ==== {api-request-title}
14
11
15
- The result of the above delete operation is:
12
+ `DELETE /<index>/_doc/<_id>`
16
13
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/]
14
+ [[docs-delete-api-desc]]
15
+ ==== {api-description-title}
16
+
17
+ You use DELETE to remove a document from an index. You must specify the
18
+ index name and document ID.
37
19
38
20
[float]
39
21
[[optimistic-concurrency-control-delete]]
40
- ==== Optimistic concurrency control
22
+ ===== Optimistic concurrency control
41
23
42
24
Delete operations can be made conditional and only be performed if the last
43
- modification to the document was assigned the sequence number and primary
25
+ modification to the document was assigned the sequence number and primary
44
26
term specified by the `if_seq_no` and `if_primary_term` parameters. If a
45
27
mismatch is detected, the operation will result in a `VersionConflictException`
46
- and a status code of 409. See <<optimistic-concurrency-control>> for more details.
28
+ and a status code of 409. See <<optimistic-concurrency-control>> for more details.
47
29
48
30
[float]
49
31
[[delete-versioning]]
50
- ==== Versioning
32
+ ===== Versioning
51
33
52
34
Each document indexed is versioned. When deleting a document, the `version` can
53
35
be specified to make sure the relevant document we are trying to delete is
@@ -60,11 +42,17 @@ determined by the `index.gc_deletes` index setting and defaults to 60 seconds.
60
42
61
43
[float]
62
44
[[delete-routing]]
63
- ==== 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:
64
55
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:
68
56
69
57
////
70
58
Example to delete with routing
@@ -87,34 +75,29 @@ DELETE /twitter/_doc/1?routing=kimchy
87
75
// CONSOLE
88
76
// TEST[continued]
89
77
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.
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.
97
80
98
81
[float]
99
82
[[delete-index-creation]]
100
- ==== Automatic index creation
83
+ ===== Automatic index creation
101
84
102
85
If an <<docs-index_,external versioning variant>> is used,
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) .
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>> .
106
89
107
90
[float]
108
91
[[delete-distributed]]
109
- ==== Distributed
92
+ ===== Distributed
110
93
111
94
The delete operation gets hashed into a specific shard id. It then gets
112
95
redirected into the primary shard within that id group, and replicated
113
96
(if needed) to shard replicas within that id group.
114
97
115
98
[float]
116
99
[[delete-wait-for-active-shards]]
117
- ==== Wait For Active Shards
100
+ ===== Wait for active shards
118
101
119
102
When making delete requests, you can set the `wait_for_active_shards`
120
103
parameter to require a minimum number of shard copies to be active
@@ -124,15 +107,14 @@ example.
124
107
125
108
[float]
126
109
[[delete-refresh]]
127
- ==== Refresh
110
+ ===== Refresh
128
111
129
112
Control when the changes made by this request are visible to search. See
130
113
<<docs-refresh>>.
131
114
132
-
133
115
[float]
134
116
[[delete-timeout]]
135
- ==== Timeout
117
+ ===== Timeout
136
118
137
119
The primary shard assigned to perform the delete operation might not be
138
120
available when the delete operation is executed. Some reasons for this
@@ -149,3 +131,68 @@ DELETE /twitter/_doc/1?timeout=5m
149
131
--------------------------------------------------
150
132
// CONSOLE
151
133
// 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