Skip to content

Comments

Allow FetchSubPhaseProcessors to report their required stored fields …#1

Open
MitchLewis930 wants to merge 1 commit intopr_011_beforefrom
pr_011_after
Open

Allow FetchSubPhaseProcessors to report their required stored fields …#1
MitchLewis930 wants to merge 1 commit intopr_011_beforefrom
pr_011_after

Conversation

@MitchLewis930
Copy link

PR_011

…lastic#91269)

Loading of stored fields is currently handled directly in FetchPhase, with
some fairly complex logic examining various bits of the FetchContext to work
out what fields need to be loaded. This is further complicated by synthetic
source, which may have its own stored field requirements.

This commit tries to separate out these concerns a little by adding a new
StoredFieldsSpec record that holds information about which stored fields
need to be loaded. Each FetchSubPhaseProcessor can now report a
StoredFieldsSpec detailing what its requirements are, and these specs can
be merged together, along with requirements from a SourceLoader, to
determine up-front what fields should be loaded by the StoredFieldLoader.
The stored fields themselves are added into the SearchHit by a new
StoredFieldsPhase, which handles alias resolution and value post-
processing. The logic to determine when source should be loaded and
when not, based on the presence of script fields or stored fields, is
moved into FetchContext, which highlights some inconsistencies that
can be fixed in follow-up commits.
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 00:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors how FetchSubPhaseProcessors report their required stored fields and source dependencies, enabling more efficient field loading during search fetch operations.

Changes:

  • Introduced StoredFieldsSpec to consolidate stored field requirements across fetch sub-phases
  • Refactored SearchHit construction to use builder pattern for document/metadata fields
  • Added StoredFieldsPhase as a dedicated sub-phase for processing stored fields

Reviewed changes

Copilot reviewed 84 out of 84 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/src/main/java/org/elasticsearch/search/fetch/StoredFieldsSpec.java New record class defining stored field requirements
server/src/main/java/org/elasticsearch/search/fetch/FetchSubPhaseProcessor.java Added storedFieldsSpec() method to interface
server/src/main/java/org/elasticsearch/search/SearchHit.java Refactored constructor and field handling to use builder pattern
server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java Major refactor to consolidate stored field loading logic
server/src/main/java/org/elasticsearch/search/fetch/subphase/StoredFieldsPhase.java New dedicated phase for processing stored fields
Multiple test files Updated SearchHit instantiation to use simplified constructors
server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java Changed field type visibility from INSTANCE to FIELD_TYPE
server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java Changed field type visibility from INSTANCE to FIELD_TYPE
server/src/main/java/org/elasticsearch/index/mapper/LegacyTypeFieldMapper.java Changed field type visibility and added FIELD_TYPE constant

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Override
public boolean hasScriptFields() {
return scriptFields != null;
return scriptFields != null && scriptFields.fields().isEmpty() == false;
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The double negation pattern isEmpty() == false reduces readability. Use !scriptFields.fields().isEmpty() for clearer intent.

Suggested change
return scriptFields != null && scriptFields.fields().isEmpty() == false;
return scriptFields != null && !scriptFields.fields().isEmpty();

Copilot uses AI. Check for mistakes.
@Override
public boolean hasScriptFields() {
return scriptFields != null;
return scriptFields != null && scriptFields.fields().isEmpty() == false;
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The double negation pattern isEmpty() == false reduces readability. Use !scriptFields.fields().isEmpty() for clearer intent.

Suggested change
return scriptFields != null && scriptFields.fields().isEmpty() == false;
return scriptFields != null && !scriptFields.fields().isEmpty();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants