More update to support Reducer Builders
This commit is contained in:
parent
c97dd84bad
commit
511e275825
|
@ -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<B extends AggregationBuilder<B>> extends AbstractAggregationBuilder {
|
||||
|
||||
private List<AbstractAggregationBuilder> aggregations;
|
||||
private List<ReducerBuilder<?>> reducers;
|
||||
private BytesReference aggregationsBinary;
|
||||
private Map<String, Object> metaData;
|
||||
|
||||
|
@ -59,6 +62,18 @@ public abstract class AggregationBuilder<B extends AggregationBuilder<B>> 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<B extends AggregationBuilder<B>> 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<B extends AggregationBuilder<B>> 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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -301,6 +301,10 @@ public class InternalHistogram<B extends InternalHistogram.Bucket> extends Inter
|
|||
return factory;
|
||||
}
|
||||
|
||||
public InternalOrder getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
private static class IteratorAndCurrent<B> {
|
||||
|
||||
private final Iterator<B> iterator;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<B extends ReducerBuilder<B>> implements ToX
|
|||
|
||||
private final String name;
|
||||
protected final String type;
|
||||
private List<String> bucketsPaths;
|
||||
private String[] bucketsPaths;
|
||||
private Map<String, Object> metaData;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +53,7 @@ public abstract class ReducerBuilder<B extends ReducerBuilder<B>> implements ToX
|
|||
/**
|
||||
* Sets the paths to the buckets to use for this reducer
|
||||
*/
|
||||
public B setBucketsPaths(List<String> bucketsPaths) {
|
||||
public B setBucketsPaths(String... bucketsPaths) {
|
||||
this.bucketsPaths = bucketsPaths;
|
||||
return (B) this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue