Class TopHitsAggregationBuilder
- java.lang.Object
-
- org.elasticsearch.search.aggregations.AggregationBuilder
-
- org.elasticsearch.search.aggregations.AbstractAggregationBuilder<TopHitsAggregationBuilder>
-
- org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentFragment
,BaseAggregationBuilder
public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHitsAggregationBuilder>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.AggregationBuilder
AggregationBuilder.CommonFields
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, 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 static java.lang.String
NAME
-
Fields inherited from class org.elasticsearch.search.aggregations.AbstractAggregationBuilder
metaData
-
Fields inherited from class org.elasticsearch.search.aggregations.AggregationBuilder
factoriesBuilder, name
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Modifier Constructor Description TopHitsAggregationBuilder(java.lang.String name)
TopHitsAggregationBuilder(StreamInput in)
Read from a stream.protected
TopHitsAggregationBuilder(TopHitsAggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder, java.util.Map<java.lang.String,java.lang.Object> metaData)
-
Method Summary
Modifier and Type Method Description protected TopHitsAggregatorFactory
doBuild(SearchContext context, AggregatorFactory<?> parent, AggregatorFactories.Builder subfactoriesBuilder)
TopHitsAggregationBuilder
docValueField(java.lang.String docValueField)
Adds a field to load from doc values and return as part of the search request.TopHitsAggregationBuilder
docValueField(java.lang.String docValueField, java.lang.String format)
Adds a field to load from doc values and return as part of the search request.protected boolean
doEquals(java.lang.Object obj)
protected int
doHashCode()
protected void
doWriteTo(StreamOutput out)
boolean
explain()
Indicates whether each search hit will be returned with an explanation of the hit (ranking)TopHitsAggregationBuilder
explain(boolean explain)
Should eachSearchHit
be returned with an explanation of the hit (ranking).FetchSourceContext
fetchSource()
Gets theFetchSourceContext
which defines how the _source should be fetched.TopHitsAggregationBuilder
fetchSource(boolean fetch)
Indicates whether the response should contain the stored _source for every hitTopHitsAggregationBuilder
fetchSource(java.lang.String[] includes, java.lang.String[] excludes)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.TopHitsAggregationBuilder
fetchSource(java.lang.String include, java.lang.String exclude)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.TopHitsAggregationBuilder
fetchSource(FetchSourceContext fetchSourceContext)
Indicate how the _source should be fetched.java.util.List<DocValueFieldsContext.FieldAndFormat>
fieldDataFields()
Gets the field-data fields.int
from()
Gets the from index to start the search from.TopHitsAggregationBuilder
from(int from)
From index to start the search from.java.lang.String
getType()
The name of the type of aggregation built by this builder.HighlightBuilder
highlighter()
Gets the highlighter builder for this request.TopHitsAggregationBuilder
highlighter(HighlightBuilder highlightBuilder)
Adds highlight to perform as part of the search.protected XContentBuilder
internalXContent(XContentBuilder builder, ToXContent.Params params)
static TopHitsAggregationBuilder
parse(java.lang.String aggregationName, XContentParser parser)
TopHitsAggregationBuilder
scriptField(java.lang.String name, Script script)
Adds a script field under the given name with the provided script.TopHitsAggregationBuilder
scriptField(java.lang.String name, Script script, boolean ignoreFailure)
Adds a script field under the given name with the provided script.java.util.Set<SearchSourceBuilder.ScriptField>
scriptFields()
Gets the script fields.TopHitsAggregationBuilder
scriptFields(java.util.List<SearchSourceBuilder.ScriptField> scriptFields)
java.lang.Boolean
seqNoAndPrimaryTerm()
Indicates whetherSearchHit
s should be returned with the sequence number and primary term of the last modification of the document.TopHitsAggregationBuilder
seqNoAndPrimaryTerm(java.lang.Boolean seqNoAndPrimaryTerm)
Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document.protected AggregationBuilder
shallowCopy(AggregatorFactories.Builder factoriesBuilder, java.util.Map<java.lang.String,java.lang.Object> metaData)
Create a shallow copy of this builder and replacingAggregationBuilder.factoriesBuilder
andmetaData
.int
size()
Gets the number of search hits to return.TopHitsAggregationBuilder
size(int size)
The number of search hits to return.TopHitsAggregationBuilder
sort(java.lang.String name)
Add a sort against the given field name.TopHitsAggregationBuilder
sort(java.lang.String name, SortOrder order)
Adds a sort against the given field name and the sort ordering.TopHitsAggregationBuilder
sort(SortBuilder<?> sort)
Adds a sort builder.java.util.List<SortBuilder<?>>
sorts()
Gets the bytes representing the sort builders for this request.TopHitsAggregationBuilder
sorts(java.util.List<SortBuilder<?>> sorts)
Adds a sort builder.TopHitsAggregationBuilder
storedField(java.lang.String field)
Adds a stored field to load and return (note, it must be stored) as part of the search request.StoredFieldsContext
storedFields()
Gets the stored fields contextTopHitsAggregationBuilder
storedFields(java.util.List<java.lang.String> fields)
Sets the stored fields to load and return as part of the search request.TopHitsAggregationBuilder
subAggregations(AggregatorFactories.Builder subFactories)
Registers sub-factories with this factory.boolean
trackScores()
Indicates whether scores will be tracked for this request.TopHitsAggregationBuilder
trackScores(boolean trackScores)
Applies when sorting, and controls if scores will be tracked as well.boolean
version()
Indicates whether the document's version will be included in the search hits.TopHitsAggregationBuilder
version(boolean version)
Should eachSearchHit
be returned with a version associated with it.-
Methods inherited from class org.elasticsearch.search.aggregations.AbstractAggregationBuilder
build, equals, getMetaData, getWriteableName, hashCode, setMetaData, subAggregation, subAggregation, toXContent, writeTo
-
Methods inherited from class org.elasticsearch.search.aggregations.AggregationBuilder
doRewrite, getName, getPipelineAggregations, getSubAggregations, rewrite, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TopHitsAggregationBuilder
public TopHitsAggregationBuilder(java.lang.String name)
-
TopHitsAggregationBuilder
protected TopHitsAggregationBuilder(TopHitsAggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder, java.util.Map<java.lang.String,java.lang.Object> metaData)
-
TopHitsAggregationBuilder
public TopHitsAggregationBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
shallowCopy
protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBuilder, java.util.Map<java.lang.String,java.lang.Object> metaData)
Description copied from class:AggregationBuilder
Create a shallow copy of this builder and replacingAggregationBuilder.factoriesBuilder
andmetaData
. Used byAggregationBuilder.rewrite(QueryRewriteContext)
.- Specified by:
shallowCopy
in classAggregationBuilder
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteTo
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
- Throws:
java.io.IOException
-
from
public TopHitsAggregationBuilder from(int from)
From index to start the search from. Defaults to0
.
-
from
public int from()
Gets the from index to start the search from.
-
size
public TopHitsAggregationBuilder size(int size)
The number of search hits to return. Defaults to10
.
-
size
public int size()
Gets the number of search hits to return.
-
sort
public TopHitsAggregationBuilder sort(java.lang.String name, SortOrder order)
Adds a sort against the given field name and the sort ordering.- Parameters:
name
- The name of the fieldorder
- The sort ordering
-
sort
public TopHitsAggregationBuilder sort(java.lang.String name)
Add a sort against the given field name.- Parameters:
name
- The name of the field to sort by
-
sort
public TopHitsAggregationBuilder sort(SortBuilder<?> sort)
Adds a sort builder.
-
sorts
public TopHitsAggregationBuilder sorts(java.util.List<SortBuilder<?>> sorts)
Adds a sort builder.
-
sorts
public java.util.List<SortBuilder<?>> sorts()
Gets the bytes representing the sort builders for this request.
-
highlighter
public TopHitsAggregationBuilder highlighter(HighlightBuilder highlightBuilder)
Adds highlight to perform as part of the search.
-
highlighter
public HighlightBuilder highlighter()
Gets the highlighter builder for this request.
-
fetchSource
public TopHitsAggregationBuilder fetchSource(boolean fetch)
Indicates whether the response should contain the stored _source for every hit
-
fetchSource
public TopHitsAggregationBuilder fetchSource(@Nullable java.lang.String include, @Nullable java.lang.String exclude)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.- Parameters:
include
- An optional include (optionally wildcarded) pattern to filter the returned _sourceexclude
- An optional exclude (optionally wildcarded) pattern to filter the returned _source
-
fetchSource
public TopHitsAggregationBuilder fetchSource(@Nullable java.lang.String[] includes, @Nullable java.lang.String[] excludes)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.- Parameters:
includes
- An optional list of include (optionally wildcarded) pattern to filter the returned _sourceexcludes
- An optional list of exclude (optionally wildcarded) pattern to filter the returned _source
-
fetchSource
public TopHitsAggregationBuilder fetchSource(@Nullable FetchSourceContext fetchSourceContext)
Indicate how the _source should be fetched.
-
fetchSource
public FetchSourceContext fetchSource()
Gets theFetchSourceContext
which defines how the _source should be fetched.
-
storedField
public TopHitsAggregationBuilder storedField(java.lang.String field)
Adds a stored field to load and return (note, it must be stored) as part of the search request. To disable the stored fields entirely (source and metadata fields) usestoredField("_none_")
.
-
storedFields
public TopHitsAggregationBuilder storedFields(java.util.List<java.lang.String> fields)
Sets the stored fields to load and return as part of the search request. To disable the stored fields entirely (source and metadata fields) usestoredField("_none_")
.
-
storedFields
public StoredFieldsContext storedFields()
Gets the stored fields context
-
docValueField
public TopHitsAggregationBuilder docValueField(java.lang.String docValueField, java.lang.String format)
Adds a field to load from doc values and return as part of the search request.
-
docValueField
public TopHitsAggregationBuilder docValueField(java.lang.String docValueField)
Adds a field to load from doc values and return as part of the search request.
-
fieldDataFields
public java.util.List<DocValueFieldsContext.FieldAndFormat> fieldDataFields()
Gets the field-data fields.
-
scriptField
public TopHitsAggregationBuilder scriptField(java.lang.String name, Script script)
Adds a script field under the given name with the provided script.- Parameters:
name
- The name of the fieldscript
- The script
-
scriptField
public TopHitsAggregationBuilder scriptField(java.lang.String name, Script script, boolean ignoreFailure)
Adds a script field under the given name with the provided script.- Parameters:
name
- The name of the fieldscript
- The script
-
scriptFields
public TopHitsAggregationBuilder scriptFields(java.util.List<SearchSourceBuilder.ScriptField> scriptFields)
-
scriptFields
public java.util.Set<SearchSourceBuilder.ScriptField> scriptFields()
Gets the script fields.
-
explain
public TopHitsAggregationBuilder explain(boolean explain)
Should eachSearchHit
be returned with an explanation of the hit (ranking).
-
explain
public boolean explain()
Indicates whether each search hit will be returned with an explanation of the hit (ranking)
-
version
public TopHitsAggregationBuilder version(boolean version)
Should eachSearchHit
be returned with a version associated with it.
-
version
public boolean version()
Indicates whether the document's version will be included in the search hits.
-
seqNoAndPrimaryTerm
public TopHitsAggregationBuilder seqNoAndPrimaryTerm(java.lang.Boolean seqNoAndPrimaryTerm)
Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document.
-
seqNoAndPrimaryTerm
public java.lang.Boolean seqNoAndPrimaryTerm()
Indicates whetherSearchHit
s should be returned with the sequence number and primary term of the last modification of the document.
-
trackScores
public TopHitsAggregationBuilder trackScores(boolean trackScores)
Applies when sorting, and controls if scores will be tracked as well. Defaults tofalse
.
-
trackScores
public boolean trackScores()
Indicates whether scores will be tracked for this request.
-
subAggregations
public TopHitsAggregationBuilder subAggregations(AggregatorFactories.Builder subFactories)
Description copied from class:AbstractAggregationBuilder
Registers sub-factories with this factory. The sub-factory will be responsible for the creation of sub-aggregators under the aggregator created by this factory.- Specified by:
subAggregations
in interfaceBaseAggregationBuilder
- Overrides:
subAggregations
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
- Parameters:
subFactories
- The sub-factories- Returns:
- this factory (fluent interface)
-
doBuild
protected TopHitsAggregatorFactory doBuild(SearchContext context, AggregatorFactory<?> parent, AggregatorFactories.Builder subfactoriesBuilder) throws java.io.IOException
- Specified by:
doBuild
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
- Throws:
java.io.IOException
-
internalXContent
protected XContentBuilder internalXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
internalXContent
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
- Throws:
java.io.IOException
-
parse
public static TopHitsAggregationBuilder parse(java.lang.String aggregationName, XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCode
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
-
doEquals
protected boolean doEquals(java.lang.Object obj)
- Specified by:
doEquals
in classAbstractAggregationBuilder<TopHitsAggregationBuilder>
-
getType
public java.lang.String getType()
Description copied from interface:BaseAggregationBuilder
The name of the type of aggregation built by this builder.
-
-