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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    aggregation(String path, boolean asc)
    Creates a bucket ordering strategy which sorts buckets based on a single-valued sub-aggregation.
    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.
    Build a comparator for fully built buckets.
    Creates a bucket ordering strategy which sorts buckets based on multiple criteria.
    compound(BucketOrder... orders)
    Creates a bucket ordering strategy which sorts buckets based on multiple criteria.
    count(boolean asc)
    Creates a bucket ordering strategy that sorts buckets by their document counts (ascending or descending).
    abstract boolean
     
    abstract int
     
    key(boolean asc)
    Creates a bucket ordering strategy that sorts buckets by their keys (ascending or descending).
    A builds comparator comparing buckets partially built buckets by delegating comparison of the results of any "child" aggregations to the provided Aggregator.
     
    void
    validate(Aggregator aggregator)
    Validate an aggregation against an Aggregator.
    void
    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

      public static BucketOrder count(boolean asc)
      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

      public static BucketOrder key(boolean asc)
      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

      public static BucketOrder aggregation(String path, boolean asc)
      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

      public 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.
      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

      public static BucketOrder compound(List<BucketOrder> orders)
      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 of BucketOrder objects to sort on, in order of priority.
    • compound

      public static BucketOrder compound(BucketOrder... orders)
      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 of BucketOrder parameters to sort on, in order of priority.
    • validate

      public final void validate(Aggregator aggregator) throws AggregationExecutionException
      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

      public abstract Comparator<MultiBucketsAggregation.Bucket> comparator()
      Build a comparator for fully built buckets.
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object