18
18
import org .elasticsearch .common .util .CollectionUtils ;
19
19
import org .elasticsearch .datastreams .DataStreamsPlugin ;
20
20
import org .elasticsearch .index .IndexNotFoundException ;
21
+ import org .elasticsearch .index .query .MatchAllQueryBuilder ;
22
+ import org .elasticsearch .index .query .MatchNoneQueryBuilder ;
21
23
import org .elasticsearch .plugins .Plugin ;
22
24
import org .elasticsearch .xpack .esql .VerificationException ;
23
25
import org .elasticsearch .xpack .esql .action .AbstractEsqlIntegTestCase ;
@@ -96,11 +98,24 @@ public void testResolvesPattern() {
96
98
}
97
99
}
98
100
99
- public void testDoesNotResolveMissingIndex () {
101
+ public void testResolvesExclusionPattern () {
102
+ assertAcked (client ().admin ().indices ().prepareCreate ("index-1" ));
103
+ indexRandom (true , "index-1" , 1 );
104
+ assertAcked (client ().admin ().indices ().prepareCreate ("index-2" ));
105
+ indexRandom (true , "index-2" , 1 );
106
+
107
+ try (var response = run (syncEsqlQueryRequest ().query ("FROM index*,-index-2 METADATA _index" ))) {
108
+ assertOk (response );
109
+ assertResultConcreteIndices (response , "index-1" );// excludes concrete index from pattern
110
+ }
111
+ try (var response = run (syncEsqlQueryRequest ().query ("FROM index*,-*2 METADATA _index" ))) {
112
+ assertOk (response );
113
+ assertResultConcreteIndices (response , "index-1" );// excludes pattern from pattern
114
+ }
100
115
expectThrows (
101
116
VerificationException .class ,
102
- containsString ("Unknown index [no-such-index ]" ),
103
- () -> run (syncEsqlQueryRequest ().query ("FROM no-such-index " ))
117
+ containsString ("Unknown index [index-*,-* ]" ),
118
+ () -> run (syncEsqlQueryRequest ().query ("FROM index-*,-* METADATA _index " )) // exclude all resolves to empty
104
119
);
105
120
}
106
121
@@ -120,6 +135,14 @@ public void testDoesNotResolveEmptyPattern() {
120
135
}
121
136
}
122
137
138
+ public void testDoesNotResolveUnknownIndex () {
139
+ expectThrows (
140
+ VerificationException .class ,
141
+ containsString ("Unknown index [no-such-index]" ),
142
+ () -> run (syncEsqlQueryRequest ().query ("FROM no-such-index" ))
143
+ );
144
+ }
145
+
123
146
public void testDoesNotResolveClosedIndex () {
124
147
assertAcked (client ().admin ().indices ().prepareCreate ("index-1" ));
125
148
indexRandom (true , "index-1" , 1 );
@@ -219,6 +242,20 @@ public void testPartialResolution() {
219
242
);
220
243
}
221
244
245
+ public void testResolutionWithFilter () {
246
+ assertAcked (client ().admin ().indices ().prepareCreate ("data" ));
247
+ indexRandom (true , "data" , 1 );
248
+
249
+ try (var response = run (syncEsqlQueryRequest ().query ("FROM data METADATA _index" ).filter (new MatchAllQueryBuilder ()))) {
250
+ assertOk (response );
251
+ assertResultConcreteIndices (response , "data" );
252
+ }
253
+ try (var response = run (syncEsqlQueryRequest ().query ("FROM data METADATA _index" ).filter (new MatchNoneQueryBuilder ()))) {
254
+ assertOk (response );
255
+ assertResultConcreteIndices (response );
256
+ }
257
+ }
258
+
222
259
private static void assertOk (EsqlQueryResponse response ) {
223
260
assertThat (response .isPartial (), equalTo (false ));
224
261
}
0 commit comments