-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce SearchResponseSections base class #24442
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
Introduce SearchResponseSections base class #24442
Conversation
SearchResponseSections is the common part extracted from InternalSearchResponse that can be shared between high level REST and elasticsearch. The only bits left out are around serialization which is not supported. This way it can accept Aggregations as a constructor argument, without requiring InternalAggregations, as the high level REST client uses its own objects for aggs parsing rather than internal ones. This change also makes Aggregations implement ToXContent, and Aggregation extend ToXContent. Especially the latter is suboptimal but the best solution that allows to share as much code as possible between core and the client, that doesn't require messing with generics and making the api complicated. Also it doesn't have downsides as all of the current implementations of Aggregation do implement ToXContent already.
tlrx
left 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 looks nice, I left some comments/questions
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 documentation. We could also change SearchResponseSections so that it does not implement Writeable here and later cast SearchResponse's internalResponse to InternalSearchResponse in SearchResponse.writeTo(StreamOutput) ? I think it's acceptable since SearchResponse.readFrom() already expects an InternalSearchResponse.
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.
the subtle difference there is that if you try to serialize the parsed search response by calling writeTo you get back a class cast exception rather than an unsupported operation exception. I think it's ok to create internal search response in readFrom as we can control that. I think I will try to have the inner class not implement Writeable, yet leave the writeTo method that throws exception there.
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.
What about BaseSearchResponse? I find this sections suffix confusing, but maybe it's just me.
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.
BaseSearchResponse makes me think that it has to do with its ancestor. I went for sections because it holds the different sections of the search response, in the same spirit as Aggregations.
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.
Ok
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.
aggregations is not initialized with emptyList() anymore, I think this might cause an issue here
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.
yea I forgot to push a commit. I had already fixed this, good catch.
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.
Writeable is not necessary here
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 left it as SearchREsponseSections doesn't implement Writeable anymore
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.
Sure, thanks. I prefer this, SearchResponseSections not declaring that it implements Writeable but still providing a writeTo method.
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.
Do you think we could add some @Nullable here?
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, I tried to limit the unrelated changes here as it will go in our branch. Does the need for Nullable come from my changes?
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.
Does the need for Nullable come from my changes?
No, just thinking that it would be useful here.
a48dbb7 to
3749a8c
Compare
|
can you have another look @tlrx ? |
| return builder; | ||
| } | ||
|
|
||
| //TODO add tests for this method |
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.
would you mind if I add tests as a follow-up so we can get this in rather quickly?
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.
++
tlrx
left 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.
LGTM, thanks
SearchResponseSections is the common part extracted from InternalSearchResponse that can be shared between high level REST and elasticsearch. The only bits left out are around serialization which is not supported. This way it can accept Aggregations as a constructor argument, without requiring InternalAggregations, as the high level REST client uses its own objects for aggs parsing rather than internal ones. This change also makes Aggregations implement ToXContent, and Aggregation extend ToXContent. Especially the latter is suboptimal but the best solution that allows to share as much code as possible between core and the client, that doesn't require messing with generics and making the api complicated. Also it doesn't have downsides as all of the current implementations of Aggregation do implement ToXContent already.
SearchResponseSectionsis the common part extracted fromInternalSearchResponsethat can be shared between high level REST and elasticsearch. The only bits left out are around serialization which is not supported. This way it can acceptAggregationsas a constructor argument, without requiringInternalAggregations, as the high level REST client uses its own objects for aggs parsing rather than internal ones.This change also makes Aggregations implement ToXContent, and Aggregation extend ToXContent. Especially the latter is suboptimal but the best solution that allows to share as much code as possible between core and the client, that doesn't require messing with generics and making the api complicated. Also it doesn't have downsides as all of the current implementations of Aggregation do implement ToXContent already.
The idea is that with this change we can go back to #22533, add
fromXContenttoSearchResponse, where we will be able to return a search response created by passing in an instance ofSearchResponseSectionsrather thanInternalSearchResponse.SearchResponseSectionsholdsAggregationsrather thanInternalAggregations, which allows the high level REST client not to useInternalAggregationinstances for aggs parsing, ratherParsedAggregation