Skip to content

Commit

Permalink
Aggregations: Adds methods to get to/from as Strings for Range Aggs
Browse files Browse the repository at this point in the history
Adds getToAsString and getFromAsString to Range interface and implements them for all range aggregations

Closes #9003
  • Loading branch information
colings86 committed Dec 22, 2014
1 parent c7558ab commit 2b47e54
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 9 deletions.
Expand Up @@ -19,6 +19,7 @@
package org.elasticsearch.search.aggregations.bucket.range;

import com.google.common.collect.Lists;

import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -94,6 +95,28 @@ public Number getTo() {
return to;
}

@Override
public String getFromAsString() {
if (Double.isInfinite(from)) {
return null;
} else if (formatter == null) {
return ValueFormatter.RAW.format(from);
} else {
return formatter.format(from);
}
}

@Override
public String getToAsString() {
if (Double.isInfinite(to)) {
return null;
} else if (formatter == null) {
return ValueFormatter.RAW.format(to);
} else {
return formatter.format(to);
}
}

@Override
public long getDocCount() {
return docCount;
Expand Down Expand Up @@ -151,7 +174,7 @@ protected String generateKey(double from, double to, @Nullable ValueFormatter fo
return sb.toString();
}

}
}

public static class Factory<B extends Bucket, R extends InternalRange<B>> {

Expand Down
Expand Up @@ -20,7 +20,6 @@

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;

import java.util.Collection;

/**
* A {@code range} aggregation. Defines multiple buckets, each associated with a pre-defined value range of a field,
Expand All @@ -38,16 +37,26 @@ public static interface Bucket extends MultiBucketsAggregation.Bucket {
*/
Number getFrom();

/**
* @return The string value for the lower bound of the range
*/
String getFromAsString();

/**
* @return The upper bound of the range (excluding)
*/
Number getTo();

/**
* @return The string value for the upper bound of the range (excluding)
*/
String getToAsString();
}

/**
* Return the buckets of this range aggregation.
*/
Collection<? extends Bucket> getBuckets();
List<? extends Bucket> getBuckets();

@Override
Bucket getBucketByKey(String key);
Expand Down
Expand Up @@ -20,7 +20,6 @@

import org.elasticsearch.search.aggregations.bucket.range.Range;

import java.util.Collection;

/**
* A range aggregation on ipv4 values.
Expand All @@ -29,14 +28,10 @@ public interface IPv4Range extends Range {

static interface Bucket extends Range.Bucket {

String getFromAsString();

String getToAsString();

}

@Override
Collection<? extends IPv4Range.Bucket> getBuckets();
List<? extends Bucket> getBuckets();

@Override
IPv4Range.Bucket getBucketByKey(String key);
Expand Down

0 comments on commit 2b47e54

Please sign in to comment.