Class InternalAggregation
java.lang.Object
org.elasticsearch.search.aggregations.InternalAggregation
- All Implemented Interfaces:
NamedWriteable,Writeable,Aggregation,org.elasticsearch.xcontent.ToXContent,org.elasticsearch.xcontent.ToXContentFragment
- Direct Known Subclasses:
InternalGeoBounds,InternalGeoCentroid,InternalMultiBucketAggregation,InternalMultiValueAggregation,InternalNumericMetricsAggregation,InternalScriptedMetric,InternalSingleBucketAggregation,InternalTopHits
An internal implementation of
Aggregation. Serves as a base class for all aggregation implementations.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.search.aggregations.Aggregation
Aggregation.CommonFieldsNested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
org.elasticsearch.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.xcontent.ToXContent.MapParams, org.elasticsearch.xcontent.ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsFields inherited from interface org.elasticsearch.search.aggregations.Aggregation
TYPED_KEYS_DELIMITERFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInternalAggregation(String name, Map<String, Object> metadata) Constructs an aggregation result with a given name.protectedRead from a stream. -
Method Summary
Modifier and TypeMethodDescriptionRewrite the sub-aggregations in the buckets in this aggregation.protected abstract voiddoWriteTo(StreamOutput out) abstract org.elasticsearch.xcontent.XContentBuilderdoXContentBody(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) booleanfinalizeSampling(SamplingContext samplingContext) Called by the parent sampling context.voidforEachBucket(Consumer<InternalAggregations> consumer) Run a Consumer over all buckets in this aggregation.Get the optional byte array metadata that was set on the aggregationgetName()getProperty(String path) Get the value of specified path in the aggregation.abstract ObjectgetProperty(List<String> path) getType()inthashCode()booleanisMapped()Return true if this aggregation is mapped, and can lead a reduction.protected abstract booleanSignal the framework if the reduce(List, AggregationReduceContext) phase needs to be called when there is only one InternalAggregation.protected static intreadSize(StreamInput in) Read a size under the assumption that a value of 0 means unlimited.abstract InternalAggregationreduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) Reduces the given aggregations to a single one and returns it.reducePipelines(InternalAggregation reducedAggs, AggregationReduceContext reduceContext, PipelineAggregator.PipelineTree pipelinesForThisAgg) Creates the output from all pipeline aggs that this aggregation is associated with.Get value to use when sorting by this aggregation.Get value to use when sorting by a descendant of this aggregation.toString()final org.elasticsearch.xcontent.XContentBuildertoXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) protected static voidwriteSize(int size, StreamOutput out) Write a size under the assumption that a value of 0 means unlimited.final voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.common.io.stream.NamedWriteable
getWriteableNameMethods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
-
Field Details
-
name
-
metadata
-
-
Constructor Details
-
InternalAggregation
Constructs an aggregation result with a given name.- Parameters:
name- The name of the aggregation.
-
InternalAggregation
Read from a stream.- Throws:
IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
doWriteTo
- Throws:
IOException
-
getName
- Specified by:
getNamein interfaceAggregation- Returns:
- The name of this aggregation.
-
copyWithRewritenBuckets
public InternalAggregation copyWithRewritenBuckets(Function<InternalAggregations, InternalAggregations> rewriter) Rewrite the sub-aggregations in the buckets in this aggregation. Returns a copy of this InternalAggregation with the rewritten buckets, or, if there aren't any modifications to the buckets then this method will return this aggregation. Either way, it doesn't modify this aggregation.Implementers of this should call the
rewriteronce per bucket with its InternalAggregations. Therewritershould returnnullif it doen't have any rewriting to do or it should return a new InternalAggregations to make changs.The default implementation throws an exception because most aggregations don't have buckets in them. It should be overridden by aggregations that contain buckets. Implementers should respect the description above.
-
forEachBucket
Run a Consumer over all buckets in this aggregation. -
reducePipelines
public InternalAggregation reducePipelines(InternalAggregation reducedAggs, AggregationReduceContext reduceContext, PipelineAggregator.PipelineTree pipelinesForThisAgg) Creates the output from all pipeline aggs that this aggregation is associated with. Should only be called after all aggregations have been fully reduced -
reduce
public abstract InternalAggregation reduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) Reduces the given aggregations to a single one and returns it. In most cases, the assumption will be the all given aggregations are of the same type (the same type as this aggregation). For best efficiency, when implementing, try reusing an existing instance (typically the first in the given list) to save on redundant object construction.- See Also:
-
finalizeSampling
Called by the parent sampling context. Should only ever be called once as some aggregations scale their internal values- Parameters:
samplingContext- the current sampling context- Returns:
- new aggregation with the sampling context applied, could be the same aggregation instance if nothing needs to be done
-
mustReduceOnSingleInternalAgg
protected abstract boolean mustReduceOnSingleInternalAgg()Signal the framework if the reduce(List, AggregationReduceContext) phase needs to be called when there is only one InternalAggregation. -
isMapped
public boolean isMapped()Return true if this aggregation is mapped, and can lead a reduction. If this agg returns false, it should return itself if asked to lead a reduction -
getProperty
Get the value of specified path in the aggregation.- Parameters:
path- the path to the property in the aggregation tree- Returns:
- the value of the property
-
getProperty
-
readSize
Read a size under the assumption that a value of 0 means unlimited.- Throws:
IOException
-
writeSize
Write a size under the assumption that a value of 0 means unlimited.- Throws:
IOException
-
getMetadata
Description copied from interface:AggregationGet the optional byte array metadata that was set on the aggregation- Specified by:
getMetadatain interfaceAggregation
-
getType
- Specified by:
getTypein interfaceAggregation- Returns:
- a string representing the type of the aggregation. This type is added to the aggregation name in the response, so that it can later be used by clients to determine type of the aggregation and parse it into the proper object.
-
toXContent
public final org.elasticsearch.xcontent.XContentBuilder toXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceorg.elasticsearch.xcontent.ToXContent- Throws:
IOException
-
doXContentBody
public abstract org.elasticsearch.xcontent.XContentBuilder doXContentBody(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) throws IOException - Throws:
IOException
-
hashCode
public int hashCode() -
equals
-
toString
-
sortValue
Get value to use when sorting by this aggregation. -
sortValue
public SortValue sortValue(AggregationPath.PathElement head, Iterator<AggregationPath.PathElement> tail) Get value to use when sorting by a descendant of this aggregation.
-