Skip to content

Conversation

@javanna
Copy link
Member

@javanna javanna commented May 2, 2017

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.

The idea is that with this change we can go back to #22533, add fromXContent to SearchResponse, where we will be able to return a search response created by passing in an instance of SearchResponseSections rather than InternalSearchResponse. SearchResponseSections holds Aggregations rather than InternalAggregations, which allows the high level REST client not to use InternalAggregation instances for aggs parsing, rather ParsedAggregation

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.
Copy link
Member

@tlrx tlrx left a 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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Ok

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

@javanna javanna force-pushed the enhancement/parsed_aggs_search_response branch from a48dbb7 to 3749a8c Compare May 3, 2017 08:24
@javanna
Copy link
Member Author

javanna commented May 3, 2017

can you have another look @tlrx ?

return builder;
}

//TODO add tests for this method
Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

++

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@javanna javanna merged commit fbd793d into elastic:feature/client_aggs_parsing May 3, 2017
javanna added a commit to javanna/elasticsearch that referenced this pull request May 23, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants