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
Use SearchRequest copy constructor in ExpandSearchPhase #36772
Use SearchRequest copy constructor in ExpandSearchPhase #36772
Conversation
Pinging @elastic/es-search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one small comment around a maybe redundant line that could be removed, but other than that LGTM
@@ -91,7 +91,8 @@ public void run() throws IOException { | |||
SearchSourceBuilder sourceBuilder = buildExpandSearchSourceBuilder(innerHitBuilder, innerCollapseBuilder) | |||
.query(groupQuery) | |||
.postFilter(searchRequest.source().postFilter()); | |||
SearchRequest groupRequest = buildExpandSearchRequest(searchRequest, sourceBuilder); | |||
SearchRequest groupRequest = new SearchRequest(searchRequest); | |||
groupRequest.source(sourceBuilder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java#L112 I think this extra line can be removed, or am I missing sth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we remove it the copy constructor would not be a correct copy constructor, meaning it would never copy the source? I think it's fine that it copies it and we override it when needed? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I wasn't suggesting removing it in the copy constructor. I was missing the part that sourceBuilder
here seems not be part of searchRequest
yet when calling the copy constructor. All good now, thanks for the clarification.
Using the copy constructor introduced with #36641 guarantees that whenever new fields are added to
SearchRequest
they are properly propagated to its copies. Copies created inExpandSearchPhase
were missing a couple of recently added fields.