From 5ae12368574b33a8fad215ef104108fbf5435eb3 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 4 Mar 2014 11:08:19 +0100 Subject: [PATCH] Fix `metric` impl on unmapped fields. --- .../search/aggregations/metrics/avg/AvgAggregator.java | 2 +- .../search/aggregations/metrics/max/MaxAggregator.java | 2 +- .../search/aggregations/metrics/min/MinAggregator.java | 2 +- .../search/aggregations/metrics/sum/SumAggregator.java | 2 +- .../aggregations/metrics/valuecount/ValueCountAggregator.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java index 1c52dfb2875..e0ce9a652ae 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java @@ -80,7 +80,7 @@ public class AvgAggregator extends MetricsAggregator.SingleValue { @Override public double metric(long owningBucketOrd) { - return sums.get(owningBucketOrd) / counts.get(owningBucketOrd); + return valuesSource == null ? Double.NaN : sums.get(owningBucketOrd) / counts.get(owningBucketOrd); } @Override diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java index 3a1e8e43852..2e01f01205c 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java @@ -80,7 +80,7 @@ public class MaxAggregator extends MetricsAggregator.SingleValue { @Override public double metric(long owningBucketOrd) { - return maxes.get(owningBucketOrd); + return valuesSource == null ? Double.NEGATIVE_INFINITY : maxes.get(owningBucketOrd); } @Override diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java index 3ef01ccc833..8fe98531f9c 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java @@ -79,7 +79,7 @@ public class MinAggregator extends MetricsAggregator.SingleValue { @Override public double metric(long owningBucketOrd) { - return mins.get(owningBucketOrd); + return valuesSource == null ? Double.POSITIVE_INFINITY : mins.get(owningBucketOrd); } @Override diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java index 21c67a8c0fb..15d4ce91270 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java @@ -75,7 +75,7 @@ public class SumAggregator extends MetricsAggregator.SingleValue { @Override public double metric(long owningBucketOrd) { - return sums.get(owningBucketOrd); + return valuesSource == null ? 0 : sums.get(owningBucketOrd); } @Override diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java index 60d11fdd7a8..51ee90f3c2f 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java @@ -74,7 +74,7 @@ public class ValueCountAggregator extends MetricsAggregator.SingleValue { @Override public double metric(long owningBucketOrd) { - return counts.get(owningBucketOrd); + return valuesSource == null ? 0 : counts.get(owningBucketOrd); } @Override