Class InternalAggregation
java.lang.Object
org.elasticsearch.search.aggregations.InternalAggregation
- All Implemented Interfaces:
NamedWriteable
,Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentFragment
,Aggregation
- Direct Known Subclasses:
InternalGeoBounds
,InternalGeoCentroid
,InternalMultiBucketAggregation
,InternalNumericMetricsAggregation
,InternalScriptedMetric
,InternalSingleBucketAggregation
,InternalTopHits
public abstract class InternalAggregation extends java.lang.Object implements Aggregation, NamedWriteable
An internal implementation of
Aggregation
. Serves as a base class for all aggregation implementations.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InternalAggregation.ReduceContext
static interface
InternalAggregation.ReduceContextBuilder
Nested classes/interfaces inherited from interface org.elasticsearch.search.aggregations.Aggregation
Aggregation.CommonFields
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 Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.Object>
metadata
protected java.lang.String
name
Fields inherited from interface org.elasticsearch.search.aggregations.Aggregation
TYPED_KEYS_DELIMITER
-
Constructor Summary
Constructors Modifier Constructor Description protected
InternalAggregation(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> metadata)
Constructs an aggregation result with a given name.protected
InternalAggregation(StreamInput in)
Read from a stream. -
Method Summary
Modifier and Type Method Description InternalAggregation
copyWithRewritenBuckets(java.util.function.Function<InternalAggregations,InternalAggregations> rewriter)
Rewrite the sub-aggregations in the buckets in this aggregation.protected abstract void
doWriteTo(StreamOutput out)
abstract org.elasticsearch.common.xcontent.XContentBuilder
doXContentBody(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
boolean
equals(java.lang.Object obj)
void
forEachBucket(java.util.function.Consumer<InternalAggregations> consumer)
Run a Consumer over all buckets in this aggregation.java.util.Map<java.lang.String,java.lang.Object>
getMetadata()
Get the optional byte array metadata that was set on the aggregationjava.lang.String
getName()
java.lang.Object
getProperty(java.lang.String path)
Get the value of specified path in the aggregation.abstract java.lang.Object
getProperty(java.util.List<java.lang.String> path)
java.lang.String
getType()
int
hashCode()
boolean
isMapped()
Return true if this aggregation is mapped, and can lead a reduction.void
mergePipelineTreeForBWCSerialization(PipelineAggregator.PipelineTree pipelineTree)
Merge a PipelineAggregator.PipelineTree into this aggregation result tree before serializing to a node older than 7.8.0.protected abstract boolean
mustReduceOnSingleInternalAgg()
Signal the framework if the reduce(List, ReduceContext) phase needs to be called when there is only one InternalAggregation.java.util.List<PipelineAggregator>
pipelineAggregatorsForBwcSerialization()
Deprecated.only use these for serializing to older Elasticsearch versionsprotected static int
readSize(StreamInput in)
Read a size under the assumption that a value of 0 means unlimited.abstract InternalAggregation
reduce(java.util.List<InternalAggregation> aggregations, InternalAggregation.ReduceContext reduceContext)
Reduces the given aggregations to a single one and returns it.InternalAggregation
reducePipelines(InternalAggregation reducedAggs, InternalAggregation.ReduceContext reduceContext, PipelineAggregator.PipelineTree pipelinesForThisAgg)
Creates the output from all pipeline aggs that this aggregation is associated with.double
sortValue(java.lang.String key)
Get value to use when sorting by this aggregation.double
sortValue(AggregationPath.PathElement head, java.util.Iterator<AggregationPath.PathElement> tail)
Get value to use when sorting by a descendant of this aggregation.java.lang.String
toString()
org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
protected static void
writeSize(int size, StreamOutput out)
Write a size under the assumption that a value of 0 means unlimited.void
writeTo(StreamOutput out)
Write this into the StreamOutput.
-
Field Details
-
Constructor Details
-
InternalAggregation
protected InternalAggregation(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> metadata)Constructs an aggregation result with a given name.- Parameters:
name
- The name of the aggregation.
-
InternalAggregation
Read from a stream.- Throws:
java.io.IOException
-
-
Method Details
-
mergePipelineTreeForBWCSerialization
public final void mergePipelineTreeForBWCSerialization(PipelineAggregator.PipelineTree pipelineTree)Merge a PipelineAggregator.PipelineTree into this aggregation result tree before serializing to a node older than 7.8.0. -
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput. -
doWriteTo
- Throws:
java.io.IOException
-
getName
public java.lang.String getName()- Specified by:
getName
in interfaceAggregation
- Returns:
- The name of this aggregation.
-
copyWithRewritenBuckets
public InternalAggregation copyWithRewritenBuckets(java.util.function.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
rewriter
once per bucket with its InternalAggregations. Therewriter
should returnnull
if 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, InternalAggregation.ReduceContext 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(java.util.List<InternalAggregation> aggregations, InternalAggregation.ReduceContext 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:
mustReduceOnSingleInternalAgg()
-
mustReduceOnSingleInternalAgg
protected abstract boolean mustReduceOnSingleInternalAgg()Signal the framework if the reduce(List, ReduceContext) 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
public java.lang.Object getProperty(java.lang.String path)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
public abstract java.lang.Object getProperty(java.util.List<java.lang.String> path) -
readSize
Read a size under the assumption that a value of 0 means unlimited.- Throws:
java.io.IOException
-
writeSize
Write a size under the assumption that a value of 0 means unlimited.- Throws:
java.io.IOException
-
getMetadata
public java.util.Map<java.lang.String,java.lang.Object> getMetadata()Description copied from interface:Aggregation
Get the optional byte array metadata that was set on the aggregation- Specified by:
getMetadata
in interfaceAggregation
-
pipelineAggregatorsForBwcSerialization
Deprecated.only use these for serializing to older Elasticsearch versionsThe PipelineAggregators sent to older versions of Elasticsearch. -
getType
public java.lang.String getType()- Specified by:
getType
in 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.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Specified by:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
java.io.IOException
-
doXContentBody
public abstract org.elasticsearch.common.xcontent.XContentBuilder doXContentBody(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Throws:
java.io.IOException
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
sortValue
public double sortValue(java.lang.String key)Get value to use when sorting by this aggregation. -
sortValue
public double sortValue(AggregationPath.PathElement head, java.util.Iterator<AggregationPath.PathElement> tail)Get value to use when sorting by a descendant of this aggregation.
-