Skip to content

Commit

Permalink
Aggregations: Make the list of buckets for terms and histogram return…
Browse files Browse the repository at this point in the history
…ed as a java.util.List.

The terms and histogram aggregations always have an order. So it would make the
response easier to consume to return the buckets as a list instead of a
collection in order to make it easier to do things like getting the first/last
buckets.

Close #7275
  • Loading branch information
jpountz committed Aug 18, 2014
1 parent 0156bcb commit 436e37c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Expand Up @@ -20,7 +20,7 @@

import org.joda.time.DateTime;

import java.util.Collection;
import java.util.List;

/**
* A {@code date_histogram} aggregation.
Expand All @@ -37,7 +37,7 @@ static interface Bucket extends Histogram.Bucket {
}

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

@Override
Bucket getBucketByKey(String key);
Expand Down
Expand Up @@ -21,8 +21,8 @@
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;

/**
* A {@code histogram} aggregation. Defines multiple buckets, each representing an interval in a histogram.
Expand All @@ -44,7 +44,7 @@ static interface Bucket extends MultiBucketsAggregation.Bucket {
/**
* @return The buckets of this histogram (each bucket representing an interval in the histogram)
*/
Collection<? extends Bucket> getBuckets();
List<? extends Bucket> getBuckets();

/**
* Returns a bucket by the key associated with it.
Expand Down
Expand Up @@ -40,7 +40,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;

Expand Down Expand Up @@ -230,7 +229,7 @@ public Type type() {
}

@Override
public Collection<B> getBuckets() {
public List<B> getBuckets() {
return buckets;
}

Expand Down
Expand Up @@ -120,9 +120,9 @@ protected InternalTerms(String name, InternalOrder order, int requiredSize, int
}

@Override
public Collection<Terms.Bucket> getBuckets() {
public List<Terms.Bucket> getBuckets() {
Object o = buckets;
return (Collection<Terms.Bucket>) o;
return (List<Terms.Bucket>) o;
}

@Override
Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;

/**
* A {@code terms} aggregation. Defines multiple bucket, each associated with a unique term for a specific field.
Expand Down Expand Up @@ -70,7 +70,10 @@ static abstract class Bucket implements MultiBucketsAggregation.Bucket {

}

Collection<Bucket> getBuckets();
/**
* Return the sorted list of the buckets in this terms aggregation.
*/
List<Bucket> getBuckets();

Bucket getBucketByKey(String term);

Expand Down

0 comments on commit 436e37c

Please sign in to comment.