Skip to content

Commit 58a6ef0

Browse files
committed
SNAPSHOT - Working with new param
1 parent 6a4c23d commit 58a6ef0

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/cat.segments.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@
9191
"micros",
9292
"nanos"
9393
]
94+
},
95+
"expand_wildcards": {
96+
"type": "enum",
97+
"options": [
98+
"open",
99+
"closed",
100+
"hidden",
101+
"none",
102+
"all"
103+
],
104+
"default": "all",
105+
"description": "Whether to expand wildcard expression to concrete indices that are open, closed or both."
106+
},
107+
"allow_closed": {
108+
"type": "boolean",
109+
"description": "If true, allow closed indices to be returned in the response otherwise if false, keep the legacy behaviour of throwing an exception if index pattern matches closed indices",
110+
"default": false
94111
}
95112
}
96113
}

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cat.segments/10_basic.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,56 @@ tsdb:
209209
$body: |
210210
/^(tsdb \s+ 0 \s+ p \s+ \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \s+ _\d (\s\d){3} \s+
211211
(\d+|\d+[.]\d+)(kb|b) \s+ \d+ (\s+ (false|true)){2} \s+ \d+\.\d+(\.\d+)? \s+ (false|true) \s? \n?)$/
212+
213+
---
214+
Wildcard Expansion Settings:
215+
- do:
216+
indices.create:
217+
index: basic-index
218+
- do:
219+
index:
220+
index: basic-index
221+
id: "1"
222+
body:
223+
field: "basic doc 1"
224+
225+
- do:
226+
indices.create:
227+
index: hidden-index
228+
body:
229+
settings:
230+
index.hidden: true
231+
- do:
232+
index:
233+
index: hidden-index
234+
id: "1"
235+
body:
236+
field: "hidden doc 1"
237+
238+
- do:
239+
indices.create:
240+
index: closed-index
241+
- do:
242+
index:
243+
index: closed-index
244+
id: "1"
245+
body:
246+
field: "closed doc 1"
247+
248+
- do:
249+
indices.refresh:
250+
index: [ basic-index, closed-index, hidden-index ]
251+
252+
- do:
253+
indices.close:
254+
index: closed-index
255+
256+
- do:
257+
cat.segments:
258+
v: true
259+
s: index
260+
expand_wildcards: all
261+
allow_closed: true
262+
- match:
263+
$body: |
264+
/basic-index.*false(\s)+true.*\nclosed-index.*true(\s)+false.*\nhidden-index.*false(\s)+true.*/

server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ protected RestChannelConsumer doCatRequest(final RestRequest request, final Node
6363
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest(getMasterNodeTimeout(request));
6464
RestUtils.consumeDeprecatedLocalParameter(request);
6565

66-
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.lenientExpandOpen());
66+
boolean allowClosed = request.paramAsBoolean("allow_closed", false);
67+
IndicesOptions defaultOptions = allowClosed
68+
? IndicesOptions.strictExpandHidden()
69+
: IndicesOptions.strictExpandOpenAndForbidClosed();
70+
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, defaultOptions);
71+
6772
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices).indicesOptions(indicesOptions);
6873

6974
final RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, request.getHttpChannel());
7075

71-
return channel -> cancelClient.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
76+
return channel -> cancelClient.admin().cluster().state(clusterStateRequest, new RestActionListener<>(channel) {
7277
@Override
7378
public void processResponse(final ClusterStateResponse clusterStateResponse) {
7479
final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
7580
indicesSegmentsRequest.indices(indices).indicesOptions(indicesOptions);
76-
cancelClient.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {
81+
cancelClient.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<>(channel) {
7782
@Override
7883
public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
7984
if (request.getHttpChannel().isOpen() == false) {

0 commit comments

Comments
 (0)