Skip to content

Commit fcb0b13

Browse files
committed
update
1 parent 2d9de15 commit fcb0b13

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

docs/reference/elasticsearch/rest-apis/api-conventions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ In multi-target syntax, you can use a comma-separated list to run a request on m
284284

285285
Targets can be excluded by prefixing with the `-` character. This applies to both concrete names and wildcard patterns.
286286
For example, `test*,-test3` resolves to all resources that start with `test` except for the resource named `test3`.
287-
It is possible for exclusion to exclude all resources. For example, `test*,-test*` resolves to an empty set.
287+
It is possible for exclusion to exclude all resources. For example, both `test*,-test*` and `test,-test` resolve to an empty set.
288288
An exclusion affects targets listed _before_ it and has no impact on targets listed _after_ it.
289-
For example, `-test3,test*` resolves to all resources that start with `test`, including `test3`.
289+
For example, `test3*,-test3,test*` resolves to all resources that start with `test`, including `test3`, because it is included
290+
by the last `test*` pattern.
290291

291292
::::{important}
292293
Aliases are resolved after wildcard expressions. This can result in a request that targets an excluded alias. For example, if `test3` is an index alias, the pattern `test*,-test3` still targets the indices for `test3`. To avoid this, exclude the concrete indices for the alias instead.

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,22 +658,51 @@ public void testExclusionByItself() {
658658

659659
public void testExclusionDoesNotAffectFollowingExpressions() {
660660
final var userAvailableIndices = getUserAvailableIndices();
661-
// Exclusion does not affect anything after it
662-
var request = new SearchRequest(randomIndexExclusion(userAvailableIndices), "*");
661+
final String indexExclusion = randomIndexExclusion(userAvailableIndices);
663662
final boolean expandToClosedIndices = randomBoolean();
664663
final boolean expandToHiddenIndices = randomBoolean();
665-
request.indicesOptions(IndicesOptions.fromOptions(false, false, true, expandToClosedIndices, expandToHiddenIndices));
666-
final var expectedIndices = Arrays.stream(userAvailableIndices)
667-
.filter(name -> expandToClosedIndices || name.contains("closed") == false)
668-
.filter(name -> expandToHiddenIndices || name.startsWith(".") == false && name.contains("hidden") == false)
669-
.toArray(String[]::new);
670664

671-
List<String> indices = resolveIndices(request, buildAuthorizedIndices(user, TransportSearchAction.TYPE.name())).getLocal();
672-
assertThat(indices, containsInAnyOrder(expectedIndices));
673-
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
674-
ResolvedIndexExpressions actual = request.getResolvedIndexExpressions();
675-
assertThat(actual, is(notNullValue()));
676-
assertThat(actual.expressions(), contains(resolvedIndexExpression("*", Set.of(expectedIndices), SUCCESS)));
665+
{
666+
// Exclusion does not affect anything after it
667+
var request = new SearchRequest(indexExclusion, "*");
668+
request.indicesOptions(IndicesOptions.fromOptions(false, false, true, expandToClosedIndices, expandToHiddenIndices));
669+
final var expectedIndices = Arrays.stream(userAvailableIndices)
670+
.filter(name -> expandToClosedIndices || name.contains("closed") == false)
671+
.filter(name -> expandToHiddenIndices || name.startsWith(".") == false && name.contains("hidden") == false)
672+
.toArray(String[]::new);
673+
674+
List<String> indices = resolveIndices(request, buildAuthorizedIndices(user, TransportSearchAction.TYPE.name())).getLocal();
675+
assertThat(indices, containsInAnyOrder(expectedIndices));
676+
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
677+
ResolvedIndexExpressions actual = request.getResolvedIndexExpressions();
678+
assertThat(actual, is(notNullValue()));
679+
680+
assertThat(actual.expressions(), contains(resolvedIndexExpression("*", Set.of(expectedIndices), SUCCESS)));
681+
}
682+
683+
{
684+
// Exclusion excludes from prior wildcard but still included by the later wildcard
685+
var request = new SearchRequest("*", indexExclusion, "*");
686+
request.indicesOptions(IndicesOptions.fromOptions(false, false, true, expandToClosedIndices, expandToHiddenIndices));
687+
final var expectedIndices = Arrays.stream(userAvailableIndices)
688+
.filter(name -> expandToClosedIndices || name.contains("closed") == false)
689+
.filter(name -> expandToHiddenIndices || name.startsWith(".") == false && name.contains("hidden") == false)
690+
.toArray(String[]::new);
691+
692+
List<String> indices = resolveIndices(request, buildAuthorizedIndices(user, TransportSearchAction.TYPE.name())).getLocal();
693+
assertThat(Set.copyOf(indices), containsInAnyOrder(expectedIndices));
694+
assertThat(Set.copyOf(List.of(request.indices())), containsInAnyOrder(expectedIndices));
695+
ResolvedIndexExpressions actual = request.getResolvedIndexExpressions();
696+
assertThat(actual, is(notNullValue()));
697+
698+
assertThat(actual.expressions(), contains(resolvedIndexExpression("*", Arrays.stream(expectedIndices).filter(name -> {
699+
if (indexExclusion.endsWith("*")) {
700+
return Regex.simpleMatch(indexExclusion.substring(1), name) == false;
701+
} else {
702+
return name.equals(indexExclusion.substring(1)) == false;
703+
}
704+
}).collect(Collectors.toSet()), SUCCESS), resolvedIndexExpression("*", Set.of(expectedIndices), SUCCESS)));
705+
}
677706
}
678707

679708
public void testExclusionWithoutPriorWildcards() {

0 commit comments

Comments
 (0)