|
|
@@ -15,6 +15,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
|
import org.elasticsearch.core.CheckedFunction;
|
|
|
+import org.elasticsearch.index.fielddata.FieldData;
|
|
|
+import org.elasticsearch.index.fielddata.NumericDoubleValues;
|
|
|
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
|
|
|
import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType;
|
|
|
import org.elasticsearch.index.mapper.DateFieldMapper.Resolution;
|
|
|
@@ -93,6 +95,16 @@ public abstract class RangeAggregator extends BucketsAggregator {
|
|
|
|
|
|
static final DoubleUnaryOperator IDENTITY = DoubleUnaryOperator.identity();
|
|
|
|
|
|
+ /**
|
|
|
+ * Count of ranges with single values.
|
|
|
+ */
|
|
|
+ private int singletonRanges;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Count of ranges with more than a single value.
|
|
|
+ */
|
|
|
+ private int nonsingletonRanges;
|
|
|
+
|
|
|
public static class Range implements Writeable, ToXContentObject {
|
|
|
public static final ParseField KEY_FIELD = new ParseField("key");
|
|
|
public static final ParseField FROM_FIELD = new ParseField("from");
|
|
|
@@ -565,6 +577,8 @@ public abstract class RangeAggregator extends BucketsAggregator {
|
|
|
super.collectDebugInfo(add);
|
|
|
add.accept("ranges", ranges.length);
|
|
|
add.accept("average_docs_per_range", averageDocsPerRange);
|
|
|
+ add.accept("singletons", singletonRanges);
|
|
|
+ add.accept("non-singletons", nonsingletonRanges);
|
|
|
}
|
|
|
|
|
|
public static class Unmapped<R extends RangeAggregator.Range> extends NonCollectingAggregator {
|
|
|
@@ -640,6 +654,20 @@ public abstract class RangeAggregator extends BucketsAggregator {
|
|
|
@Override
|
|
|
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
|
|
|
final SortedNumericDoubleValues values = ((ValuesSource.Numeric) this.valuesSource).doubleValues(ctx);
|
|
|
+ final NumericDoubleValues singleton = FieldData.unwrapSingleton(values);
|
|
|
+
|
|
|
+ if (singleton != null) {
|
|
|
+ super.singletonRanges++;
|
|
|
+ return new LeafBucketCollectorBase(sub, values) {
|
|
|
+ @Override
|
|
|
+ public void collect(int doc, long bucket) throws IOException {
|
|
|
+ if (singleton.advanceExact(doc)) {
|
|
|
+ NumericRangeAggregator.this.collect(sub, doc, singleton.doubleValue(), bucket, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ super.nonsingletonRanges++;
|
|
|
return new LeafBucketCollectorBase(sub, values) {
|
|
|
@Override
|
|
|
public void collect(int doc, long bucket) throws IOException {
|