Module org.elasticsearch.server
Record Class SamplingContext
java.lang.Object
java.lang.Record
org.elasticsearch.search.aggregations.support.SamplingContext
This provides information around the current sampling context for aggregations
-
Field Summary
-
Constructor Summary
ConstructorDescriptionSamplingContext
(double probability, int seed) Creates an instance of aSamplingContext
record class. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.lucene.search.Query
buildQueryWithSampler
(QueryBuilder builder, AggregationContext context) 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
hashCode()
Returns a hash code value for this object.boolean
double
Returns the value of theprobability
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 probabilitylong
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 valueint
seed()
Returns the value of theseed
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
NONE
-
-
Constructor Details
-
SamplingContext
public SamplingContext(double probability, int seed) Creates an instance of aSamplingContext
record class.- Parameters:
probability
- the value for theprobability
record componentseed
- the value for theseed
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 querycontext
- 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
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. -
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. -
equals
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 '=='. -
probability
public double probability()Returns the value of theprobability
record component.- Returns:
- the value of the
probability
record component
-
seed
public int seed()Returns the value of theseed
record component.- Returns:
- the value of the
seed
record component
-