Skip to content

Commit bcac7ee

Browse files
committed
Filter all sets
1 parent 9a13bac commit bcac7ee

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.util.Set;
6565
import java.util.SortedMap;
6666
import java.util.TreeMap;
67+
import java.util.function.Predicate;
6768
import java.util.stream.Stream;
6869

6970
import static org.elasticsearch.action.search.TransportSearchHelper.checkCCSVersionCompatibility;
@@ -679,6 +680,17 @@ private static void mergeResults(
679680
}
680681
}
681682

683+
private static Predicate<Index> indexModeFilter(ProjectState projectState, Set<IndexMode> indexModes) {
684+
if (indexModes.isEmpty()) {
685+
return index -> true;
686+
}
687+
return index -> {
688+
IndexMetadata indexMetadata = projectState.metadata().index(index);
689+
IndexMode mode = indexMetadata.getIndexMode() == null ? IndexMode.STANDARD : indexMetadata.getIndexMode();
690+
return indexModes.contains(mode);
691+
};
692+
}
693+
682694
private static void enrichIndexAbstraction(
683695
ProjectState projectState,
684696
ResolvedExpression resolvedExpression,
@@ -689,16 +701,15 @@ private static void enrichIndexAbstraction(
689701
) {
690702
SortedMap<String, IndexAbstraction> indicesLookup = projectState.metadata().getIndicesLookup();
691703
IndexAbstraction ia = indicesLookup.get(resolvedExpression.resource());
704+
var filterPredicate = indexModeFilter(projectState, indexModes);
692705
if (ia != null) {
693706
switch (ia.getType()) {
694707
case CONCRETE_INDEX -> {
708+
if (filterPredicate.test(ia.getWriteIndex()) == false) {
709+
return;
710+
}
695711
IndexMetadata writeIndex = projectState.metadata().index(ia.getWriteIndex());
696712
IndexMode mode = writeIndex.getIndexMode() == null ? IndexMode.STANDARD : writeIndex.getIndexMode();
697-
if (indexModes.isEmpty() == false) {
698-
if (indexModes.contains(mode) == false) {
699-
return;
700-
}
701-
}
702713
String[] aliasNames = writeIndex.getAliases().keySet().stream().sorted().toArray(String[]::new);
703714
List<Attribute> attributes = new ArrayList<>();
704715
attributes.add(writeIndex.getState() == IndexMetadata.State.OPEN ? Attribute.OPEN : Attribute.CLOSED);
@@ -728,7 +739,8 @@ private static void enrichIndexAbstraction(
728739
// If we didn't ask for standard indices, skip aliases too
729740
return;
730741
}
731-
String[] indexNames = getAliasIndexStream(resolvedExpression, ia, projectState.metadata()).map(Index::getName)
742+
String[] indexNames = getAliasIndexStream(resolvedExpression, ia, projectState.metadata()).filter(filterPredicate)
743+
.map(Index::getName)
732744
.toArray(String[]::new);
733745
Arrays.sort(indexNames);
734746
aliases.add(new ResolvedAlias(ia.getName(), indexNames));
@@ -745,7 +757,7 @@ private static void enrichIndexAbstraction(
745757
case DATA -> dataStream.getDataComponent().getIndices().stream();
746758
case FAILURES -> dataStream.getFailureIndices().stream();
747759
};
748-
String[] backingIndices = dataStreamIndices.map(Index::getName).toArray(String[]::new);
760+
String[] backingIndices = dataStreamIndices.filter(filterPredicate).map(Index::getName).toArray(String[]::new);
749761
dataStreams.add(new ResolvedDataStream(dataStream.getName(), backingIndices, DataStream.TIMESTAMP_FIELD_NAME));
750762
}
751763
default -> throw new IllegalStateException("unknown index abstraction type: " + ia.getType());

0 commit comments

Comments
 (0)