Class TopHitsAggregationBuilder

All Implemented Interfaces:
NamedWriteable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentFragment, Rewriteable<AggregationBuilder>, BaseAggregationBuilder

public class TopHitsAggregationBuilder
extends AbstractAggregationBuilder<TopHitsAggregationBuilder>
  • Field Details

  • Constructor Details

    • 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 Details

    • 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 replacing AggregationBuilder.factoriesBuilder and metadata. Used by AggregationBuilder.rewrite(QueryRewriteContext).
      Specified by:
      shallowCopy in class AggregationBuilder
    • doWriteTo

      protected void doWriteTo​(StreamOutput out) throws java.io.IOException
      Specified by:
      doWriteTo in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
      Throws:
      java.io.IOException
    • from

      public TopHitsAggregationBuilder from​(int from)
      From index to start the search from. Defaults to 0.
    • 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 to 10.
    • 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 field
      order - 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 _source
      exclude - 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 _source
      excludes - 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 the FetchSourceContext 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) use storedField("_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) use storedField("_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.
    • docValueFields

      public java.util.List<FieldAndFormat> docValueFields()
      Gets the field-data fields.
    • fetchField

      public TopHitsAggregationBuilder fetchField​(FieldAndFormat fieldAndFormat)
      Adds a field to load and return as part of the search request.
    • fetchField

      public TopHitsAggregationBuilder fetchField​(java.lang.String field)
      Adds a field to load and return as part of the search request.
    • fetchFields

      public java.util.List<FieldAndFormat> fetchFields()
      Gets the fields to load and return as part of the search request.
    • 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 field
      script - 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 field
      script - 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 each SearchHit 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 each SearchHit 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 each SearchHit be returned with the sequence number and primary term of the last modification of the document.
    • seqNoAndPrimaryTerm

      public java.lang.Boolean seqNoAndPrimaryTerm()
      Indicates whether SearchHits 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 to false.
    • 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 interface BaseAggregationBuilder
      Overrides:
      subAggregations in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
      Parameters:
      subFactories - The sub-factories
      Returns:
      this factory (fluent interface)
    • bucketCardinality

      public AggregationBuilder.BucketCardinality bucketCardinality()
      Description copied from class: AggregationBuilder
      A rough count of the number of buckets that Aggregators built by this builder will contain per owning parent bucket.
      Specified by:
      bucketCardinality in class AggregationBuilder
    • doBuild

      protected org.elasticsearch.search.aggregations.metrics.TopHitsAggregatorFactory doBuild​(AggregationContext context, AggregatorFactory parent, AggregatorFactories.Builder subfactoriesBuilder) throws java.io.IOException
      Specified by:
      doBuild in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
      Throws:
      java.io.IOException
    • internalXContent

      protected org.elasticsearch.common.xcontent.XContentBuilder internalXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException
      Specified by:
      internalXContent in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
      Throws:
      java.io.IOException
    • parse

      public static TopHitsAggregationBuilder parse​(java.lang.String aggregationName, org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException
      Throws:
      java.io.IOException
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractAggregationBuilder<TopHitsAggregationBuilder>
    • getType

      public java.lang.String getType()
      Description copied from interface: BaseAggregationBuilder
      The name of the type of aggregation built by this builder.