Skip to content

Support recording index resolution results on IndicesRequest#134783

Merged
elasticsearchmachine merged 12 commits intoelastic:mainfrom
n1v0lg:cps-index-expressions-model
Sep 19, 2025
Merged

Support recording index resolution results on IndicesRequest#134783
elasticsearchmachine merged 12 commits intoelastic:mainfrom
n1v0lg:cps-index-expressions-model

Conversation

@n1v0lg
Copy link
Copy Markdown
Contributor

@n1v0lg n1v0lg commented Sep 16, 2025

This PR introduces ResolvedIndexExpression and ResolvedIndexExpressions classes to capture context about index resolution (local results, exceptions, and unresolved remote expressions).

IndicesRequest.Replaceable now provides optional methods to set and retrieve resolved index expressions, enabling requests to carry richer resolution metadata alongside the existing indices(...) API.

Follow up work will plug this class into IndicesAndAliasesResolver.

This change is motivated by the requirements around error handling for cross-project search where error handling is performed post local index resolution in some cases.

Closes: ES-12688

@n1v0lg n1v0lg self-assigned this Sep 16, 2025
@n1v0lg n1v0lg added >non-issue :Security/Security Security issues without another label labels Sep 16, 2025
@n1v0lg n1v0lg changed the title Introduce ReplacedIndexExpressions model Introduce ResolvedIndexExpressions model Sep 18, 2025
@n1v0lg n1v0lg changed the title Introduce ResolvedIndexExpressions model Support for recording resolved index expressions in IndicesRequest Sep 18, 2025
@n1v0lg n1v0lg changed the title Support for recording resolved index expressions in IndicesRequest Support recording index resolution results on IndicesRequest Sep 18, 2025
@n1v0lg n1v0lg requested review from piergm and ywangd September 18, 2025 12:46
@n1v0lg n1v0lg marked this pull request as ready for review September 18, 2025 12:47
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Sep 18, 2025
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Member

@piergm piergm left a comment

Choose a reason for hiding this comment

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

Nice, this looks really good @n1v0lg!

Copy link
Copy Markdown
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


/**
* Record the results of index resolution. See {@link ResolvedIndexExpressions} for details.
* Note: this method does not replace {@link #indices(String...)}. {@link #indices(String...)} must still be called to update
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing to do for this PR. But could you please remind me what the long term vision is for this new method and the existing indices(String ...indices) method? Did we align that the new one could eventually replace the existing one and as an interim the default implementation could call something like indices(expressions.getAllLocalIndices())? Or maybe something else? My memory is hazy on this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My current plan for the interim is to maintain the methods separately and keep them independent. However, I'll still play around with the option of making a call like indices(expressions.getAllLocalIndices()) under the hood in the next PR where I plug this into the indices resolver.

Long term, the plan is to consolidate the two methods (replace indices(...)). That's a bigger refactor but seems very worthwhile since it'll move us closer to having structured info about index resources as opposed to opaque strings.

@n1v0lg n1v0lg added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Sep 19, 2025
@elasticsearchmachine elasticsearchmachine merged commit c9c4740 into elastic:main Sep 19, 2025
40 checks passed
@n1v0lg n1v0lg deleted the cps-index-expressions-model branch September 19, 2025 09:47
elasticsearchmachine pushed a commit that referenced this pull request Sep 24, 2025
This PR extends index resolution logic to capture the resolution mapping
from original to resolution result via `ResolvedIndexExpressions`
(introduced in #134783).
This lets consumers such as cross-project search that require full
resolution context to access it via the `IndicesRequest.Replaceable`
interface. 

To maximize code re-use, the PR updates the existing
`resolveIndexAbstractions` method to always return a
`ResolvedIndexExpressions` instance. The result is only recorded on the
request if a boolean flag is set to avoid unnecessary memory overhead in
contexts where storing the expressions is not necessary. In a (much
bigger) future refactor, we plan to move away from storing a raw indices
list and always use `ResolvedIndexExpressions` as the source of truth
for indices resources accessed by a request. Once that's complete, we
will move to _always_ storing the full resolution result.

This PR does not include the following, which we'll address in immediate
follow ups:

- Integrate the change into the wider implementation of cross-project search index expressions rewriting and error handling
- Store resolution for `_all` index expression handling
- Record full authorization exceptions on authorization failures
- Record resolution for remote expressions  (e.g., `p:logs -> p1:logs`) 

Relates: ES-12690
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 :Security/Security Security issues without another label Team:Security Meta label for security team v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants