Skip to content

Commit 0b25da3

Browse files
committed
Add REST interface for RemoveBlock API
- Add RestRemoveIndexBlockAction for DELETE /{index}/_block/{block} - Add indices.remove_block.json API specification - Update YAML REST tests and documentation - Remove shards_acknowledged field references from docs Completes public HTTP interface providing symmetry with addBlock API.
1 parent 4f223be commit 0b25da3

File tree

4 files changed

+234
-3
lines changed

4 files changed

+234
-3
lines changed

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. Unlike the add index block API, this operation doesn't require shard-level verification and completes immediately after updating the cluster metadata.
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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@
2424
index: test_index
2525

2626
- do:
27-
indices.put_settings:
27+
indices.remove_block:
2828
index: test_index
29-
body:
30-
index.blocks.write: false
29+
block: write
30+
- is_true: acknowledged
31+
32+
- do:
33+
index:
34+
index: test_index
35+
body: { foo: bar }
36+
37+
- do:
38+
search:
39+
index: test_index
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.rest.action.admin.indices;
11+
12+
import org.elasticsearch.action.admin.indices.readonly.RemoveIndexBlockRequest;
13+
import org.elasticsearch.action.support.IndicesOptions;
14+
import org.elasticsearch.client.internal.node.NodeClient;
15+
import org.elasticsearch.cluster.metadata.IndexMetadata;
16+
import org.elasticsearch.common.Strings;
17+
import org.elasticsearch.rest.BaseRestHandler;
18+
import org.elasticsearch.rest.RestRequest;
19+
import org.elasticsearch.rest.ServerlessScope;
20+
import org.elasticsearch.rest.action.RestToXContentListener;
21+
22+
import java.io.IOException;
23+
import java.util.List;
24+
25+
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
26+
import static org.elasticsearch.rest.RestUtils.getAckTimeout;
27+
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout;
28+
import static org.elasticsearch.rest.Scope.PUBLIC;
29+
30+
@ServerlessScope(PUBLIC)
31+
public class RestRemoveIndexBlockAction extends BaseRestHandler {
32+
33+
@Override
34+
public List<Route> routes() {
35+
return List.of(new Route(DELETE, "/{index}/_block/{block}"));
36+
}
37+
38+
@Override
39+
public String getName() {
40+
return "remove_index_block_action";
41+
}
42+
43+
@Override
44+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
45+
RemoveIndexBlockRequest removeIndexBlockRequest = new RemoveIndexBlockRequest(
46+
IndexMetadata.APIBlock.fromName(request.param("block")),
47+
Strings.splitStringByCommaToArray(request.param("index"))
48+
);
49+
removeIndexBlockRequest.masterNodeTimeout(getMasterNodeTimeout(request));
50+
removeIndexBlockRequest.ackTimeout(getAckTimeout(request));
51+
removeIndexBlockRequest.indicesOptions(IndicesOptions.fromRequest(request, removeIndexBlockRequest.indicesOptions()));
52+
return channel -> client.admin().indices().removeBlock(removeIndexBlockRequest, new RestToXContentListener<>(channel));
53+
}
54+
}

0 commit comments

Comments
 (0)