Skip to content

Conversation

@pawankartik-elastic
Copy link
Contributor

@pawankartik-elastic pawankartik-elastic commented Nov 4, 2025

project_routing can either be a query parameter or be included in the request's body:

{
  "project_routing": "_alias:_origin",
  "sort": [
    { "date": { "order": "asc" } }
  ],
  "aggs": {
    "sale_date": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "1d"
      }
    }
  }
}

At no time should it be set at both places. This PR adds support for it and the subsequent checks.

  • Check if project_routing needs to be serialised/de-serialised.

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Nov 4, 2025
searchRequest.indicesOptions(indicesOptions);

validateSearchRequest(request, searchRequest);
validateSearchRequest(request, searchRequest, crossProjectEnabled);
Copy link
Contributor Author

@pawankartik-elastic pawankartik-elastic Nov 4, 2025

Choose a reason for hiding this comment

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

Other endpoints use SearchRequest, too. Should we prohibit them from using project_routing? At the moment, we only look at whether CPS is enabled or not, not if an endpoint supports CPS, so I'm wondering about those endpoints, such as Fleet's.

The query parameter is consumed in the respective Rest*Action-s, so that's fine. It's the presence of the routing parameter in the request's body that I'm thinking about.

Copy link
Member

Choose a reason for hiding this comment

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

Also search with PIT id should not read/consume project_routing but that's with the PIT changes to make sure it doesn't happen, so we should be good here

@pawankartik-elastic pawankartik-elastic added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch :Search Foundations/CCS >enhancement labels Nov 5, 2025
@pawankartik-elastic pawankartik-elastic marked this pull request as ready for review November 5, 2025 11:24
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @pawankartik-elastic, I've created a changelog YAML for you.

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

Changes looks good, left some minor, non-blocking questions I'd like your opinion on.

} else if (token.isValue()) {
if (FROM_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
if (PROJECT_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
projectRouting(parser.text());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment here for future maintainers that we are going to validate the project routing and maybe throw in validateSearchRequest if it's not a CPS context, otherwise would be strange to see it parsed ok/without errors and an error thrown afterwards IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, making the change in the next push.

Copy link
Contributor

@quux00 quux00 left a comment

Choose a reason for hiding this comment

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

Good progress!

Some questions and suggestions left.

ElasticsearchException validationEx = CrossProjectIndexResolutionValidator.validate(
originalIdxOpts,
null,
projectRouting,
Copy link
Contributor

Choose a reason for hiding this comment

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

@piergm - Can you help me understand why we want projectRouting to be passed into CrossProjectIndexResolutionValidator.validate? This method appears to be called only from Transport Actions, not the SecurityActionFilter and its sole use in the validate method is to help determine whether the index expression is qualified. Why would projectRouting being set mean that we have a qualified expression?

That doesn't seem right to me, but maybe I'm missing a use case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would projectRouting being set mean that we have a qualified expression?

Consider these indices: foo,bar. Normally, they'd be considered unqualified, and in the flat world, we're fine with wherever they exist. However, if project_routing is specified, say, _alias:_origin, it means we're interested in the results from the origin. So you need to read both the indices and the routing info together.

Here's how it works, using Search as an example: the SAF uses project routing to resolve the projects that are in scope. Say, the routing is _alias:p1. All non-p1 projects are filtered out via CrossProjectRoutingResolver#resolve(), and index expressions are expanded/rewritten using these "resolved" projects. When the coordinator fans out the request, it only does it to those projects that are in scope wrt the routing info, i.e. p1 in this case. So the indices effectively belong to p1, and reading both the unqualified index expressions and the routing together, they can be treated as qualified.

phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Nov 6, 2025
BASE=7a23516cce48dcd78aed0075a398b604531f1e81
HEAD=121d0f632c058df1d808a022c58eaf2303e8c246
Branch=main
Copy link
Contributor

@quux00 quux00 left a comment

Choose a reason for hiding this comment

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

Good progress. Two suggested changes.

phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Nov 7, 2025
BASE=e916243b86560e938fa1d2c5f2607c28d7a49dd3
HEAD=0c7ee5d1fa023820437f540cf94528fe48d2488b
Branch=main
Copy link
Contributor

@quux00 quux00 left a comment

Choose a reason for hiding this comment

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

Once the new TransportVersion and serialized projectRouting is done, LGTM, so approving now.

@pawankartik-elastic pawankartik-elastic merged commit 6aa1eb4 into elastic:main Nov 13, 2025
34 checks passed
@pawankartik-elastic pawankartik-elastic deleted the pkar/search-project-routing branch November 13, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search Foundations/CCS serverless-linked Added by automation, don't add manually Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants