Skip to content

Commit d8bba0c

Browse files
Do not track project in metadata if it doesn't participate in search
1 parent 30a65be commit d8bba0c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,21 @@ static void collectSearchShards(
994994
@Override
995995
void innerOnResponse(SearchShardsResponse searchShardsResponse) {
996996
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SEARCH_COORDINATION);
997-
ccsClusterInfoUpdate(searchShardsResponse, clusters, clusterAlias, timeProvider);
997+
/*
998+
* This particular linked project returned empty shards and that's because none of the requested
999+
* indices are on it. So we need to prevent it from appearing in the metadata. In case the very
1000+
* same indices don't exist on the origin too, we use `CrossProjectIndexResolutionValidator#validate()`
1001+
* to throw an error downstream.
1002+
*
1003+
* TODO: Handle the `total` count that tracks total projects since it populates that info
1004+
* within Cluster#ctor().
1005+
*/
1006+
boolean canPurge = resolvesCrossProject && searchShardsResponse.getGroups().isEmpty();
1007+
if (canPurge) {
1008+
clusters.swapCluster(clusterAlias, (ignored1, ignored2) -> null);
1009+
} else {
1010+
ccsClusterInfoUpdate(searchShardsResponse, clusters, clusterAlias, timeProvider);
1011+
}
9981012
searchShardsResponses.put(clusterAlias, searchShardsResponse);
9991013
}
10001014

0 commit comments

Comments
 (0)