Skip to content

Commit

Permalink
Make path syntax for lower and upper standard deviation bounds in the…
Browse files Browse the repository at this point in the history
… extended_stats aggregation more obvious

Fix for elastic#19040
  • Loading branch information
alexshadow007 committed Oct 8, 2016
1 parent 6418f89 commit c46e3b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Expand Up @@ -67,7 +67,7 @@ public interface ExtendedStats extends Stats {
String getVarianceAsString();


public enum Bounds {
enum Bounds {
UPPER, LOWER
}

Expand Down
Expand Up @@ -90,6 +90,20 @@ public double value(String name) {
return super.value(name);
}

@Override
public Object getProperty(List<String> path) {
if (path.size() == 2 && "std_deviation_bounds".equals(path.get(0))) {
String bound = path.get(1);
if ("lower".equals(bound)) {
return getStdDeviationBound(Bounds.LOWER);
}
if ("upper".equals(bound)) {
return getStdDeviationBound(Bounds.UPPER);
}
}
return super.getProperty(path);
}

@Override
public double getSumOfSquares() {
return sumOfSqrs;
Expand Down
Expand Up @@ -19,7 +19,13 @@

package org.elasticsearch.search.aggregations.metrics;

import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats;
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats;
import org.junit.Test;

import java.util.Collections;

public class ExtendedStatsTests extends AbstractNumericMetricTestCase<ExtendedStatsAggregationBuilder> {

Expand All @@ -32,4 +38,15 @@ protected ExtendedStatsAggregationBuilder doCreateTestAggregatorFactory() {
return factory;
}

@Test
public void getStdDeviationBoundsByPath() throws Exception {
double min = 1.0;
double max = 4.0;

ExtendedStats stats = new InternalExtendedStats("test", 2, min + max, min, max, Math.pow(min, 2) + Math.pow(max, 2),
1.0, DocValueFormat.RAW, Collections.emptyList(), Collections.emptyMap());

assertEquals(stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), stats.getProperty("std_deviation_bounds.lower"));
assertEquals(stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), stats.getProperty("std_deviation_bounds.upper"));
}
}

0 comments on commit c46e3b6

Please sign in to comment.