Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/97460.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 97460
summary: Set new providers before building `FetchSubPhaseProcessors`
area: "Search"
type: bug
issues:
- 96284
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,33 @@ synthetic _source:
buckets_path:
ts: top_salary_hits[salary]
script: "params.ts < 8000"

---
runtime fields:
- do:
search:
index: test
body:
runtime_mappings:
runtime_field:
type: keyword
script:
lang: painless
source: "emit(params['_source'].toString())"
fields: [runtime_field]
size: 0
aggs:
page:
terms:
field: page
aggs:
top_hits:
top_hits: {}

- match: { hits.total.value: 3 }
- length: { aggregations.page.buckets: 2 }
- match: { aggregations.page.buckets.0.key: 1 }
- match: { aggregations.page.buckets.0.top_hits.hits.hits.0.fields.runtime_field: ["{page=1, text=the quick brown fox}"] }
- match: { aggregations.page.buckets.0.top_hits.hits.hits.1.fields.runtime_field: ["{page=1, text=jumped over the lazy dog}"] }
- match: { aggregations.page.buckets.1.key: 2 }
- match: { aggregations.page.buckets.1.top_hits.hits.hits.0.fields.runtime_field: ["{page=2, text=The vorpal blade went snicker-snack!}"] }
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private SearchHits buildSearchHits(SearchContext context, Profiler profiler) {
FetchContext fetchContext = new FetchContext(context);
SourceLoader sourceLoader = context.newSourceLoader();

PreloadedSourceProvider sourceProvider = new PreloadedSourceProvider();
PreloadedFieldLookupProvider fieldLookupProvider = new PreloadedFieldLookupProvider();
context.getSearchExecutionContext().setLookupProviders(sourceProvider, ctx -> fieldLookupProvider);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to add a unit test as well? I guess it really has to do with how top hits interacts with the fetch phase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unit tests for this will be tricky. We don't really have unit tests for any of the FetchPhase at the moment as the context structures that it uses are so heavy.


List<FetchSubPhaseProcessor> processors = getProcessors(context.shardTarget(), fetchContext, profiler);

StoredFieldsSpec storedFieldsSpec = StoredFieldsSpec.build(processors, FetchSubPhaseProcessor::storedFieldsSpec);
Expand All @@ -110,10 +114,6 @@ private SearchHits buildSearchHits(SearchContext context, Profiler profiler) {

NestedDocuments nestedDocuments = context.getSearchExecutionContext().getNestedDocuments();

PreloadedSourceProvider sourceProvider = new PreloadedSourceProvider();
PreloadedFieldLookupProvider fieldLookupProvider = new PreloadedFieldLookupProvider();
context.getSearchExecutionContext().setLookupProviders(sourceProvider, ctx -> fieldLookupProvider);

FetchPhaseDocsIterator docsIterator = new FetchPhaseDocsIterator() {

LeafReaderContext ctx;
Expand Down