Package org.elasticsearch.search.suggest
Class SuggestBuilder
java.lang.Object
org.elasticsearch.search.suggest.SuggestBuilder
- All Implemented Interfaces:
Writeable,org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentObject
public class SuggestBuilder extends java.lang.Object implements Writeable, org.elasticsearch.common.xcontent.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.
-
Nested Class Summary
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.ParamsNested 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 static org.elasticsearch.common.ParseFieldGLOBAL_TEXT_FIELDFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
Constructors Constructor Description SuggestBuilder()Build an empty SuggestBuilder.SuggestBuilder(StreamInput in)Read from a stream. -
Method Summary
Modifier and Type Method Description SuggestBuilderaddSuggestion(java.lang.String name, SuggestionBuilder<?> suggestion)Adds anSuggestionBuilderinstance under a user defined name.SuggestionSearchContextbuild(SearchExecutionContext context)booleanequals(java.lang.Object other)static SuggestBuilderfromXContent(org.elasticsearch.common.xcontent.XContentParser parser)java.lang.StringgetGlobalText()Gets the global suggest textjava.util.Map<java.lang.String,SuggestionBuilder<?>>getSuggestions()Get all theSuggestionsthat were added to the globalSuggestBuilder, together with their namesinthashCode()SuggestBuildersetGlobalText(java.lang.String globalText)Sets the text to provide suggestions for.java.lang.StringtoString()org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)voidwriteTo(StreamOutput out)Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Field Details
-
GLOBAL_TEXT_FIELD
protected static final org.elasticsearch.common.ParseField GLOBAL_TEXT_FIELD
-
-
Constructor Details
-
SuggestBuilder
public SuggestBuilder()Build an empty SuggestBuilder. -
SuggestBuilder
Read from a stream.- Throws:
java.io.IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput. -
setGlobalText
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 theSuggestionBuilder.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
Adds anSuggestionBuilderinstance under a user defined name. The order in which theSuggestionsare added, is the same as in the response.- Throws:
java.lang.IllegalArgumentException- if two suggestions added have the same name
-
getSuggestions
Get all theSuggestionsthat were added to the globalSuggestBuilder, together with their names -
toXContent
public 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:
toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Throws:
java.io.IOException
-
fromXContent
public static SuggestBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException- Throws:
java.io.IOException
-
build
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-