Skip to content

Use storedFieldsSpec to load stored fields for highlighting #91841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 31, 2023

Conversation

romseygeek
Copy link
Contributor

Since #91269, fetch phase subprocessors can report any stored fields that they
need back to the top-level FetchPhase so that all stored fields can be loaded
up front. This commit switches the unified and plain highlighters to use this
functionality so that highlighting does not need to open stored field readers
twice.

@romseygeek romseygeek requested a review from nik9000 November 23, 2022 11:10
@romseygeek romseygeek self-assigned this Nov 23, 2022
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Nov 23, 2022
@elasticsearchmachine
Copy link
Collaborator

Hi @romseygeek, I've created a changelog YAML for you.

@rjernst rjernst added v8.8.0 and removed v8.7.0 labels Feb 8, 2023
@romseygeek romseygeek requested a review from cbuescher February 21, 2023 12:37
@cbuescher
Copy link
Member

@romseygeek just found this sitting in my queue of PRs assigned for review and wanted to say sorry this fell through the cracks. Seems stale at the moment, do you think it should get updated or is it better to close at this point?

@romseygeek
Copy link
Contributor Author

Still worth doing, I think. I'll update.

@romseygeek
Copy link
Contributor Author

@cbuescher this is ready for review again when you get time.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

I took a look and left two questions. Mostly I'm trying to understand through which part of this change unified and plain highlighters make use of the pre-loading. I think I found the spot but want to make sure I understand this right. Also not sure how difficult it would be to test that the optimization actually gets used.


Map<String, HighlightField> highlights = highlight(mapperService, doc, search);
assertHighlights(highlights, "field", "this is <em>some</em> text");
}
Copy link
Member

Choose a reason for hiding this comment

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

These tests already pass without the modifications in this PR. Do we have other ways to verify that the new optimization is actually used, e.g. check frequency of stored field readers access? Some asserting mocks etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's interesting, I think something has happened since I opened the PR that makes these pass. But we can definitely add checks to the highlight method that asserts we only load stored fields once per document. I will work on that.

hitContext.reader().document(hitContext.docId(), fieldVisitor);
List<Object> textsToHighlight = fieldVisitor.fields().get(fieldType.name());
return Objects.requireNonNullElse(textsToHighlight, Collections.emptyList());
List<Object> values = hitContext.loadedFields().get(fieldType.name());
Copy link
Member

Choose a reason for hiding this comment

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

To check my understanding: is this the part where we actually save having to open stored field readers more than once? Does the hitContext now always already contain the loaded fields?

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, exactly so

@romseygeek romseygeek requested a review from cbuescher March 30, 2023 15:05
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Thanks for the additional changes, LGTM. Nice solution for the test with wrapping the directory reader.

@romseygeek romseygeek merged commit d5e93a8 into elastic:main Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Relevance/Highlighting How a query matched a document Team:Search Meta label for search team v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants