Class SuggestionBuilder<T extends SuggestionBuilder<T>>

All Implemented Interfaces:
NamedWriteable, Writeable, ToXContent, ToXContentFragment
Direct Known Subclasses:
CompletionSuggestionBuilder, PhraseSuggestionBuilder, TermSuggestionBuilder

public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>>
extends java.lang.Object
implements NamedWriteable, ToXContentFragment
Base class for the different suggestion implementations.
  • Field Details

  • Constructor Details

    • SuggestionBuilder

      protected SuggestionBuilder​(java.lang.String field)
      Creates a new suggestion.
      field - field to execute suggestions on
    • SuggestionBuilder

      protected SuggestionBuilder​(java.lang.String field, SuggestionBuilder<?> in)
      internal copy constructor that copies over all class fields from second SuggestionBuilder except field name.
    • SuggestionBuilder

      protected SuggestionBuilder​(StreamInput in) throws
      Read from a stream.
  • Method Details

    • writeTo

      public final void writeTo​(StreamOutput out) throws
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
    • doWriteTo

      protected abstract void doWriteTo​(StreamOutput out) throws
    • text

      public T text​(java.lang.String text)
      Same as in SuggestBuilder.setGlobalText(String), but in the suggestion scope.
    • text

      public java.lang.String text()
      get the text for this suggestion
    • prefix

      protected T prefix​(java.lang.String prefix)
    • prefix

      public java.lang.String prefix()
      get the prefix for this suggestion
    • regex

      protected T regex​(java.lang.String regex)
    • regex

      public java.lang.String regex()
      get the regex for this suggestion
    • field

      public java.lang.String field()
      get the field() parameter
    • analyzer

      public T analyzer​(java.lang.String analyzer)
      Sets the analyzer to analyse to suggest text with. Defaults to the search analyzer of the suggest field.
    • analyzer

      public java.lang.String analyzer()
      get the analyzer() parameter
    • size

      public T size​(int size)
      Sets the maximum suggestions to be returned per suggest text term.
    • size

      public java.lang.Integer size()
      get the size() parameter
    • shardSize

      public T shardSize​(java.lang.Integer shardSize)
      Sets the maximum number of suggested term to be retrieved from each individual shard. During the reduce phase the only the top N suggestions are returned based on the size option. Defaults to the size option.

      Setting this to a value higher than the `size` can be useful in order to get a more accurate document frequency for suggested terms. Due to the fact that terms are partitioned amongst shards, the shard level document frequencies of suggestions may not be precise. Increasing this will make these document frequencies more precise.

    • shardSize

      public java.lang.Integer shardSize()
      get the shardSize() parameter
    • toXContent

      public XContentBuilder toXContent​(XContentBuilder builder, ToXContent.Params params) throws
      Specified by:
      toXContent in interface ToXContent
    • innerToXContent

      protected abstract XContentBuilder innerToXContent​(XContentBuilder builder, ToXContent.Params params) throws
    • build

      protected abstract SuggestionSearchContext.SuggestionContext build​(QueryShardContext context) throws
    • populateCommonFields

      protected void populateCommonFields​(MapperService mapperService, SuggestionSearchContext.SuggestionContext suggestionContext)
      Transfers the text, prefix, regex, analyzer, field, size and shard size settings from the original SuggestionBuilder to the target SuggestionSearchContext.SuggestionContext
    • equals

      public final boolean equals​(java.lang.Object obj)
      equals in class java.lang.Object
    • doEquals

      protected abstract boolean doEquals​(T other)
      Indicates whether some other SuggestionBuilder of the same type is "equal to" this one.
    • hashCode

      public final int hashCode()
      hashCode in class java.lang.Object
    • doHashCode

      protected abstract int doHashCode()
      HashCode for the subclass of SuggestionBuilder to implement.