Package org.elasticsearch.search.suggest
Class SuggestBuilder
- java.lang.Object
-
- org.elasticsearch.search.suggest.SuggestBuilder
-
- All Implemented Interfaces:
Writeable,ToXContent,ToXContentObject
public class SuggestBuilder extends Object implements Writeable, ToXContentObject
Defines how to perform suggesting. This builders allows a number of global options to be specified and an arbitrary number ofSuggestionBuilderinstances.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
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 protected static ParseFieldGLOBAL_TEXT_FIELD-
Fields 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SuggestBuilderaddSuggestion(String name, SuggestionBuilder<?> suggestion)Adds anSuggestionBuilderinstance under a user defined name.SuggestionSearchContextbuild(QueryShardContext context)booleanequals(Object other)static SuggestBuilderfromXContent(XContentParser parser)StringgetGlobalText()Gets the global suggest textMap<String,SuggestionBuilder<?>>getSuggestions()Get all theSuggestionsthat were added to the globalSuggestBuilder, together with their namesinthashCode()SuggestBuildersetGlobalText(String globalText)Sets the text to provide suggestions for.StringtoString()XContentBuildertoXContent(XContentBuilder builder, 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, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
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 IOException
Read from a stream.- Throws:
IOException
-
-
Method Detail
-
writeTo
public void writeTo(StreamOutput out) throws IOException
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
setGlobalText
public SuggestBuilder setGlobalText(@Nullable 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 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.
-
addSuggestion
public SuggestBuilder addSuggestion(String name, SuggestionBuilder<?> suggestion)
Adds anSuggestionBuilderinstance under a user defined name. The order in which theSuggestionsare added, is the same as in the response.- Throws:
IllegalArgumentException- if two suggestions added have the same name
-
getSuggestions
public Map<String,SuggestionBuilder<?>> getSuggestions()
Get all theSuggestionsthat were added to the globalSuggestBuilder, together with their names
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
fromXContent
public static SuggestBuilder fromXContent(XContentParser parser) throws IOException
- Throws:
IOException
-
build
public SuggestionSearchContext build(QueryShardContext context) throws IOException
- Throws:
IOException
-
-