@@ -430,7 +430,11 @@ public boolean isPartOfDataStream() {
430430 public boolean checkIndex (Group group ) {
431431 final DataStream ds = indexAbstraction == null ? null : indexAbstraction .getParentDataStream ();
432432 if (ds != null ) {
433- if (group .checkIndex (ds .getName ())) {
433+ boolean isFailureStoreIndex = ds .isFailureStoreIndex (indexAbstraction .getName ());
434+ if (isFailureStoreIndex
435+ && group .checkIndex (IndexNameExpressionResolver .combineSelector (ds .getName (), IndexComponentSelector .FAILURES ))) {
436+ return true ;
437+ } else if (isFailureStoreIndex == false && group .checkIndex (ds .getName ())) {
434438 return true ;
435439 }
436440 }
@@ -907,12 +911,9 @@ static String convertToExcludeFailures(String indexPattern) {
907911 assert indexPattern != "*" : "* is a special case and should never exclude failures" ;
908912 assert indexPattern .endsWith ("*" ) || Automatons .isLuceneRegex (indexPattern )
909913 : "Only patterns with a trailing wildcard " + "or regular expressions should explicitly exclude failures" ;
910- // TODO: [Jake] also properly convert `?` and properly escape any characters such as `.` that is valid in index names but have
911- // special meaning in the regular expression
912914 StringBuilder sb = new StringBuilder ();
913915 if (indexPattern .endsWith ("*" )) {
914- // using Strings.replace instead of String.replaceAll to avoid regex compilation
915- String inny = Strings .replace (indexPattern , "*" , ".*" );
916+ String inny = globToRegex (indexPattern );
916917 return sb .append ("/(" ).append (inny ).append (")&~(" ).append (inny ).append ("::failures)/" ).toString ();
917918 } else if (Automatons .isLuceneRegex (indexPattern )) {
918919 String inny = indexPattern .substring (1 , indexPattern .length () - 1 );
@@ -922,6 +923,43 @@ static String convertToExcludeFailures(String indexPattern) {
922923 }
923924 }
924925
926+ private static String globToRegex (String glob ) {
927+ StringBuilder sb = new StringBuilder ();
928+ for (int i = 0 ; i < glob .length (); i ++) {
929+ char c = glob .charAt (i );
930+ switch (c ) {
931+ case '*' :
932+ sb .append (".*" );
933+ break ;
934+ case '?' :
935+ sb .append ('.' );
936+ break ;
937+ case '.' :
938+ case '(' :
939+ case ')' :
940+ case '[' :
941+ case ']' :
942+ case '{' :
943+ case '}' :
944+ case '\\' :
945+ case '\"' :
946+ case '|' :
947+ case '+' :
948+ case '#' :
949+ case '@' :
950+ case '<' :
951+ case '>' :
952+ case '~' :
953+ sb .append ('\\' ).append (c );
954+ break ;
955+ default :
956+ sb .append (c );
957+ break ;
958+ }
959+ }
960+ return sb .toString ();
961+ }
962+
925963 public IndexPrivilege privilege () {
926964 return privilege ;
927965 }
0 commit comments