Skip to content

CPS: Copy existing resolved index expressions when constructing a new SearchRequest from an existing one#139596

Merged
pawankartik-elastic merged 5 commits intoelastic:mainfrom
pawankartik-elastic:pkar/cp-resolved-exprs-for-rewritten
Dec 18, 2025
Merged

CPS: Copy existing resolved index expressions when constructing a new SearchRequest from an existing one#139596
pawankartik-elastic merged 5 commits intoelastic:mainfrom
pawankartik-elastic:pkar/cp-resolved-exprs-for-rewritten

Conversation

@pawankartik-elastic
Copy link
Contributor

@pawankartik-elastic pawankartik-elastic commented Dec 16, 2025

When a search request hits TransportSearchAction and goes through Rewriteable#rewriteAndFetch(), we get back a newly rewritten "search request" via a listener that we pass. Underneath, the rewritten search request is constructed from the original one. Because this happens after the Security Action Filter runs, the new search request's index expressions are not resolved and stay null, and neither are the previously resolved index expressions copied onto the new request correctly. This PR fixes it by copying over the older computed info about the resolved expressions.

The linked Serverless PR contains a test case that triggers a rewrite. I've explicitly checked that the rewrite occurs within TSA before the search is executed and that without this fix, the rewritten request's resolved expressions are null. Without this fix, the said test fails.

@elasticsearchmachine elasticsearchmachine added v9.3.0 serverless-linked Added by automation, don't add manually labels Dec 16, 2025
@pawankartik-elastic pawankartik-elastic changed the title Copy existing resolved index expressions when constructing a new SearchRequest from an existing one CPS: Copy existing resolved index expressions when constructing a new SearchRequest from an existing one Dec 16, 2025
@pawankartik-elastic pawankartik-elastic added >bug Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch :Search Foundations/CCS labels Dec 16, 2025
@pawankartik-elastic pawankartik-elastic marked this pull request as ready for review December 16, 2025 17:09
@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.

this.waitForCheckpointsTimeout = searchRequest.waitForCheckpointsTimeout;
this.forceSyntheticSource = searchRequest.forceSyntheticSource;
this.projectRouting = searchRequest.projectRouting;
this.resolvedIndexExpressions = searchRequest.resolvedIndexExpressions;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a quick unit test for this ctor just to ensure when we refactor it next time this aspect is not lost.

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.

LGTM

@pawankartik-elastic pawankartik-elastic merged commit f030f3d into elastic:main Dec 18, 2025
35 checks passed
@pawankartik-elastic pawankartik-elastic deleted the pkar/cp-resolved-exprs-for-rewritten branch December 18, 2025 16:29
szybia added a commit to szybia/elasticsearch that referenced this pull request Dec 19, 2025
* upstream/main: (253 commits)
  Adds ST_SIMPLIFY geo spatial function (elastic#136309)
  Take control of max clause count verification in Lucene searcher (elastic#139752)
  [ML] Unmute Inference Test (elastic#139765)
  Parameterize the vector operation benchmark tests (elastic#139735)
  Fix node reduction pushdown tests for release tests (elastic#139548)
  Fix flakiness in TSDataGenerationHelper (elastic#139759)
  CPS: Copy existing resolved index expressions when constructing a new `SearchRequest` from an existing one (elastic#139596)
  Add release notes for v9.1.9 release (elastic#139674)
  Add lucene query for wildcards on high cardinality keyword fields. (elastic#139746)
  Suppress Tika entitlement warnings from AWT (elastic#139711)
  Check field storage when synthetic source is enabled, in tests (elastic#139715)
  Refactor VectorSimilarityType to know about its corresponding Function (elastic#139678)
  Merge fixes from patch branch back into main (elastic#139721)
  Define native bulk operations for vector square distance (elastic#139198)
  Use LongUpDownCounter for Linked Project Error Metrics (elastic#139657)
  ESQL: Add javadoc that explains version-aware planning (elastic#139706)
  Add helper to pick node for reindex relocation (elastic#139081)
  Fix auth serialization randomized version test (elastic#139182)
  ES|QL - Add parsing, preanalysis and analysis timing information to profile (elastic#139540)
  Mute org.elasticsearch.persistent.ClusterPersistentTasksCustomMetadataTests testMinVersionSerialization elastic#139741
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :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.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants