Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions server/src/main/java/org/elasticsearch/action/ResolvedIndices.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,44 +240,6 @@ public static ResolvedIndices resolveWithPIT(
);
}

/**
* Create a new {@link ResolvedIndices} instance from a Map of Projects to {@link ResolvedIndexExpressions}. This is intended to be
* used for Cross-Project Search (CPS).
*
* @param localIndices this value is set as-is in the resulting ResolvedIndices.
* @param localIndexMetadata this value is set as-is in the resulting ResolvedIndices.
* @param remoteExpressions the map of project names to {@link ResolvedIndexExpressions}. This map is used to create the
* {@link ResolvedIndices#getRemoteClusterIndices()} for the resulting ResolvedIndices. Each project keyed
* in the map is guaranteed to have at least one index for the index expression provided by the user.
* The resulting {@link ResolvedIndices#getRemoteClusterIndices()} will map to the original index expression
* provided by the user. For example, if the user requested "logs" and "project-1" resolved that to "logs-1",
* then the result will map "project-1" to "logs". We rely on the remote search request to expand "logs" back
* to "logs-1".
* @param indicesOptions this value is set as-is in the resulting ResolvedIndices.
*/
public static ResolvedIndices resolveWithIndexExpressions(
OriginalIndices localIndices,
Map<Index, IndexMetadata> localIndexMetadata,
Map<String, ResolvedIndexExpressions> remoteExpressions,
IndicesOptions indicesOptions
) {
Map<String, OriginalIndices> remoteIndices = remoteExpressions.entrySet().stream().collect(HashMap::new, (map, entry) -> {
var indices = entry.getValue().expressions().stream().filter(expression -> {
var resolvedExpressions = expression.localExpressions();
var successfulResolution = resolvedExpressions
.localIndexResolutionResult() == ResolvedIndexExpression.LocalIndexResolutionResult.SUCCESS;
// if the expression is a wildcard, it will be successful even if there are no indices, so filter for no indices
var hasResolvedIndices = resolvedExpressions.indices().isEmpty() == false;
return successfulResolution && hasResolvedIndices;
}).map(ResolvedIndexExpression::original).toArray(String[]::new);
if (indices.length > 0) {
map.put(entry.getKey(), new OriginalIndices(indices, indicesOptions));
}
}, Map::putAll);

return new ResolvedIndices(remoteIndices, localIndices, localIndexMetadata);
}

private static Map<Index, IndexMetadata> resolveLocalIndexMetadata(
Index[] concreteLocalIndices,
ProjectMetadata projectMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,17 @@ private static void mergeResolvedIndices(
if (ex != null) {
listener.onFailure(ex);
} else {
ResolvedIndices resolvedIndicesForCps = ResolvedIndices.resolveWithIndexExpressions(
originalResolvedIndices.getLocalIndices(),
originalResolvedIndices.getConcreteLocalIndicesMetadata(),
resolvedExpressions,
resolutionIdxOpts
);

HashMap<String, OriginalIndices> participatingLinkedProjects = new HashMap<>(resolvedIndicesForCps.getRemoteClusterIndices());
HashMap<String, OriginalIndices> participatingLinkedProjects = new HashMap<>();
for (var entry : resolvedExpressions.entrySet()) {
boolean hasAnyResolvedIndices = entry.getValue().expressions().stream().anyMatch(expression -> {
var localExpressions = expression.localExpressions();
return localExpressions.localIndexResolutionResult() == ResolvedIndexExpression.LocalIndexResolutionResult.SUCCESS
&& localExpressions.indices().isEmpty() == false;
});
if (hasAnyResolvedIndices) {
participatingLinkedProjects.put(entry.getKey(), originalResolvedIndices.getRemoteClusterIndices().get(entry.getKey()));
}
}
Comment on lines +1239 to +1249
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It's possible to build participatingLinkedProjects with a stream. But I am ok with this as well.

Copy link
Contributor Author

@n1v0lg n1v0lg Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets a little awkward because it's explicitly a HashMap, i.e. needs to be mutable so the toMap step gets convoluted. I'll keep the for-loop but with the intention of revisiting this code -- I think we can do some clean up here.


/*
* Because we're considering unresponsive projects as participating and instantiating a `Clusters` object based
Expand All @@ -1261,7 +1264,7 @@ private static void mergeResolvedIndices(
new ResolvedIndices(
participatingLinkedProjects,
includeOriginProjectInMetadata ? originalResolvedIndices.getLocalIndices() : null,
resolvedIndicesForCps.getConcreteLocalIndicesMetadata()
originalResolvedIndices.getConcreteLocalIndicesMetadata()
)
);
}
Expand Down

This file was deleted.

Loading