|
65 | 65 | import java.util.SortedMap; |
66 | 66 | import java.util.TreeMap; |
67 | 67 | import java.util.function.Predicate; |
| 68 | +import java.util.stream.Collectors; |
68 | 69 | import java.util.stream.Stream; |
69 | 70 |
|
70 | 71 | import static org.elasticsearch.action.search.TransportSearchHelper.checkCCSVersionCompatibility; |
@@ -135,12 +136,12 @@ public boolean equals(Object o) { |
135 | 136 | if (this == o) return true; |
136 | 137 | if (o == null || getClass() != o.getClass()) return false; |
137 | 138 | Request request = (Request) o; |
138 | | - return Arrays.equals(names, request.names); |
| 139 | + return Arrays.equals(names, request.names) && indexModes.equals(request.indexModes); |
139 | 140 | } |
140 | 141 |
|
141 | 142 | @Override |
142 | 143 | public int hashCode() { |
143 | | - return Arrays.hashCode(names); |
| 144 | + return Objects.hash(Arrays.hashCode(names), indexModes); |
144 | 145 | } |
145 | 146 |
|
146 | 147 | @Override |
@@ -668,14 +669,39 @@ private static void mergeResults( |
668 | 669 | } |
669 | 670 | indices.add(index.copy(RemoteClusterAware.buildRemoteIndexName(clusterAlias, index.getName()))); |
670 | 671 | } |
671 | | - if (indexModes.isEmpty() == false && indexModes.contains(IndexMode.STANDARD) == false) { |
672 | | - continue; |
673 | | - } |
| 672 | + Set<String> indexNames = indices.stream().map(ResolvedIndexAbstraction::getName).collect(Collectors.toSet()); |
674 | 673 | for (ResolvedAlias alias : response.aliases) { |
675 | | - aliases.add(alias.copy(RemoteClusterAware.buildRemoteIndexName(clusterAlias, alias.getName()))); |
| 674 | + if (indexModes.isEmpty() == false) { |
| 675 | + // We need to filter out aliases that point to no indices after index mode filtering |
| 676 | + String[] filteredIndices = Arrays.stream(alias.getIndices()) |
| 677 | + .filter(idxName -> indexNames.contains(RemoteClusterAware.buildRemoteIndexName(clusterAlias, idxName))) |
| 678 | + .toArray(String[]::new); |
| 679 | + if (filteredIndices.length == 0) { |
| 680 | + continue; |
| 681 | + } |
| 682 | + alias = new ResolvedAlias(RemoteClusterAware.buildRemoteIndexName(clusterAlias, alias.getName()), filteredIndices); |
| 683 | + } else { |
| 684 | + alias = alias.copy(RemoteClusterAware.buildRemoteIndexName(clusterAlias, alias.getName())); |
| 685 | + } |
| 686 | + aliases.add(alias); |
676 | 687 | } |
677 | 688 | for (ResolvedDataStream dataStream : response.dataStreams) { |
678 | | - dataStreams.add(dataStream.copy(RemoteClusterAware.buildRemoteIndexName(clusterAlias, dataStream.getName()))); |
| 689 | + if (indexModes.isEmpty() == false) { |
| 690 | + String[] filteredBackingIndices = Arrays.stream(dataStream.getBackingIndices()) |
| 691 | + .filter(idxName -> indexNames.contains(RemoteClusterAware.buildRemoteIndexName(clusterAlias, idxName))) |
| 692 | + .toArray(String[]::new); |
| 693 | + if (filteredBackingIndices.length == 0) { |
| 694 | + continue; |
| 695 | + } |
| 696 | + dataStream = new ResolvedDataStream( |
| 697 | + RemoteClusterAware.buildRemoteIndexName(clusterAlias, dataStream.getName()), |
| 698 | + filteredBackingIndices, |
| 699 | + dataStream.getTimestampField() |
| 700 | + ); |
| 701 | + } else { |
| 702 | + dataStream = dataStream.copy(RemoteClusterAware.buildRemoteIndexName(clusterAlias, dataStream.getName())); |
| 703 | + } |
| 704 | + dataStreams.add(dataStream); |
679 | 705 | } |
680 | 706 | } |
681 | 707 | } |
|
0 commit comments