Class SuggestBuilder

  • All Implemented Interfaces:
    Writeable, ToXContent, ToXContentObject

    public class SuggestBuilder
    extends java.lang.Object
    implements Writeable, ToXContentObject
    Defines how to perform suggesting. This builders allows a number of global options to be specified and an arbitrary number of SuggestionBuilder instances.

    Suggesting works by suggesting terms/phrases that appear in the suggest text that are similar compared to the terms in provided text. These suggestions are based on several options described in this class.

    • Field Detail

      • GLOBAL_TEXT_FIELD

        protected static final ParseField GLOBAL_TEXT_FIELD
    • Constructor Detail

      • SuggestBuilder

        public SuggestBuilder()
        Build an empty SuggestBuilder.
      • SuggestBuilder

        public SuggestBuilder​(StreamInput in)
                       throws java.io.IOException
        Read from a stream.
        Throws:
        java.io.IOException
    • Method Detail

      • setGlobalText

        public SuggestBuilder setGlobalText​(@Nullable
                                            java.lang.String globalText)
        Sets the text to provide suggestions for. The suggest text is a required option that needs to be set either via this setter or via the SuggestionBuilder.text(String) method.

        The suggest text gets analyzed by the suggest analyzer or the suggest field search analyzer. For each analyzed token, suggested terms are suggested if possible.

      • getGlobalText

        @Nullable
        public java.lang.String getGlobalText()
        Gets the global suggest text
      • addSuggestion

        public SuggestBuilder addSuggestion​(java.lang.String name,
                                            SuggestionBuilder<?> suggestion)
        Adds an SuggestionBuilder instance under a user defined name. The order in which the Suggestions are added, is the same as in the response.
        Throws:
        java.lang.IllegalArgumentException - if two suggestions added have the same name
      • getSuggestions

        public java.util.Map<java.lang.String,​SuggestionBuilder<?>> getSuggestions()
        Get all the Suggestions that were added to the global SuggestBuilder, together with their names
      • fromXContent

        public static SuggestBuilder fromXContent​(XContentParser parser)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object