Record Class SamplingContext

java.lang.Object
java.lang.Record
org.elasticsearch.search.aggregations.support.SamplingContext

public record SamplingContext(double probability, int seed) extends Record
This provides information around the current sampling context for aggregations
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SamplingContext(double probability, int seed)
    Creates an instance of a SamplingContext record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.search.Query
    Builds the provided query builder into a Lucene query object.
    Optional<org.apache.lucene.search.Query>
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
     
    double
    Returns the value of the probability record component.
    double
    scaleDown(double value)
    Scales the given value according to the configured sampling probability.
    long
    scaleDown(long value)
    Scales the given value according to the configured sampling probability.
    double
    scaleUp(double value)
    This scales the given value according to the inverse of the configured sampling probability
    long
    scaleUp(long value)
    This scales the given value according to the inverse of the configured sampling probability The value is rounded to the nearest whole value
    int
    Returns the value of the seed record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SamplingContext

      public SamplingContext(double probability, int seed)
      Creates an instance of a SamplingContext record class.
      Parameters:
      probability - the value for the probability record component
      seed - the value for the seed record component
  • Method Details

    • isSampled

      public boolean isSampled()
    • scaleDown

      public long scaleDown(long value)
      Scales the given value according to the configured sampling probability. If the sampling context is NONE, then no scaling takes place.
      Parameters:
      value - the value to scale
      Returns:
      the scaled value, or the passed value if no sampling is configured
    • scaleUp

      public long scaleUp(long value)
      This scales the given value according to the inverse of the configured sampling probability The value is rounded to the nearest whole value
      Parameters:
      value - the value to inversely scale
      Returns:
      the scaled value, or the passed value if no sampling has been configured
    • scaleDown

      public double scaleDown(double value)
      Scales the given value according to the configured sampling probability. If the sampling context is NONE, then no scaling takes place.
      Parameters:
      value - the value to scale
      Returns:
      the scaled value, or the passed value if no sampling is configured
    • scaleUp

      public double scaleUp(double value)
      This scales the given value according to the inverse of the configured sampling probability
      Parameters:
      value - the value to inversely scale
      Returns:
      the scaled value, or the passed value if no sampling has been configured
    • buildQueryWithSampler

      public org.apache.lucene.search.Query buildQueryWithSampler(QueryBuilder builder, AggregationContext context) throws IOException
      Builds the provided query builder into a Lucene query object. The returned query takes sampling into account.
      Parameters:
      builder - The filter query to build along with the random sampling query
      context - The current aggregation context
      Returns:
      A lucene query that takes sampling into account if necessary
      Throws:
      IOException - on query build failure
    • buildSamplingQueryIfNecessary

      public Optional<org.apache.lucene.search.Query> buildSamplingQueryIfNecessary(AggregationContext context) throws IOException
      Parameters:
      context - The current aggregation context
      Returns:
      the sampling query if the sampling context indicates that sampling is required
      Throws:
      IOException - thrown on query build failure
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • probability

      public double probability()
      Returns the value of the probability record component.
      Returns:
      the value of the probability record component
    • seed

      public int seed()
      Returns the value of the seed record component.
      Returns:
      the value of the seed record component