-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Refactored inner hits parsing and intoduced InnerHitBuilder #17291
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
Refactored inner hits parsing and intoduced InnerHitBuilder #17291
Conversation
this.innerHitsBuilders = new HashMap<>(); | ||
} | ||
|
||
public InnerHitsBuilder(Map<String, InnerHitBuilder> innerHitsBuilders) { |
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.
Maybe this can be private.
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.
Could you also check for null here?
@martijnvg this looks great, even though I didn't compare it completely to the way it was before the refactoring, I have the feeling this change simplifies a lot. Left a few minor comments, only thing that was causing some trouble with the tests on my side was the |
d9081b5
to
1b36a9e
Compare
@cbuescher Thanks for looking at this. I updated the PR based on your comment and fixed the |
With top-level I'm thinking that something like this will work; is there a better way?
|
@dimfeld Yes, that should work too. Also I'm thinking of also allowing the
This would be better, because it would be more efficient as only one The goal with replacing inner hits is that same things can be done with inline inner hits as top level inner hits. |
1b36a9e
to
d453f70
Compare
Sounds good. Thanks @martijnvg! |
@martijnvg thanks, changes look great and all works for me now, but maybe @colings86, @javanna or @s1monw want to take a second look at this before it gets in. |
return from; | ||
} | ||
|
||
public InnerHitBuilder setFrom(int from) { |
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.
I wonder if we should add validation check to these setter methods like we do in the query builders? So for this one check that the value is >= 0 and for setName() make sure the name passed in is not null.
@martijnvg I left a few minor comments but otherwise it LGTM |
sSource = source.toString(); | ||
} catch (Throwable e1) { | ||
// ignore | ||
queryShardContext.reset(); |
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.
I'm curious about why this reset (and the one in the finally block) are done. I saw this pattern in other places, just trying to figure out why this is done. In case its important, maybe worth a comment?
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.
This is the same logic in QueryShardContext#toQuery()
where we reset also twice. Personally I think a reset at the end is sufficient, but I kept the logic consistent with this method.
The reason we need to invoke reset at all here is because inner hits modifies the QueryShardContext#nestedScope
, so we need to reset at the end.
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.
Thanks for the explanation, I've been looking at resets in shard contexts recently and this helps my understanding.
@martijnvg I did another quick round, left a few minor suggestions and one question for my own understanding. |
d453f70
to
b4f3512
Compare
@cbuescher @colings86 I've updated the PR. |
@@ -202,7 +200,7 @@ public String getName() { | |||
} | |||
|
|||
public InnerHitBuilder setName(String name) { | |||
this.name = name; | |||
this.name = Objects.requireNonNull(name); |
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.
Is it valid for an inner hits builder to have no name, nestedPath and/or parentChildType set? If not then maybe we should remove the setters for these three fields and have them instead set in the constructor so that it is not possible to construct an InnerHitsBuilder that is not valid?
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.
Name is optional, if the name isn't specified it will default to either nestedPath or parentChildType.
I'll add a constructor that accepts either a nestedPath or a parentChildType.
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.
scratch that last line... the reason I didn't go with constructor arguments was because: the nested path / parent child type is known while parsing the xcontent for top level inner hits. After we have removed top level inner hits we can make this change easily.
(also name is just a label for reading back the inner hits in the response, lets say you have two nested queries for the same path that have inner hits enabled)
238e86c
to
7ef852b
Compare
Thanks, looked at the last changes, LGTM. |
7ef852b
to
b25d555
Compare
Both top level and inline inner hits are now covered by InnerHitBuilder. Although there are differences between top level and inline inner hits, they now make use of the same builder logic. The parsing of top level inner hits slightly changed to be more readable. Before the nested path or parent/child type had to be specified as encapsuting json object, now these settings are simple fields. Before this was required to allow streaming parsing of inner hits without missing contextual information. Once some issues are fixed with inline inner hits (around multi level hierachy of inner hits), top level inner hits will be deprecated and removed in the next major version.
b25d555
to
7e2696c
Compare
Both top level and inline inner hits are now covered by InnerHitBuilder.
Although there are differences between top level and inline inner hits,
they now make use of the same builder logic.
The parsing of top level inner hits slightly changed to be more readable.
Before the nested path or parent/child type had to be specified as encapsuting
json object, now these settings are simple fields. Before this was required
to allow streaming parsing of inner hits without missing contextual information.
Once some issues are fixed with inline inner hits (around multi level hierachy of inner hits),
top level inner hits will be deprecated and removed in the next major version.
Also I think some
SearchParseElement
implementations can be removed, but I haven't done that yet.