@@ -224,7 +224,7 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
224
224
}
225
225
} else if (indexAbstraction .getType () == IndexAbstraction .Type .DATA_STREAM &&
226
226
context .includeDataStreams () == false ) {
227
- throw dataStreamsNotSupportedException ( expression ) ;
227
+ continue ;
228
228
}
229
229
230
230
if (indexAbstraction .getType () == IndexAbstraction .Type .ALIAS && context .isResolveToWriteIndex ()) {
@@ -298,11 +298,6 @@ private static IllegalArgumentException aliasesNotSupportedException(String expr
298
298
"alias, specify the corresponding concrete indices instead." );
299
299
}
300
300
301
- private static IllegalArgumentException dataStreamsNotSupportedException (String expression ) {
302
- return new IllegalArgumentException ("The provided expression [" + expression + "] matches a " +
303
- "data stream, specify the corresponding concrete indices instead." );
304
- }
305
-
306
301
/**
307
302
* Utility method that allows to resolve an index expression to its corresponding single concrete index.
308
303
* Callers should make sure they provide proper {@link org.elasticsearch.action.support.IndicesOptions}
@@ -354,7 +349,12 @@ public Index concreteWriteIndex(ClusterState state, IndicesRequest request) {
354
349
*/
355
350
public Index concreteWriteIndex (ClusterState state , IndicesOptions options , String index , boolean allowNoIndices ,
356
351
boolean includeDataStreams ) {
357
- Context context = new Context (state , options , false , true , includeDataStreams );
352
+ IndicesOptions combinedOptions = IndicesOptions .fromOptions (options .ignoreUnavailable (), allowNoIndices ,
353
+ options .expandWildcardsOpen (), options .expandWildcardsClosed (), options .expandWildcardsHidden (),
354
+ options .allowAliasesToMultipleIndices (), options .forbidClosedIndices (), options .ignoreAliases (),
355
+ options .ignoreThrottled ());
356
+
357
+ Context context = new Context (state , combinedOptions , false , true , includeDataStreams );
358
358
Index [] indices = concreteIndices (context , index );
359
359
if (allowNoIndices && indices .length == 0 ) {
360
360
return null ;
@@ -729,10 +729,6 @@ public List<String> resolve(Context context, List<String> expressions) {
729
729
}
730
730
731
731
if (isEmptyOrTrivialWildcard (expressions )) {
732
- if (context .includeDataStreams () == false && metadata .dataStreams ().isEmpty () == false ) {
733
- throw dataStreamsNotSupportedException (expressions .toString ());
734
- }
735
-
736
732
List <String > resolvedExpressions = resolveEmptyOrTrivialWildcard (options , metadata );
737
733
if (context .includeDataStreams ()) {
738
734
final IndexMetadata .State excludeState = excludeState (options );
@@ -797,8 +793,8 @@ private Set<String> innerResolve(Context context, List<String> expressions, Indi
797
793
} else if (indexAbstraction .getType () == IndexAbstraction .Type .ALIAS && options .ignoreAliases ()) {
798
794
throw aliasesNotSupportedException (expression );
799
795
} else if (indexAbstraction .getType () == IndexAbstraction .Type .DATA_STREAM &&
800
- context .includeDataStreams () == false ) {
801
- throw dataStreamsNotSupportedException (expression );
796
+ context .includeDataStreams () == false ) {
797
+ throw indexNotFoundException (expression );
802
798
}
803
799
}
804
800
if (add ) {
@@ -878,7 +874,7 @@ private static IndexMetadata.State excludeState(IndicesOptions options) {
878
874
879
875
public static Map <String , IndexAbstraction > matches (Context context , Metadata metadata , String expression ) {
880
876
if (Regex .isMatchAllPattern (expression )) {
881
- return filterIndicesLookup (context , metadata .getIndicesLookup (), null , expression , context .getOptions ());
877
+ return filterIndicesLookup (context , metadata .getIndicesLookup (), null , context .getOptions ());
882
878
} else if (expression .indexOf ("*" ) == expression .length () - 1 ) {
883
879
return suffixWildcard (context , metadata , expression );
884
880
} else {
@@ -893,18 +889,17 @@ private static Map<String, IndexAbstraction> suffixWildcard(Context context, Met
893
889
toPrefixCharArr [toPrefixCharArr .length - 1 ]++;
894
890
String toPrefix = new String (toPrefixCharArr );
895
891
SortedMap <String , IndexAbstraction > subMap = metadata .getIndicesLookup ().subMap (fromPrefix , toPrefix );
896
- return filterIndicesLookup (context , subMap , null , expression , context .getOptions ());
892
+ return filterIndicesLookup (context , subMap , null , context .getOptions ());
897
893
}
898
894
899
895
private static Map <String , IndexAbstraction > otherWildcard (Context context , Metadata metadata , String expression ) {
900
896
final String pattern = expression ;
901
897
return filterIndicesLookup (context , metadata .getIndicesLookup (), e -> Regex .simpleMatch (pattern , e .getKey ()),
902
- expression , context .getOptions ());
898
+ context .getOptions ());
903
899
}
904
900
905
901
private static Map <String , IndexAbstraction > filterIndicesLookup (Context context , SortedMap <String , IndexAbstraction > indicesLookup ,
906
902
Predicate <? super Map .Entry <String , IndexAbstraction >> filter ,
907
- String expression ,
908
903
IndicesOptions options ) {
909
904
boolean shouldConsumeStream = false ;
910
905
Stream <Map .Entry <String , IndexAbstraction >> stream = indicesLookup .entrySet ().stream ();
@@ -918,11 +913,7 @@ private static Map<String, IndexAbstraction> filterIndicesLookup(Context context
918
913
}
919
914
if (context .includeDataStreams () == false ) {
920
915
shouldConsumeStream = true ;
921
- stream = stream .peek (e -> {
922
- if (e .getValue ().getType () == IndexAbstraction .Type .DATA_STREAM ) {
923
- throw dataStreamsNotSupportedException (expression );
924
- }
925
- });
916
+ stream = stream .filter (e -> e .getValue ().getType () != IndexAbstraction .Type .DATA_STREAM );
926
917
}
927
918
if (shouldConsumeStream ) {
928
919
return stream .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
0 commit comments