Skip to content

Fix exclusion handling for CPS _search#144145

Merged
elasticsearchmachine merged 6 commits intoelastic:mainfrom
n1v0lg:test-exclusions
Mar 13, 2026
Merged

Fix exclusion handling for CPS _search#144145
elasticsearchmachine merged 6 commits intoelastic:mainfrom
n1v0lg:test-exclusions

Conversation

@n1v0lg
Copy link
Contributor

@n1v0lg n1v0lg commented Mar 12, 2026

Cross-project search with minimize_roundtrips=true was dropping index exclusion patterns (e.g. linked_project:-shared-index-1) when dispatching to linked projects. The MRT=true path used _resolve/index to determine which projects participate, then reconstructed OriginalIndices from the resolve response — but exclusion expressions don't resolve to concrete indices, so they were silently lost.

Instead, we can use the resolve response only to determine project participation, then pass the original index expressions (including exclusions) to participating projects.

Test coverage in linked PR.

@n1v0lg n1v0lg self-assigned this Mar 12, 2026
@n1v0lg n1v0lg added >non-issue :Security/Security Security issues without another label labels Mar 12, 2026
@elasticsearchmachine elasticsearchmachine added v9.4.0 serverless-linked Added by automation, don't add manually labels Mar 12, 2026
@n1v0lg n1v0lg marked this pull request as ready for review March 13, 2026 07:18
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Mar 13, 2026
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@n1v0lg n1v0lg added :Search Foundations/Search Catch all for Search Foundations and removed Team:Security Meta label for security team labels Mar 13, 2026
@elasticsearchmachine elasticsearchmachine added Team:Security Meta label for security team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch labels Mar 13, 2026
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@n1v0lg
Copy link
Contributor Author

n1v0lg commented Mar 13, 2026

Compile error after merge 👀

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for fixing it.

I don't quite get why search resolve indices per project separately. But that's not related to the change here.

Comment on lines +1239 to +1249
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()));
}
}
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.

@n1v0lg n1v0lg added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 13, 2026
@elasticsearchmachine elasticsearchmachine merged commit b29b75b into elastic:main Mar 13, 2026
43 checks passed
@n1v0lg n1v0lg deleted the test-exclusions branch March 13, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >non-issue :Search Foundations/Search Catch all for Search Foundations :Security/Security Security issues without another label serverless-linked Added by automation, don't add manually Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch Team:Security Meta label for security team v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants