Class BucketOrder
java.lang.Object
org.elasticsearch.search.aggregations.BucketOrder
- All Implemented Interfaces:
Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentObject
- Direct Known Subclasses:
InternalOrder
,InternalOrder.CompoundOrder
public abstract class BucketOrder
extends Object
implements org.elasticsearch.common.xcontent.ToXContentObject, Writeable
MultiBucketsAggregation.Bucket
ordering strategy. Buckets can be order either as
"complete" buckets using comparator()
or against a combination
of the buckets internals with its ordinal with
partiallyBuiltBucketComparator(ToLongFunction, Aggregator)
.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BucketOrder
aggregation(String path, boolean asc)
Creates a bucket ordering strategy which sorts buckets based on a single-valued sub-aggregation.static BucketOrder
aggregation(String path, String metricName, boolean asc)
Creates a bucket ordering strategy which sorts buckets based on a metric from a multi-valued sub-aggregation.abstract Comparator<MultiBucketsAggregation.Bucket>
Build a comparator for fully built buckets.static BucketOrder
compound(List<BucketOrder> orders)
Creates a bucket ordering strategy which sorts buckets based on multiple criteria.static BucketOrder
compound(BucketOrder... orders)
Creates a bucket ordering strategy which sorts buckets based on multiple criteria.static BucketOrder
count(boolean asc)
Creates a bucket ordering strategy that sorts buckets by their document counts (ascending or descending).abstract boolean
abstract int
hashCode()
static BucketOrder
key(boolean asc)
Creates a bucket ordering strategy that sorts buckets by their keys (ascending or descending).abstract <T extends MultiBucketsAggregation.Bucket>
Comparator<T>partiallyBuiltBucketComparator(ToLongFunction<T> ordinalReader, Aggregator aggregator)
A builds comparator comparing buckets partially built buckets by delegating comparison of the results of any "child" aggregations to the provided Aggregator.toString()
void
validate(Aggregator aggregator)
Validate an aggregation against an Aggregator.void
writeTo(StreamOutput out)
Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContent
toXContent
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Constructor Details
-
BucketOrder
public BucketOrder()
-
-
Method Details
-
count
Creates a bucket ordering strategy that sorts buckets by their document counts (ascending or descending).- Parameters:
asc
- direction to sort by:true
for ascending,false
for descending.
-
key
Creates a bucket ordering strategy that sorts buckets by their keys (ascending or descending). This may be used as a tie-breaker to avoid non-deterministic ordering.- Parameters:
asc
- direction to sort by:true
for ascending,false
for descending.
-
aggregation
Creates a bucket ordering strategy which sorts buckets based on a single-valued sub-aggregation.- Parameters:
path
- path to the sub-aggregation to sort on.asc
- direction to sort by:true
for ascending,false
for descending.- See Also:
AggregationPath
-
aggregation
Creates a bucket ordering strategy which sorts buckets based on a metric from a multi-valued sub-aggregation.- Parameters:
path
- path to the sub-aggregation to sort on.metricName
- name of the value of the multi-value metric to sort on.asc
- direction to sort by:true
for ascending,false
for descending.- See Also:
AggregationPath
-
compound
Creates a bucket ordering strategy which sorts buckets based on multiple criteria. A tie-breaker may be added to avoid non-deterministic ordering.- Parameters:
orders
- a list ofBucketOrder
objects to sort on, in order of priority.
-
compound
Creates a bucket ordering strategy which sorts buckets based on multiple criteria. A tie-breaker may be added to avoid non-deterministic ordering.- Parameters:
orders
- a list ofBucketOrder
parameters to sort on, in order of priority.
-
validate
Validate an aggregation against an Aggregator.- Throws:
AggregationExecutionException
- when the ordering is invalid for this Aggregator.
-
partiallyBuiltBucketComparator
public abstract <T extends MultiBucketsAggregation.Bucket> Comparator<T> partiallyBuiltBucketComparator(ToLongFunction<T> ordinalReader, Aggregator aggregator)A builds comparator comparing buckets partially built buckets by delegating comparison of the results of any "child" aggregations to the provided Aggregator.Warning: This is fairly difficult to use and impossible to use cleanly. In addition, this exists primarily to return the "top n" buckets based on the results of a sub aggregation. The trouble is that could end up throwing away buckets on the data nodes that should ultimately be kept after reducing all of the results. If you know that this is coming it is fine, but most folks that use "generic" sorts don't. In other words: before you use this method think super duper hard if you want to have these kinds of issues. The terms agg does an folks get into trouble with it all the time.
-
comparator
Build a comparator for fully built buckets. -
hashCode
public abstract int hashCode() -
equals
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Throws:
IOException
-
toString
-