@@ -296,14 +296,38 @@ private ImmutableOpenMap<String, List<AliasMetaData>> findAliases(String[] origi
296296 return ImmutableOpenMap .of ();
297297 }
298298
299- boolean matchAllAliases = matchAllAliases (aliases );
299+ String [] patterns = new String [aliases .length ];
300+ boolean [] include = new boolean [aliases .length ];
301+ for (int i = 0 ; i < aliases .length ; i ++) {
302+ String alias = aliases [i ];
303+ if (alias .charAt (0 ) == '-' ) {
304+ patterns [i ] = alias .substring (1 );
305+ include [i ] = false ;
306+ } else {
307+ patterns [i ] = alias ;
308+ include [i ] = true ;
309+ }
310+ }
311+ boolean matchAllAliases = patterns .length == 0 ;
300312 ImmutableOpenMap .Builder <String , List <AliasMetaData >> mapBuilder = ImmutableOpenMap .builder ();
301313 for (String index : concreteIndices ) {
302314 IndexMetaData indexMetaData = indices .get (index );
303315 List <AliasMetaData > filteredValues = new ArrayList <>();
304316 for (ObjectCursor <AliasMetaData > cursor : indexMetaData .getAliases ().values ()) {
305317 AliasMetaData value = cursor .value ;
306- if (matchAllAliases || Regex .simpleMatch (aliases , value .alias ())) {
318+ boolean matched = matchAllAliases ;
319+ String alias = value .alias ();
320+ for (int i = 0 ; i < patterns .length ; i ++) {
321+ if (include [i ]) {
322+ if (matched == false ) {
323+ String pattern = patterns [i ];
324+ matched = ALL .equals (pattern ) || Regex .simpleMatch (pattern , alias );
325+ }
326+ } else if (matched ) {
327+ matched = Regex .simpleMatch (patterns [i ], alias ) == false ;
328+ }
329+ }
330+ if (matched ) {
307331 filteredValues .add (value );
308332 }
309333 }
@@ -317,15 +341,6 @@ private ImmutableOpenMap<String, List<AliasMetaData>> findAliases(String[] origi
317341 return mapBuilder .build ();
318342 }
319343
320- private static boolean matchAllAliases (final String [] aliases ) {
321- for (String alias : aliases ) {
322- if (alias .equals (ALL )) {
323- return true ;
324- }
325- }
326- return aliases .length == 0 ;
327- }
328-
329344 /**
330345 * Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the
331346 * alias names for partial matches.
0 commit comments