-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move top-level pipeline aggs out of QuerySearchResult (#40319)
As part of #40177 we have added top-level pipeline aggs to `InternalAggregations`. Given that `QuerySearchResult` holds an `InternalAggregations` instance, there is no need to keep on setting top-level pipeline aggs separately. Top-level pipeline aggs can then always be transported through `InternalAggregations`. Such change is made in a backwards compatible manner.
- Loading branch information
Showing
7 changed files
with
145 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
102 changes: 102 additions & 0 deletions
102
server/src/test/java/org/elasticsearch/search/query/QuerySearchResultTests.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.search.query; | ||
|
||
import org.apache.lucene.search.ScoreDoc; | ||
import org.apache.lucene.search.TopDocs; | ||
import org.apache.lucene.search.TotalHits; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.OriginalIndices; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.SearchModule; | ||
import org.elasticsearch.search.SearchShardTarget; | ||
import org.elasticsearch.search.aggregations.Aggregations; | ||
import org.elasticsearch.search.aggregations.InternalAggregations; | ||
import org.elasticsearch.search.aggregations.InternalAggregationsTests; | ||
import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator; | ||
import org.elasticsearch.search.suggest.SuggestTests; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
public class QuerySearchResultTests extends ESTestCase { | ||
|
||
private final NamedWriteableRegistry namedWriteableRegistry; | ||
|
||
public QuerySearchResultTests() { | ||
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); | ||
this.namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables()); | ||
} | ||
|
||
private static QuerySearchResult createTestInstance() throws Exception { | ||
ShardId shardId = new ShardId("index", "uuid", randomInt()); | ||
QuerySearchResult result = new QuerySearchResult(randomLong(), new SearchShardTarget("node", shardId, null, OriginalIndices.NONE)); | ||
if (randomBoolean()) { | ||
result.terminatedEarly(randomBoolean()); | ||
} | ||
TopDocs topDocs = new TopDocs(new TotalHits(randomLongBetween(0, Long.MAX_VALUE), TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]); | ||
result.topDocs(new TopDocsAndMaxScore(topDocs, randomBoolean() ? Float.NaN : randomFloat()), new DocValueFormat[0]); | ||
result.size(randomInt()); | ||
result.from(randomInt()); | ||
if (randomBoolean()) { | ||
result.suggest(SuggestTests.createTestItem()); | ||
} | ||
if (randomBoolean()) { | ||
result.aggregations(InternalAggregationsTests.createTestInstance()); | ||
} | ||
return result; | ||
} | ||
|
||
public void testSerialization() throws Exception { | ||
QuerySearchResult querySearchResult = createTestInstance(); | ||
Version version = VersionUtils.randomVersion(random()); | ||
QuerySearchResult deserialized = copyStreamable(querySearchResult, namedWriteableRegistry, QuerySearchResult::new, version); | ||
assertEquals(querySearchResult.getRequestId(), deserialized.getRequestId()); | ||
assertNull(deserialized.getSearchShardTarget()); | ||
assertEquals(querySearchResult.topDocs().maxScore, deserialized.topDocs().maxScore, 0f); | ||
assertEquals(querySearchResult.topDocs().topDocs.totalHits, deserialized.topDocs().topDocs.totalHits); | ||
assertEquals(querySearchResult.from(), deserialized.from()); | ||
assertEquals(querySearchResult.size(), deserialized.size()); | ||
assertEquals(querySearchResult.hasAggs(), deserialized.hasAggs()); | ||
if (deserialized.hasAggs()) { | ||
Aggregations aggs = querySearchResult.consumeAggs(); | ||
Aggregations deserializedAggs = deserialized.consumeAggs(); | ||
assertEquals(aggs.asList(), deserializedAggs.asList()); | ||
List<SiblingPipelineAggregator> pipelineAggs = ((InternalAggregations) aggs).getTopLevelPipelineAggregators(); | ||
List<SiblingPipelineAggregator> deserializedPipelineAggs = | ||
((InternalAggregations) deserializedAggs).getTopLevelPipelineAggregators(); | ||
assertEquals(pipelineAggs.size(), deserializedPipelineAggs.size()); | ||
for (int i = 0; i < pipelineAggs.size(); i++) { | ||
SiblingPipelineAggregator pipelineAgg = pipelineAggs.get(i); | ||
SiblingPipelineAggregator deserializedPipelineAgg = deserializedPipelineAggs.get(i); | ||
assertArrayEquals(pipelineAgg.bucketsPaths(), deserializedPipelineAgg.bucketsPaths()); | ||
assertEquals(pipelineAgg.name(), deserializedPipelineAgg.name()); | ||
} | ||
} | ||
assertEquals(querySearchResult.terminatedEarly(), deserialized.terminatedEarly()); | ||
} | ||
} |