-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move top-level pipeline aggs out of QuerySearchResult #40319
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
javanna
merged 9 commits into
elastic:master
from
javanna:enhancement/query_search_result_remove_pipeline_aggs
Mar 28, 2019
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18365a9
Move top-level pipeline aggs out of QuerySearchResult
javanna fa6bb04
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna 64fb309
address review comments
javanna 56cd793
add tests
javanna 11fe5da
add tests
javanna 5852f0d
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna 4d4fa33
update versions and disable bwc tests
javanna bef9315
remove redundant test, will be added to 7.x only
javanna b4ec1bd
Merge branch 'master' into enhancement/query_search_result_remove_pip…
javanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,15 @@ | |
|
|
||
| import org.apache.lucene.search.FieldDoc; | ||
| import org.apache.lucene.search.TotalHits; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore; | ||
| import org.elasticsearch.search.DocValueFormat; | ||
| import org.elasticsearch.search.SearchPhaseResult; | ||
| import org.elasticsearch.search.SearchShardTarget; | ||
| import org.elasticsearch.search.aggregations.Aggregations; | ||
| import org.elasticsearch.search.aggregations.InternalAggregation; | ||
| import org.elasticsearch.search.aggregations.InternalAggregations; | ||
| import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; | ||
| import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator; | ||
|
|
@@ -37,7 +39,6 @@ | |
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.elasticsearch.common.lucene.Lucene.readTopDocs; | ||
|
|
@@ -54,7 +55,6 @@ public final class QuerySearchResult extends SearchPhaseResult { | |
| private DocValueFormat[] sortValueFormats; | ||
| private InternalAggregations aggregations; | ||
| private boolean hasAggs; | ||
| private List<SiblingPipelineAggregator> pipelineAggregators = Collections.emptyList(); | ||
| private Suggest suggest; | ||
| private boolean searchTimedOut; | ||
| private Boolean terminatedEarly = null; | ||
|
|
@@ -198,14 +198,6 @@ public void profileResults(ProfileShardResult shardResults) { | |
| hasProfileResults = shardResults != null; | ||
| } | ||
|
|
||
| public List<SiblingPipelineAggregator> pipelineAggregators() { | ||
| return pipelineAggregators; | ||
| } | ||
|
|
||
| public void pipelineAggregators(List<SiblingPipelineAggregator> pipelineAggregators) { | ||
| this.pipelineAggregators = Objects.requireNonNull(pipelineAggregators); | ||
| } | ||
|
|
||
| public Suggest suggest() { | ||
| return suggest; | ||
| } | ||
|
|
@@ -294,8 +286,19 @@ public void readFromWithId(long id, StreamInput in) throws IOException { | |
| if (hasAggs = in.readBoolean()) { | ||
| aggregations = InternalAggregations.readAggregations(in); | ||
| } | ||
| pipelineAggregators = in.readNamedWriteableList(PipelineAggregator.class).stream().map(a -> (SiblingPipelineAggregator) a) | ||
| .collect(Collectors.toList()); | ||
| //TODO update version after backport | ||
| if (in.getVersion().before(Version.V_8_0_0)) { | ||
| List<SiblingPipelineAggregator> pipelineAggregators = in.readNamedWriteableList(PipelineAggregator.class).stream() | ||
| .map(a -> (SiblingPipelineAggregator) a).collect(Collectors.toList()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we skip the rewriting if siblings are empty ? |
||
| if (hasAggs && pipelineAggregators.isEmpty() == false) { | ||
| List<InternalAggregation> internalAggs = aggregations.asList().stream() | ||
| .map(agg -> (InternalAggregation) agg).collect(Collectors.toList()); | ||
| //Earlier versions serialize sibling pipeline aggs separately as they used to be set to QuerySearchResult directly, while | ||
| //later versions include them in InternalAggregations. Note that despite serializing sibling pipeline aggs as part of | ||
| //InternalAggregations is supported since 6.7.0, the shards set sibling pipeline aggs to InternalAggregations only from 7.1. | ||
| this.aggregations = new InternalAggregations(internalAggs, pipelineAggregators); | ||
| } | ||
| } | ||
| if (in.readBoolean()) { | ||
| suggest = new Suggest(in); | ||
| } | ||
|
|
@@ -332,7 +335,16 @@ public void writeToNoId(StreamOutput out) throws IOException { | |
| out.writeBoolean(true); | ||
| aggregations.writeTo(out); | ||
| } | ||
| out.writeNamedWriteableList(pipelineAggregators); | ||
| if (out.getVersion().before(Version.V_8_0_0)) { | ||
| //Earlier versions expect sibling pipeline aggs separately as they used to be set to QuerySearchResult directly, | ||
| //while later versions expect them in InternalAggregations. Note that despite serializing sibling pipeline aggs as part of | ||
| //InternalAggregations is supported since 6.7.0, the shards set sibling pipeline aggs to InternalAggregations only from 7.1 on. | ||
| if (aggregations == null) { | ||
| out.writeNamedWriteableList(Collections.emptyList()); | ||
| } else { | ||
| out.writeNamedWriteableList(aggregations.getTopLevelPipelineAggregators()); | ||
| } | ||
| } | ||
| if (suggest == null) { | ||
| out.writeBoolean(false); | ||
| } else { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think you need to check if
hasAggsis true here becauseaggregationscan be null.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.
yes good catch