Skip to content

Commit 201ca9c

Browse files
committed
Add tests
1 parent bcac7ee commit 201ca9c

File tree

4 files changed

+158
-38
lines changed

4 files changed

+158
-38
lines changed
Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,60 @@
11
{
2-
"indices.resolve_index":{
3-
"documentation":{
4-
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index-api.html",
5-
"description":"Returns information about any matching indices, aliases, and data streams"
2+
"indices.resolve_index": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index-api.html",
5+
"description": "Returns information about any matching indices, aliases, and data streams"
66
},
7-
"stability":"stable",
8-
"visibility":"public",
9-
"headers":{
10-
"accept": [ "application/json"]
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
1113
},
12-
"url":{
13-
"paths":[
14+
"url": {
15+
"paths": [
1416
{
15-
"path":"/_resolve/index/{name}",
16-
"methods":[
17+
"path": "/_resolve/index/{name}",
18+
"methods": [
1719
"GET"
1820
],
19-
"parts":{
20-
"name":{
21-
"type":"list",
22-
"description":"A comma-separated list of names or wildcard expressions"
21+
"parts": {
22+
"name": {
23+
"type": "list",
24+
"description": "A comma-separated list of names or wildcard expressions"
2325
}
2426
}
2527
}
2628
]
2729
},
28-
"params":{
29-
"expand_wildcards":{
30-
"type":"enum",
31-
"options":[
30+
"params": {
31+
"expand_wildcards": {
32+
"type": "enum",
33+
"options": [
3234
"open",
3335
"closed",
3436
"hidden",
3537
"none",
3638
"all"
3739
],
38-
"default":"open",
39-
"description":"Whether wildcard expressions should get expanded to open or closed indices (default: open)"
40+
"default": "open",
41+
"description": "Whether wildcard expressions should get expanded to open or closed indices (default: open)"
42+
},
43+
"ignore_unavailable": {
44+
"type": "boolean",
45+
"description": "Whether specified concrete indices should be ignored when unavailable (missing or closed)",
46+
"default": false
4047
},
41-
"ignore_unavailable":{
42-
"type":"boolean",
43-
"description":"Whether specified concrete indices should be ignored when unavailable (missing or closed)",
44-
"default":false
48+
"allow_no_indices": {
49+
"type": "boolean",
50+
"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)",
51+
"default": true
4552
},
46-
"allow_no_indices":{
47-
"type":"boolean",
48-
"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)",
49-
"default":true
53+
"mode": {
54+
"type": "string",
55+
"description": "Filter indices by index mode"
5056
}
5157
}
5258
}
5359
}
60+
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
setup:
3+
- do:
4+
indices.create:
5+
index: my-std-index
6+
body:
7+
settings:
8+
number_of_shards: 1
9+
number_of_replicas: 0
10+
aliases:
11+
my-std-alias: { }
12+
13+
# Create a time-series index
14+
- do:
15+
indices.create:
16+
index: my-ts-index
17+
body:
18+
settings:
19+
index.mode: time_series
20+
number_of_shards: 1
21+
number_of_replicas: 0
22+
index.routing_path: [ "host" ]
23+
mappings:
24+
properties:
25+
"@timestamp":
26+
type: date
27+
host:
28+
type: keyword
29+
time_series_dimension: true
30+
metric:
31+
type: keyword
32+
value:
33+
type: double
34+
aliases:
35+
my-ts-alias: { }
36+
# Create a lookup index
37+
- do:
38+
indices.create:
39+
index: my-lookup-index
40+
body:
41+
settings:
42+
index.mode: lookup
43+
aliases:
44+
my-lookup-alias: { }
45+
46+
---
47+
"resolve index filters by mode":
48+
- requires:
49+
test_runner_features: [ capabilities ]
50+
capabilities:
51+
- method: GET
52+
path: /_resolve/index/*
53+
capabilities: [ mode_filter ]
54+
reason: "Need support for mode filtering in indices.resolve_index"
55+
56+
- do:
57+
indices.resolve_index:
58+
name: 'my-*'
59+
mode: lookup
60+
- length: { indices: 1 }
61+
- match: { indices.0.name: "my-lookup-index" }
62+
- match: { indices.0.mode: "lookup" }
63+
- match: { indices.0.aliases: [ "my-lookup-alias" ] }
64+
- length: { aliases: 1 }
65+
- match: { aliases.0.name: "my-lookup-alias" }
66+
- match: { aliases.0.indices: [ "my-lookup-index" ] }
67+
68+
---
69+
"resolve index filters by mode, multiple modes":
70+
- requires:
71+
test_runner_features: [ capabilities ]
72+
capabilities:
73+
- method: GET
74+
path: /_resolve/index/*
75+
capabilities: [ mode_filter ]
76+
reason: "Need support for mode filtering in indices.resolve_index"
77+
78+
- do:
79+
indices.resolve_index:
80+
name: 'my-*'
81+
mode: time_series,standard
82+
- length: { indices: 2 }
83+
- match: { indices.0.name: "my-std-index" }
84+
- match: { indices.0.mode: "standard" }
85+
- match: { indices.0.aliases: [ "my-std-alias" ] }
86+
- match: { indices.1.name: "my-ts-index" }
87+
- match: { indices.1.mode: "time_series" }
88+
- match: { indices.1.aliases: [ "my-ts-alias" ] }
89+
- length: { aliases: 2 }
90+
- match: { aliases.0.name: "my-std-alias" }
91+
- match: { aliases.0.indices: [ "my-std-index" ] }
92+
- match: { aliases.1.name: "my-ts-alias" }
93+
- match: { aliases.1.indices: [ "my-ts-index" ] }
94+
95+
---
96+
teardown:
97+
- do:
98+
indices.delete:
99+
index: my-std-index
100+
ignore_unavailable: true
101+
- do:
102+
indices.delete:
103+
index: my-ts-index
104+
ignore_unavailable: true
105+
- do:
106+
indices.delete:
107+
index: my-lookup-index
108+
ignore_unavailable: true

server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,21 +735,16 @@ private static void enrichIndexAbstraction(
735735
);
736736
}
737737
case ALIAS -> {
738-
if (indexModes.isEmpty() == false && indexModes.contains(IndexMode.STANDARD) == false) {
739-
// If we didn't ask for standard indices, skip aliases too
740-
return;
741-
}
742738
String[] indexNames = getAliasIndexStream(resolvedExpression, ia, projectState.metadata()).filter(filterPredicate)
743739
.map(Index::getName)
744740
.toArray(String[]::new);
741+
if (indexModes.isEmpty() == false && indexNames.length == 0) {
742+
return;
743+
}
745744
Arrays.sort(indexNames);
746745
aliases.add(new ResolvedAlias(ia.getName(), indexNames));
747746
}
748747
case DATA_STREAM -> {
749-
if (indexModes.isEmpty() == false && indexModes.contains(IndexMode.STANDARD) == false) {
750-
// If we didn't ask for standard indices, skip datastreams too
751-
return;
752-
}
753748
DataStream dataStream = (DataStream) ia;
754749
Stream<Index> dataStreamIndices = resolvedExpression.selector() == null
755750
? dataStream.getIndices().stream()
@@ -758,6 +753,9 @@ private static void enrichIndexAbstraction(
758753
case FAILURES -> dataStream.getFailureIndices().stream();
759754
};
760755
String[] backingIndices = dataStreamIndices.filter(filterPredicate).map(Index::getName).toArray(String[]::new);
756+
if (indexModes.isEmpty() == false && backingIndices.length == 0) {
757+
return;
758+
}
761759
dataStreams.add(new ResolvedDataStream(dataStream.getName(), backingIndices, DataStream.TIMESTAMP_FIELD_NAME));
762760
}
763761
default -> throw new IllegalStateException("unknown index abstraction type: " + ia.getType());

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResolveIndexAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import java.util.Arrays;
2525
import java.util.EnumSet;
2626
import java.util.List;
27+
import java.util.Set;
2728

2829
import static org.elasticsearch.rest.RestRequest.Method.GET;
2930

3031
@ServerlessScope(Scope.PUBLIC)
3132
public class RestResolveIndexAction extends BaseRestHandler {
33+
private static final Set<String> CAPABILITIES = Set.of("mode_filter");
3234

3335
@Override
3436
public String getName() {
@@ -40,6 +42,11 @@ public List<Route> routes() {
4042
return List.of(new Route(GET, "/_resolve/index/{name}"));
4143
}
4244

45+
@Override
46+
public Set<String> supportedCapabilities() {
47+
return CAPABILITIES;
48+
}
49+
4350
@Override
4451
protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
4552
String[] indices = Strings.splitStringByCommaToArray(request.param("name"));

0 commit comments

Comments
 (0)