Skip to content

Commit a371f4e

Browse files
HyunSangHannielsbauman
authored andcommitted
Add RemoveBlock API to allow DELETE /{index}/_block/{block} (elastic#129128)
Introduces a new `RemoveBlock` API that complements the existing `AddBlock` API by allowing users to remove index blocks using `DELETE /{index}/_block/{block}`. Resolves elastic#128966 --------- Co-authored-by: Niels Bauman <[email protected]>
1 parent aea4d5f commit a371f4e

File tree

18 files changed

+1264
-0
lines changed

18 files changed

+1264
-0
lines changed

docs/changelog/129128.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129128
2+
summary: Add RemoveBlock API to allow `DELETE /{index}/_block/{block}`
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

docs/reference/elasticsearch/index-settings/index-block.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,106 @@ The API returns following response:
143143
}
144144
```
145145

146+
147+
## Remove index block API [remove-index-block]
148+
149+
Removes an index block from an index.
150+
151+
```console
152+
DELETE /my-index-000001/_block/write
153+
```
154+
155+
156+
### {{api-request-title}} [remove-index-block-api-request]
157+
158+
`DELETE /<index>/_block/<block>`
159+
160+
161+
### {{api-path-parms-title}} [remove-index-block-api-path-params]
162+
163+
`<index>`
164+
: (Optional, string) Comma-separated list or wildcard expression of index names used to limit the request.
165+
166+
By default, you must explicitly name the indices you are removing blocks from. To allow the removal of blocks from indices with `_all`, `*`, or other wildcard expressions, change the `action.destructive_requires_name` setting to `false`. You can update this setting in the `elasticsearch.yml` file or using the [cluster update settings](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-settings) API.
167+
168+
169+
`<block>`
170+
: (Required, string) Block type to remove from the index.
171+
172+
**Valid values**:
173+
174+
`metadata`
175+
: Remove metadata block, allowing metadata changes.
176+
177+
`read`
178+
: Remove read block, allowing read operations.
179+
180+
`read_only`
181+
: Remove read-only block, allowing write operations and metadata changes.
182+
183+
`write`
184+
: Remove write block, allowing write operations.
185+
186+
::::
187+
188+
189+
190+
### {{api-query-parms-title}} [remove-index-block-api-query-params]
191+
192+
`allow_no_indices`
193+
: (Optional, Boolean) If `false`, the request returns an error if any wildcard expression, [index alias](docs-content://manage-data/data-store/aliases.md), or `_all` value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting `foo*,bar*` returns an error if an index starts with `foo` but no index starts with `bar`.
194+
195+
Defaults to `true`.
196+
197+
198+
`expand_wildcards`
199+
: (Optional, string) Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as `open,hidden`. Valid values are:
200+
201+
`all`
202+
: Match any data stream or index, including [hidden](/reference/elasticsearch/rest-apis/api-conventions.md#multi-hidden) ones.
203+
204+
`open`
205+
: Match open, non-hidden indices. Also matches any non-hidden data stream.
206+
207+
`closed`
208+
: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
209+
210+
`hidden`
211+
: Match hidden data streams and hidden indices. Must be combined with `open`, `closed`, or both.
212+
213+
`none`
214+
: Wildcard patterns are not accepted.
215+
216+
Defaults to `open`.
217+
218+
219+
`ignore_unavailable`
220+
: (Optional, Boolean) If `false`, the request returns an error if it targets a missing or closed index. Defaults to `false`.
221+
222+
`master_timeout`
223+
: (Optional, [time units](/reference/elasticsearch/rest-apis/api-conventions.md#time-units)) Period to wait for the master node. If the master node is not available before the timeout expires, the request fails and returns an error. Defaults to `30s`. Can also be set to `-1` to indicate that the request should never timeout.
224+
225+
`timeout`
226+
: (Optional, [time units](/reference/elasticsearch/rest-apis/api-conventions.md#time-units)) Period to wait for a response from all relevant nodes in the cluster after updating the cluster metadata. If no response is received before the timeout expires, the cluster metadata update still applies but the response will indicate that it was not completely acknowledged. Defaults to `30s`. Can also be set to `-1` to indicate that the request should never timeout.
227+
228+
229+
### {{api-examples-title}} [remove-index-block-api-example]
230+
231+
The following example shows how to remove an index block:
232+
233+
```console
234+
DELETE /my-index-000001/_block/write
235+
```
236+
237+
The API returns following response:
238+
239+
```console-result
240+
{
241+
"acknowledged" : true,
242+
"indices" : [ {
243+
"name" : "my-index-000001",
244+
"unblocked" : true
245+
} ]
246+
}
247+
```
248+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"indices.remove_block": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules-blocks.html",
5+
"description": "Removes a block from an index."
6+
},
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
13+
},
14+
"url": {
15+
"paths": [
16+
{
17+
"path": "/{index}/_block/{block}",
18+
"methods": [
19+
"DELETE"
20+
],
21+
"parts": {
22+
"index": {
23+
"type": "list",
24+
"description": "A comma separated list of indices to remove a block from"
25+
},
26+
"block": {
27+
"type": "string",
28+
"description": "The block to remove (one of read, write, read_only or metadata)"
29+
}
30+
}
31+
}
32+
]
33+
},
34+
"params": {
35+
"timeout": {
36+
"type": "time",
37+
"description": "Explicit operation timeout"
38+
},
39+
"master_timeout": {
40+
"type": "time",
41+
"description": "Specify timeout for connection to master"
42+
},
43+
"ignore_unavailable": {
44+
"type": "boolean",
45+
"description": "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
46+
},
47+
"allow_no_indices": {
48+
"type": "boolean",
49+
"description": "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"
50+
},
51+
"expand_wildcards": {
52+
"type": "enum",
53+
"options": [
54+
"open",
55+
"closed",
56+
"hidden",
57+
"none",
58+
"all"
59+
],
60+
"default": "open",
61+
"description": "Whether to expand wildcard expression to concrete indices that are open, closed or both."
62+
}
63+
}
64+
}
65+
}

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.blocks/10_basic.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,46 @@
2828
index: test_index
2929
body:
3030
index.blocks.write: false
31+
32+
---
33+
"Test removing block via remove_block API":
34+
- requires:
35+
test_runner_features: [capabilities]
36+
reason: "index block APIs have only been made available in 9.1.0"
37+
capabilities:
38+
- method: DELETE
39+
path: /{index}/_block/{block}
40+
- do:
41+
indices.create:
42+
index: test_index_2
43+
44+
- do:
45+
indices.add_block:
46+
index: test_index_2
47+
block: write
48+
- is_true: acknowledged
49+
50+
- do:
51+
catch: /cluster_block_exception/
52+
index:
53+
index: test_index_2
54+
body: { foo: bar }
55+
56+
- do:
57+
search:
58+
index: test_index_2
59+
60+
- do:
61+
indices.remove_block:
62+
index: test_index_2
63+
block: write
64+
- is_true: acknowledged
65+
66+
- do:
67+
index:
68+
index: test_index_2
69+
body: { foo: bar }
70+
71+
- do:
72+
search:
73+
index: test_index_2

0 commit comments

Comments
 (0)