diff --git a/build.gradle b/build.gradle index 4484d3fc14c..08e9c946eaf 100644 --- a/build.gradle +++ b/build.gradle @@ -251,7 +251,6 @@ subprojects { "org.elasticsearch.plugin:parent-join-client:${version}": ':modules:parent-join', "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}": ':modules:aggs-matrix-stats', "org.elasticsearch.plugin:percolator-client:${version}": ':modules:percolator', - "org.elasticsearch.plugin:aggs-composite-client:${version}": ':modules:aggs-composite', ] if (indexCompatVersions[-1].snapshot) { /* The last and second to last versions can be snapshots. Rather than use diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index b9b6c6f7027..ba97605dba8 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -39,8 +39,7 @@ dependencies { compile "org.elasticsearch.client:elasticsearch-rest-client:${version}" compile "org.elasticsearch.plugin:parent-join-client:${version}" compile "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}" - compile "org.elasticsearch.plugin:aggs-composite-client:${version}" - + testCompile "org.elasticsearch.client:test:${version}" testCompile "org.elasticsearch.test:framework:${version}" testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index e4827cf31c0..2ebaf2cf342 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -56,6 +56,8 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.adjacency.ParsedAdjacencyMatrix; +import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.composite.ParsedComposite; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter; @@ -621,6 +623,7 @@ public class RestHighLevelClient implements Closeable { map.put(ScriptedMetricAggregationBuilder.NAME, (p, c) -> ParsedScriptedMetric.fromXContent(p, (String) c)); map.put(IpRangeAggregationBuilder.NAME, (p, c) -> ParsedBinaryRange.fromXContent(p, (String) c)); map.put(TopHitsAggregationBuilder.NAME, (p, c) -> ParsedTopHits.fromXContent(p, (String) c)); + map.put(CompositeAggregationBuilder.NAME, (p, c) -> ParsedComposite.fromXContent(p, (String) c)); List entries = map.entrySet().stream() .map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())) .collect(Collectors.toList()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 8e0c13aea47..1ab4c60d624 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -62,7 +62,6 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.InternalAggregations; -import org.elasticsearch.search.aggregations.composite.CompositeAggregationBuilder; import org.elasticsearch.search.aggregations.matrix.stats.MatrixStatsAggregationBuilder; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.test.ESTestCase; @@ -649,7 +648,7 @@ public class RestHighLevelClientTests extends ESTestCase { public void testProvidedNamedXContents() { List namedXContents = RestHighLevelClient.getProvidedNamedXContents(); - assertEquals(3, namedXContents.size()); + assertEquals(2, namedXContents.size()); Map, Integer> categories = new HashMap<>(); List names = new ArrayList<>(); for (NamedXContentRegistry.Entry namedXContent : namedXContents) { @@ -660,10 +659,9 @@ public class RestHighLevelClientTests extends ESTestCase { } } assertEquals(1, categories.size()); - assertEquals(Integer.valueOf(3), categories.get(Aggregation.class)); + assertEquals(Integer.valueOf(2), categories.get(Aggregation.class)); assertTrue(names.contains(ChildrenAggregationBuilder.NAME)); assertTrue(names.contains(MatrixStatsAggregationBuilder.NAME)); - assertTrue(names.contains(CompositeAggregationBuilder.NAME)); } private static class TrackingActionListener implements ActionListener { diff --git a/client/transport/build.gradle b/client/transport/build.gradle index 562d047e74b..f09668ac6ac 100644 --- a/client/transport/build.gradle +++ b/client/transport/build.gradle @@ -32,7 +32,6 @@ dependencies { compile "org.elasticsearch.plugin:lang-mustache-client:${version}" compile "org.elasticsearch.plugin:percolator-client:${version}" compile "org.elasticsearch.plugin:parent-join-client:${version}" - compile "org.elasticsearch.plugin:aggs-composite-client:${version}" testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testCompile "junit:junit:${versions.junit}" testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}" diff --git a/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java b/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java index fbcdf90238d..2c28253e3f1 100644 --- a/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java +++ b/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java @@ -30,7 +30,6 @@ import org.elasticsearch.join.ParentJoinPlugin; import org.elasticsearch.percolator.PercolatorPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.mustache.MustachePlugin; -import org.elasticsearch.search.aggregations.composite.CompositeAggregationPlugin; import org.elasticsearch.transport.Netty4Plugin; import java.util.Arrays; @@ -45,7 +44,6 @@ import java.util.concurrent.TimeUnit; * {@link PercolatorPlugin}, * {@link MustachePlugin}, * {@link ParentJoinPlugin} - * {@link CompositeAggregationPlugin} * plugins for the client. These plugins are all the required modules for Elasticsearch. */ @SuppressWarnings({"unchecked","varargs"}) @@ -90,8 +88,7 @@ public class PreBuiltTransportClient extends TransportClient { ReindexPlugin.class, PercolatorPlugin.class, MustachePlugin.class, - ParentJoinPlugin.class, - CompositeAggregationPlugin.class)); + ParentJoinPlugin.class)); /** * Creates a new transport client with pre-installed plugins. diff --git a/client/transport/src/test/java/org/elasticsearch/transport/client/PreBuiltTransportClientTests.java b/client/transport/src/test/java/org/elasticsearch/transport/client/PreBuiltTransportClientTests.java index e20f2191e99..dbcfa8715f5 100644 --- a/client/transport/src/test/java/org/elasticsearch/transport/client/PreBuiltTransportClientTests.java +++ b/client/transport/src/test/java/org/elasticsearch/transport/client/PreBuiltTransportClientTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.transport.client; import com.carrotsearch.randomizedtesting.RandomizedTest; -import org.apache.lucene.util.Constants; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; @@ -30,7 +29,6 @@ import org.elasticsearch.percolator.PercolatorPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.mustache.MustachePlugin; import org.elasticsearch.transport.Netty4Plugin; -import org.elasticsearch.search.aggregations.composite.CompositeAggregationPlugin; import org.junit.Test; import java.util.Arrays; @@ -54,7 +52,7 @@ public class PreBuiltTransportClientTests extends RandomizedTest { public void testInstallPluginTwice() { for (Class plugin : Arrays.asList(ParentJoinPlugin.class, ReindexPlugin.class, PercolatorPlugin.class, - MustachePlugin.class, CompositeAggregationPlugin.class)) { + MustachePlugin.class)) { try { new PreBuiltTransportClient(Settings.EMPTY, plugin); fail("exception expected"); diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index dd7cf962d6c..323cca79617 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -99,6 +99,9 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.adjacency.InternalAdjacencyMatrix; +import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation; +import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.composite.InternalComposite; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; @@ -408,6 +411,8 @@ public class SearchModule { GeoCentroidAggregationBuilder::parse).addResultReader(InternalGeoCentroid::new)); registerAggregation(new AggregationSpec(ScriptedMetricAggregationBuilder.NAME, ScriptedMetricAggregationBuilder::new, ScriptedMetricAggregationBuilder::parse).addResultReader(InternalScriptedMetric::new)); + registerAggregation((new AggregationSpec(CompositeAggregationBuilder.NAME, CompositeAggregationBuilder::new, + CompositeAggregationBuilder::parse).addResultReader(InternalComposite::new))); registerFromPlugin(plugins, SearchPlugin::getAggregations, this::registerAggregation); } diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregation.java similarity index 97% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregation.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregation.java index 0bb611a5f60..9a22b2e3781 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregation.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java index 74490fb0e47..5b36063e17a 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationFactory.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationFactory.java similarity index 97% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationFactory.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationFactory.java index 4bb1c758e86..c0aeb5304a5 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationFactory.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationFactory.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationPlugin.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationPlugin.java similarity index 95% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationPlugin.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationPlugin.java index 8b12ffeca6d..bd49acbe4da 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationPlugin.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationPlugin.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SearchPlugin; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregator.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java index 9fd2a5e23b2..c18c414abb6 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.CollectionTerminatedException; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeKey.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java similarity index 80% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeKey.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java index 7b6e405aa83..6f3aacc9f82 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeKey.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java @@ -17,21 +17,9 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.search.DocValueFormat; - -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; /** * A key that is composed of multiple {@link Comparable} values. diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesComparator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesComparator.java similarity index 87% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesComparator.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesComparator.java index 5967e051466..849fe2c513e 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesComparator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesComparator.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; @@ -26,10 +26,6 @@ import org.elasticsearch.search.aggregations.LeafBucketCollector; import java.io.IOException; -import static org.elasticsearch.search.aggregations.composite.CompositeValuesSource.wrapBinary; -import static org.elasticsearch.search.aggregations.composite.CompositeValuesSource.wrapDouble; -import static org.elasticsearch.search.aggregations.composite.CompositeValuesSource.wrapGlobalOrdinals; -import static org.elasticsearch.search.aggregations.composite.CompositeValuesSource.wrapLong; import static org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import static org.elasticsearch.search.aggregations.support.ValuesSource.Bytes; import static org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals; @@ -51,16 +47,16 @@ final class CompositeValuesComparator { final int reverseMul = sources[i].reverseMul(); if (sources[i].valuesSource() instanceof WithOrdinals && reader instanceof DirectoryReader) { WithOrdinals vs = (WithOrdinals) sources[i].valuesSource(); - arrays[i] = wrapGlobalOrdinals(vs, size, reverseMul); + arrays[i] = CompositeValuesSource.wrapGlobalOrdinals(vs, size, reverseMul); } else if (sources[i].valuesSource() instanceof Bytes) { Bytes vs = (Bytes) sources[i].valuesSource(); - arrays[i] = wrapBinary(vs, size, reverseMul); + arrays[i] = CompositeValuesSource.wrapBinary(vs, size, reverseMul); } else if (sources[i].valuesSource() instanceof Numeric) { final Numeric vs = (Numeric) sources[i].valuesSource(); if (vs.isFloatingPoint()) { - arrays[i] = wrapDouble(vs, size, reverseMul); + arrays[i] = CompositeValuesSource.wrapDouble(vs, size, reverseMul); } else { - arrays[i] = wrapLong(vs, size, reverseMul); + arrays[i] = CompositeValuesSource.wrapLong(vs, size, reverseMul); } } } diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSource.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSource.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSource.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSource.java index b58e140ed04..045d8fa5ed3 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSource.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSource.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java index aee35807e82..2652d90f8c3 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceConfig.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceConfig.java similarity index 96% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceConfig.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceConfig.java index 4ffb7449d65..4d5c1c8c846 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceConfig.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceConfig.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.sort.SortOrder; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceParserHelper.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceParserHelper.java similarity index 98% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceParserHelper.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceParserHelper.java index 79728f8484a..c5d3d6f2fa6 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/CompositeValuesSourceParserHelper.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceParserHelper.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/DateHistogramValuesSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/DateHistogramValuesSourceBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java index 3a4b1052794..0094da5069f 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/DateHistogramValuesSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.search.SortField; import org.elasticsearch.common.ParseField; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSource.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java similarity index 97% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSource.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java index 045cc9bbd82..d9689fc0199 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSource.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java similarity index 98% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSourceBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java index 667d12c58cd..dd5eb1b52d0 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/HistogramValuesSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.search.SortField; import org.elasticsearch.common.io.stream.StreamInput; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/InternalComposite.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java similarity index 99% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/InternalComposite.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java index 124417d1fe6..bfeabcb9833 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/InternalComposite.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.io.stream.StreamInput; @@ -59,7 +59,7 @@ public class InternalComposite this.reverseMuls = reverseMuls; } - InternalComposite(StreamInput in) throws IOException { + public InternalComposite(StreamInput in) throws IOException { super(in); this.size = in.readVInt(); this.sourceNames = in.readList(StreamInput::readString); diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/ParsedComposite.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/ParsedComposite.java similarity index 98% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/ParsedComposite.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/ParsedComposite.java index e12f52ab780..a6c3fd3fb6f 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/ParsedComposite.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/ParsedComposite.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/RoundingValuesSource.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java similarity index 98% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/RoundingValuesSource.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java index f1e64ba94fc..099f2e5e0fd 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/RoundingValuesSource.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/TermsValuesSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java similarity index 98% rename from modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/TermsValuesSourceBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java index 1660e0fafb7..481c14a37f5 100644 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/TermsValuesSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.search.SortField; import org.elasticsearch.common.io.stream.StreamInput; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java index 8916379b9b7..55514fafc23 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.search.aggregations.Aggregation.CommonFields; import org.elasticsearch.search.aggregations.bucket.adjacency.InternalAdjacencyMatrixTests; +import org.elasticsearch.search.aggregations.bucket.composite.InternalCompositeTests; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilterTests; import org.elasticsearch.search.aggregations.bucket.filter.InternalFiltersTests; import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGridTests; @@ -144,6 +145,7 @@ public class AggregationsTests extends ESTestCase { aggsTests.add(new InternalScriptedMetricTests()); aggsTests.add(new InternalBinaryRangeTests()); aggsTests.add(new InternalTopHitsTests()); + aggsTests.add(new InternalCompositeTests()); return Collections.unmodifiableList(aggsTests); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilderTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilderTests.java new file mode 100644 index 00000000000..ae28d8f9304 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilderTests.java @@ -0,0 +1,94 @@ +/* + * 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.aggregations.bucket.composite; + +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.BaseAggregationTestCase; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.sort.SortOrder; + +import java.util.ArrayList; +import java.util.List; + +public class CompositeAggregationBuilderTests extends BaseAggregationTestCase { + private DateHistogramValuesSourceBuilder randomDateHistogramSourceBuilder() { + DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); + if (randomBoolean()) { + histo.field(randomAlphaOfLengthBetween(1, 20)); + } else { + histo.script(new Script(randomAlphaOfLengthBetween(10, 20))); + } + if (randomBoolean()) { + histo.dateHistogramInterval(randomFrom(DateHistogramInterval.days(10), + DateHistogramInterval.minutes(1), DateHistogramInterval.weeks(1))); + } else { + histo.interval(randomNonNegativeLong()); + } + if (randomBoolean()) { + histo.timeZone(randomDateTimeZone()); + } + return histo; + } + + private TermsValuesSourceBuilder randomTermsSourceBuilder() { + TermsValuesSourceBuilder terms = new TermsValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); + if (randomBoolean()) { + terms.field(randomAlphaOfLengthBetween(1, 20)); + } else { + terms.script(new Script(randomAlphaOfLengthBetween(10, 20))); + } + terms.order(randomFrom(SortOrder.values())); + return terms; + } + + private HistogramValuesSourceBuilder randomHistogramSourceBuilder() { + HistogramValuesSourceBuilder histo = new HistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); + if (randomBoolean()) { + histo.field(randomAlphaOfLengthBetween(1, 20)); + } else { + histo.script(new Script(randomAlphaOfLengthBetween(10, 20))); + } + histo.interval(randomDoubleBetween(Math.nextUp(0), Double.MAX_VALUE, false)); + return histo; + } + + @Override + protected CompositeAggregationBuilder createTestAggregatorBuilder() { + int numSources = randomIntBetween(1, 10); + List> sources = new ArrayList<>(); + for (int i = 0; i < numSources; i++) { + int type = randomIntBetween(0, 2); + switch (type) { + case 0: + sources.add(randomTermsSourceBuilder()); + break; + case 1: + sources.add(randomDateHistogramSourceBuilder()); + break; + case 2: + sources.add(randomHistogramSourceBuilder()); + break; + default: + throw new AssertionError("wrong branch"); + } + } + return new CompositeAggregationBuilder(randomAlphaOfLength(10), sources); + } +} diff --git a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregatorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java similarity index 99% rename from modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregatorTests.java rename to core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java index 7d8efe772a1..73ebd0089b0 100644 --- a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregatorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; diff --git a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/InternalCompositeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/InternalCompositeTests.java similarity index 88% rename from modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/InternalCompositeTests.java rename to core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/InternalCompositeTests.java index 31e465de223..10cc5b8016d 100644 --- a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/InternalCompositeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/InternalCompositeTests.java @@ -17,18 +17,11 @@ * under the License. */ -package org.elasticsearch.search.aggregations.composite; +package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.common.xcontent.ContextParser; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.search.SearchModule; -import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.ParsedAggregation; @@ -82,23 +75,6 @@ public class InternalCompositeTests extends InternalMultiBucketAggregationTestCa formats = null; } - @Override - protected List getNamedXContents() { - List namedXContents = new ArrayList<>(getDefaultNamedXContents()); - ContextParser parser = (p, c) -> ParsedComposite.fromXContent(p, (String) c); - namedXContents.add(new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(CompositeAggregationBuilder.NAME), parser)); - return namedXContents; - } - - @Override - protected NamedWriteableRegistry getNamedWriteableRegistry() { - return new NamedWriteableRegistry( - new SearchModule( - Settings.EMPTY, false, Collections.singletonList(new CompositeAggregationPlugin()) - ).getNamedWriteables() - ); - } - @Override protected Writeable.Reader instanceReader() { return InternalComposite::new; diff --git a/modules/aggs-composite/build.gradle b/modules/aggs-composite/build.gradle deleted file mode 100644 index 2a3295b4225..00000000000 --- a/modules/aggs-composite/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ - -esplugin { - description 'A multi-bucket aggregation that can paginate buckets from different sources efficiently.' - classname 'org.elasticsearch.search.aggregations.composite.CompositeAggregationPlugin' - hasClientJar = true -} - -compileJava.options.compilerArgs << "-Xlint:-deprecation" -compileTestJava.options.compilerArgs << "-Xlint:-deprecation" diff --git a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/spi/CompositeNamedXContentProvider.java b/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/spi/CompositeNamedXContentProvider.java deleted file mode 100644 index 5da3a94bcd4..00000000000 --- a/modules/aggs-composite/src/main/java/org/elasticsearch/search/aggregations/composite/spi/CompositeNamedXContentProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.aggregations.composite.spi; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ContextParser; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.plugins.spi.NamedXContentProvider; -import org.elasticsearch.search.aggregations.Aggregation; -import org.elasticsearch.search.aggregations.composite.CompositeAggregationBuilder; -import org.elasticsearch.search.aggregations.composite.ParsedComposite; - -import java.util.List; - -import static java.util.Collections.singletonList; - -public class CompositeNamedXContentProvider implements NamedXContentProvider { - - @Override - public List getNamedXContentParsers() { - ParseField parseField = new ParseField(CompositeAggregationBuilder.NAME); - ContextParser contextParser = (p, name) -> ParsedComposite.fromXContent(p, (String) name); - return singletonList(new NamedXContentRegistry.Entry(Aggregation.class, parseField, contextParser)); - } -} diff --git a/modules/aggs-composite/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider b/modules/aggs-composite/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider deleted file mode 100644 index 7fe3cff92ec..00000000000 --- a/modules/aggs-composite/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider +++ /dev/null @@ -1 +0,0 @@ -org.elasticsearch.search.aggregations.composite.spi.CompositeNamedXContentProvider \ No newline at end of file diff --git a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilderTests.java b/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilderTests.java deleted file mode 100644 index 7e1f93c87fa..00000000000 --- a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationBuilderTests.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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.aggregations.composite; - -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.script.Script; -import org.elasticsearch.search.SearchModule; -import org.elasticsearch.search.aggregations.AggregationBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.test.ESTestCase; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode; -import static org.hamcrest.Matchers.hasSize; - -public class CompositeAggregationBuilderTests extends ESTestCase { - static final CompositeAggregationPlugin PLUGIN = new CompositeAggregationPlugin(); - - @Override - protected NamedXContentRegistry xContentRegistry() { - return new NamedXContentRegistry( - new SearchModule(Settings.EMPTY, false, Collections.singletonList(PLUGIN)).getNamedXContents() - ); - } - - @Override - protected NamedWriteableRegistry writableRegistry() { - return new NamedWriteableRegistry( - new SearchModule(Settings.EMPTY, false, Collections.singletonList(PLUGIN)).getNamedWriteables() - ); - } - - private DateHistogramValuesSourceBuilder randomDateHistogramSourceBuilder() { - DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); - if (randomBoolean()) { - histo.field(randomAlphaOfLengthBetween(1, 20)); - } else { - histo.script(new Script(randomAlphaOfLengthBetween(10, 20))); - } - if (randomBoolean()) { - histo.dateHistogramInterval(randomFrom(DateHistogramInterval.days(10), - DateHistogramInterval.minutes(1), DateHistogramInterval.weeks(1))); - } else { - histo.interval(randomNonNegativeLong()); - } - if (randomBoolean()) { - histo.timeZone(randomDateTimeZone()); - } - return histo; - } - - private TermsValuesSourceBuilder randomTermsSourceBuilder() { - TermsValuesSourceBuilder terms = new TermsValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); - if (randomBoolean()) { - terms.field(randomAlphaOfLengthBetween(1, 20)); - } else { - terms.script(new Script(randomAlphaOfLengthBetween(10, 20))); - } - terms.order(randomFrom(SortOrder.values())); - return terms; - } - - private HistogramValuesSourceBuilder randomHistogramSourceBuilder() { - HistogramValuesSourceBuilder histo = new HistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10)); - if (randomBoolean()) { - histo.field(randomAlphaOfLengthBetween(1, 20)); - } else { - histo.script(new Script(randomAlphaOfLengthBetween(10, 20))); - } - histo.interval(randomDoubleBetween(Math.nextUp(0), Double.MAX_VALUE, false)); - return histo; - } - - private CompositeAggregationBuilder randomBuilder() { - int numSources = randomIntBetween(1, 10); - List> sources = new ArrayList<>(); - for (int i = 0; i < numSources; i++) { - int type = randomIntBetween(0, 2); - switch (type) { - case 0: - sources.add(randomTermsSourceBuilder()); - break; - case 1: - sources.add(randomDateHistogramSourceBuilder()); - break; - case 2: - sources.add(randomHistogramSourceBuilder()); - break; - default: - throw new AssertionError("wrong branch"); - } - } - return new CompositeAggregationBuilder(randomAlphaOfLength(10), sources); - } - - public void testFromXContent() throws IOException { - CompositeAggregationBuilder testAgg = randomBuilder(); - AggregatorFactories.Builder factoriesBuilder = AggregatorFactories.builder().addAggregator(testAgg); - XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); - if (randomBoolean()) { - builder.prettyPrint(); - } - factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - XContentBuilder shuffled = shuffleXContent(builder); - XContentParser parser = createParser(shuffled); - AggregationBuilder newAgg = assertParse(parser); - assertNotSame(newAgg, testAgg); - assertEquals(testAgg, newAgg); - assertEquals(testAgg.hashCode(), newAgg.hashCode()); - } - - public void testToString() throws IOException { - CompositeAggregationBuilder testAgg = randomBuilder(); - String toString = randomBoolean() ? Strings.toString(testAgg) : testAgg.toString(); - XContentParser parser = createParser(XContentType.JSON.xContent(), toString); - AggregationBuilder newAgg = assertParse(parser); - assertNotSame(newAgg, testAgg); - assertEquals(testAgg, newAgg); - assertEquals(testAgg.hashCode(), newAgg.hashCode()); - } - - private AggregationBuilder assertParse(XContentParser parser) throws IOException { - assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); - AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parser); - assertThat(parsed.getAggregatorFactories(), hasSize(1)); - assertThat(parsed.getPipelineAggregatorFactories(), hasSize(0)); - AggregationBuilder newAgg = parsed.getAggregatorFactories().get(0); - assertNull(parser.nextToken()); - assertNotNull(newAgg); - return newAgg; - } - - /** - * Test serialization and deserialization of the test AggregatorFactory. - */ - public void testSerialization() throws IOException { - CompositeAggregationBuilder testAgg = randomBuilder(); - try (BytesStreamOutput output = new BytesStreamOutput()) { - output.writeNamedWriteable(testAgg); - try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry())) { - AggregationBuilder deserialized = in.readNamedWriteable(AggregationBuilder.class); - assertEquals(testAgg, deserialized); - assertEquals(testAgg.hashCode(), deserialized.hashCode()); - assertNotSame(testAgg, deserialized); - } - } - } - - public void testEqualsAndHashcode() throws IOException { - checkEqualsAndHashCode(randomBuilder(), this::copyAggregation); - } - - private CompositeAggregationBuilder copyAggregation(CompositeAggregationBuilder agg) throws IOException { - try (BytesStreamOutput output = new BytesStreamOutput()) { - agg.writeTo(output); - try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writableRegistry())) { - return (CompositeAggregationBuilder) writableRegistry().getReader(AggregationBuilder.class, - agg.getWriteableName()).read(in); - } - } - } -} diff --git a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationsClientYamlTestSuiteIT.java b/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationsClientYamlTestSuiteIT.java deleted file mode 100644 index 4dbdd4e573d..00000000000 --- a/modules/aggs-composite/src/test/java/org/elasticsearch/search/aggregations/composite/CompositeAggregationsClientYamlTestSuiteIT.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.aggregations.composite; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; -import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; - -public class CompositeAggregationsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public CompositeAggregationsClientYamlTestSuiteIT(@Name("yaml")ClientYamlTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(); - } -} diff --git a/modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/10_basic.yml b/modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/10_basic.yml deleted file mode 100644 index b1d5799f7d2..00000000000 --- a/modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/10_basic.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Integration tests for Composite aggs plugin -# -"Composite aggs loaded": - - do: - cluster.state: {} - - # Get master node id - - set: { master_node: master } - - - do: - nodes.info: {} - - - match: { nodes.$master.modules.0.name: aggs-composite } diff --git a/modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/20_composite.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml similarity index 99% rename from modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/20_composite.yml rename to rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml index 63fdf695d0a..75e7d6a4afb 100644 --- a/modules/aggs-composite/src/test/resources/rest-api-spec/test/composite/20_composite.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/230_composite.yml @@ -190,7 +190,3 @@ setup: } } ] - - - - diff --git a/settings.gradle b/settings.gradle index e1b31d71b0c..997f3b30da5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,7 +31,6 @@ List projects = [ 'test:fixtures:old-elasticsearch', 'test:logger-usage', 'modules:aggs-matrix-stats', - 'modules:aggs-composite', 'modules:analysis-common', 'modules:ingest-common', 'modules:lang-expression', diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java index 0aa88dc308b..a69695fa183 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java @@ -41,6 +41,8 @@ import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.adjacency.ParsedAdjacencyMatrix; +import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.composite.ParsedComposite; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter; @@ -136,7 +138,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; import static org.elasticsearch.test.XContentTestUtils.insertRandomFields; @@ -194,6 +195,7 @@ public abstract class InternalAggregationTestCase map.put(ScriptedMetricAggregationBuilder.NAME, (p, c) -> ParsedScriptedMetric.fromXContent(p, (String) c)); map.put(IpRangeAggregationBuilder.NAME, (p, c) -> ParsedBinaryRange.fromXContent(p, (String) c)); map.put(TopHitsAggregationBuilder.NAME, (p, c) -> ParsedTopHits.fromXContent(p, (String) c)); + map.put(CompositeAggregationBuilder.NAME, (p, c) -> ParsedComposite.fromXContent(p, (String) c)); namedXContents = map.entrySet().stream() .map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue()))