diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilder.java b/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilder.java index 5b9fab55aa4..cc3033e883f 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilder.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilder.java @@ -20,12 +20,14 @@ package org.elasticsearch.search.aggregations; import com.google.common.collect.Lists; + import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.client.Requests; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.search.aggregations.reducers.ReducerBuilder; import java.io.IOException; import java.util.List; @@ -37,6 +39,7 @@ import java.util.Map; public abstract class AggregationBuilder> extends AbstractAggregationBuilder { private List aggregations; + private List> reducers; private BytesReference aggregationsBinary; private Map metaData; @@ -59,6 +62,18 @@ public abstract class AggregationBuilder> extend return (B) this; } + /** + * Add a sub get to this bucket get. + */ + @SuppressWarnings("unchecked") + public B subAggregation(ReducerBuilder reducer) { + if (reducers == null) { + reducers = Lists.newArrayList(); + } + reducers.add(reducer); + return (B) this; + } + /** * Sets a raw (xcontent / json) sub addAggregation. */ @@ -120,7 +135,7 @@ public abstract class AggregationBuilder> extend builder.field(type); internalXContent(builder, params); - if (aggregations != null || aggregationsBinary != null) { + if (aggregations != null || aggregationsBinary != null || reducers != null) { builder.startObject("aggregations"); if (aggregations != null) { @@ -129,6 +144,12 @@ public abstract class AggregationBuilder> extend } } + if (reducers != null) { + for (ReducerBuilder subAgg : reducers) { + subAgg.toXContent(builder, params); + } + } + if (aggregationsBinary != null) { if (XContentFactory.xContentType(aggregationsBinary) == builder.contentType()) { builder.rawField("aggregations", aggregationsBinary); diff --git a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java index c99f885462c..fe4542830cc 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java @@ -57,6 +57,7 @@ import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExte import org.elasticsearch.search.aggregations.metrics.sum.InternalSum; import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits; import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount; +import org.elasticsearch.search.aggregations.reducers.InternalSimpleValue; import org.elasticsearch.search.aggregations.reducers.derivative.DerivativeReducer; /** @@ -103,6 +104,7 @@ public class TransportAggregationModule extends AbstractModule implements SpawnM InternalTopHits.registerStreams(); InternalGeoBounds.registerStream(); InternalChildren.registerStream(); + InternalSimpleValue.registerStreams(); // Reducers DerivativeReducer.registerStreams(); diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java index d5b3a1384f1..4171cc3f514 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java @@ -301,6 +301,10 @@ public class InternalHistogram extends Inter return factory; } + public InternalOrder getOrder() { + return order; + } + private static class IteratorAndCurrent { private final Iterator iterator; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalOrder.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalOrder.java index 9d503a8e90b..10902064786 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalOrder.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalOrder.java @@ -29,7 +29,7 @@ import java.util.Comparator; /** * An internal {@link Histogram.Order} strategy which is identified by a unique id. */ -class InternalOrder extends Histogram.Order { +public class InternalOrder extends Histogram.Order { final byte id; final String key; diff --git a/src/main/java/org/elasticsearch/search/aggregations/reducers/ReducerBuilder.java b/src/main/java/org/elasticsearch/search/aggregations/reducers/ReducerBuilder.java index 49bba5a0ecb..0f0f9225635 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/reducers/ReducerBuilder.java +++ b/src/main/java/org/elasticsearch/search/aggregations/reducers/ReducerBuilder.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -import java.util.List; import java.util.Map; /** @@ -33,7 +32,7 @@ public abstract class ReducerBuilder> implements ToX private final String name; protected final String type; - private List bucketsPaths; + private String[] bucketsPaths; private Map metaData; /** @@ -54,7 +53,7 @@ public abstract class ReducerBuilder> implements ToX /** * Sets the paths to the buckets to use for this reducer */ - public B setBucketsPaths(List bucketsPaths) { + public B setBucketsPaths(String... bucketsPaths) { this.bucketsPaths = bucketsPaths; return (B) this; }