Class HighlightBuilder
java.lang.Object
org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder<HighlightBuilder>
org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder
- All Implemented Interfaces:
 Writeable,org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentObject,Rewriteable<HighlightBuilder>
A builder for search highlighting. Settings can control how large fields
 are summarized to show only selected snippets ("fragments") containing search terms.
- See Also:
 SearchSourceBuilder.highlight()
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classNested 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
FieldsModifier and TypeFieldDescriptionstatic Stringthe default encoder settingstatic booleandefault for whether to highlight fields based on the source even if stored separatelystatic intthe default number of fragments size in charactersstatic booleandefault for whetherfvhshould provide highlighting on filter clausesstatic Integerdefault for whether to stop highlighting at the defined max_analyzed_offset to avoid exceptions for longer textsstatic intdefault for fragment size when there are no matchesstatic intthe default number of fragments for highlightingstatic intdefault for the maximum number of phrases the fvh will considerstatic booleandefault for whether a field should be highlighted only if a query matches that fieldstatic booleandefault for highlight fragments being ordered by scorestatic String[]the default closing tags whentag_schema = "styled"static String[]the default opening tags whentag_schema = "styled"Fields inherited from class org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder
BOUNDARY_CHARS_FIELD, BOUNDARY_MAX_SCAN_FIELD, BOUNDARY_SCANNER_FIELD, BOUNDARY_SCANNER_LOCALE_FIELD, boundaryChars, boundaryMaxScan, boundaryScannerLocale, boundaryScannerType, ENCODER_FIELD, FIELDS_FIELD, FORCE_SOURCE_FIELD, forceSource, FRAGMENT_OFFSET_FIELD, FRAGMENT_SIZE_FIELD, fragmenter, FRAGMENTER_FIELD, fragmentSize, HIGHLIGHT_FILTER_FIELD, HIGHLIGHT_QUERY_FIELD, highlighterType, highlightFilter, highlightQuery, MATCHED_FIELDS_FIELD, MAX_ANALYZED_OFFSET_FIELD, maxAnalyzedOffset, NO_MATCH_SIZE_FIELD, noMatchSize, NUMBER_OF_FRAGMENTS_FIELD, numOfFragments, options, OPTIONS_FIELD, order, ORDER_FIELD, PHRASE_LIMIT_FIELD, phraseLimit, POST_TAGS_FIELD, postTags, PRE_TAGS_FIELD, preTags, REQUIRE_FIELD_MATCH_FIELD, requireFieldMatch, TYPE_FIELDFields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDSFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS - 
Constructor Summary
ConstructorsConstructorDescriptionRead from a stream.HighlightBuilder(HighlightBuilder template, QueryBuilder highlightQuery, List<HighlightBuilder.Field> fields) - 
Method Summary
Modifier and TypeMethodDescriptionbuild(SearchExecutionContext context)protected booleandoEquals(HighlightBuilder other)fields only present in subclass should be checked for equality in the implementationprotected intfields only present in subclass should contribute to hashCode in the implementationprotected voiddoWriteTo(StreamOutput out)encoder()Getter forencoder(String)Set encoder for the highlighting arehtmlanddefault.Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5 using the default encoderAdds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.field(HighlightBuilder.Field field)fields()static HighlightBuilderfromXContent(org.elasticsearch.common.xcontent.XContentParser p)voidinnerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder)rewrite(QueryRewriteContext ctx)Rewrites this instance based on the provided context.tagsSchema(String schemaName)Set a tag scheme that encapsulates a built in pre and post tags.org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)Gets value set withuseExplicitFieldOrder(boolean)useExplicitFieldOrder(boolean useExplicitFieldOrder)Send the fields to be highlighted using a syntax that is specific about the order in which they should be highlighted.Methods inherited from class org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder
boundaryChars, boundaryChars, boundaryMaxScan, boundaryMaxScan, boundaryScannerLocale, boundaryScannerLocale, boundaryScannerType, boundaryScannerType, boundaryScannerType, equals, forceSource, forceSource, fragmenter, fragmenter, fragmentSize, fragmentSize, hashCode, highlighterType, highlighterType, highlightFilter, highlightFilter, highlightQuery, highlightQuery, maxAnalyzedOffset, maxAnalyzedOffset, noMatchSize, noMatchSize, numOfFragments, numOfFragments, options, options, order, order, order, phraseLimit, phraseLimit, postTags, postTags, preTags, preTags, requireFieldMatch, requireFieldMatch, toString, writeToMethods 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
- 
DEFAULT_FORCE_SOURCE
public static final boolean DEFAULT_FORCE_SOURCEdefault for whether to highlight fields based on the source even if stored separately- See Also:
 - Constant Field Values
 
 - 
DEFAULT_REQUIRE_FIELD_MATCH
public static final boolean DEFAULT_REQUIRE_FIELD_MATCHdefault for whether a field should be highlighted only if a query matches that field- See Also:
 - Constant Field Values
 
 - 
DEFAULT_MAX_ANALYZED_OFFSET
default for whether to stop highlighting at the defined max_analyzed_offset to avoid exceptions for longer texts - 
DEFAULT_HIGHLIGHT_FILTER
public static final boolean DEFAULT_HIGHLIGHT_FILTERdefault for whetherfvhshould provide highlighting on filter clauses- See Also:
 - Constant Field Values
 
 - 
DEFAULT_SCORE_ORDERED
public static final boolean DEFAULT_SCORE_ORDEREDdefault for highlight fragments being ordered by score- See Also:
 - Constant Field Values
 
 - 
DEFAULT_ENCODER
the default encoder setting- See Also:
 - Constant Field Values
 
 - 
DEFAULT_PHRASE_LIMIT
public static final int DEFAULT_PHRASE_LIMITdefault for the maximum number of phrases the fvh will consider- See Also:
 - Constant Field Values
 
 - 
DEFAULT_NO_MATCH_SIZE
public static final int DEFAULT_NO_MATCH_SIZEdefault for fragment size when there are no matches- See Also:
 - Constant Field Values
 
 - 
DEFAULT_NUMBER_OF_FRAGMENTS
public static final int DEFAULT_NUMBER_OF_FRAGMENTSthe default number of fragments for highlighting- See Also:
 - Constant Field Values
 
 - 
DEFAULT_FRAGMENT_CHAR_SIZE
public static final int DEFAULT_FRAGMENT_CHAR_SIZEthe default number of fragments size in characters- See Also:
 - Constant Field Values
 
 - 
DEFAULT_STYLED_PRE_TAG
the default opening tags whentag_schema = "styled" - 
DEFAULT_STYLED_POST_TAGS
the default closing tags whentag_schema = "styled" 
 - 
 - 
Constructor Details
- 
HighlightBuilder
public HighlightBuilder() - 
HighlightBuilder
public HighlightBuilder(HighlightBuilder template, QueryBuilder highlightQuery, List<HighlightBuilder.Field> fields) - 
HighlightBuilder
Read from a stream.- Throws:
 IOException
 
 - 
 - 
Method Details
- 
doWriteTo
- Specified by:
 doWriteToin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
 IOException
 - 
field
Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5 using the default encoder- Parameters:
 name- The field to highlight
 - 
field
Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.- Parameters:
 name- The field to highlightfragmentSize- The size of a fragment in characters
 - 
field
Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.- Parameters:
 name- The field to highlightfragmentSize- The size of a fragment in charactersnumberOfFragments- The (maximum) number of fragments
 - 
field
public HighlightBuilder field(String name, int fragmentSize, int numberOfFragments, int fragmentOffset)Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.- Parameters:
 name- The field to highlightfragmentSize- The size of a fragment in charactersnumberOfFragments- The (maximum) number of fragmentsfragmentOffset- The offset from the start of the fragment to the start of the highlight
 - 
field
 - 
fields
 - 
tagsSchema
Set a tag scheme that encapsulates a built in pre and post tags. The allowed schemes arestyledanddefault.- Parameters:
 schemaName- The tag scheme name
 - 
encoder
Set encoder for the highlighting arehtmlanddefault.- Parameters:
 encoder- name
 - 
encoder
Getter forencoder(String) - 
useExplicitFieldOrder
Send the fields to be highlighted using a syntax that is specific about the order in which they should be highlighted.- Returns:
 - this for chaining
 
 - 
useExplicitFieldOrder
Gets value set withuseExplicitFieldOrder(boolean) - 
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException- Specified by:
 toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Overrides:
 toXContentin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
 IOException
 - 
fromXContent
 - 
build
- Throws:
 IOException
 - 
innerXContent
public void innerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder) throws IOException- Specified by:
 innerXContentin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
 IOException
 - 
doHashCode
protected int doHashCode()Description copied from class:AbstractHighlighterBuilderfields only present in subclass should contribute to hashCode in the implementation- Specified by:
 doHashCodein classAbstractHighlighterBuilder<HighlightBuilder>
 - 
doEquals
Description copied from class:AbstractHighlighterBuilderfields only present in subclass should be checked for equality in the implementation- Specified by:
 doEqualsin classAbstractHighlighterBuilder<HighlightBuilder>
 - 
rewrite
Description copied from interface:RewriteableRewrites this instance based on the provided context. The returned objects will be the same instance as this if no changes during the rewrite were applied.- Throws:
 IOException
 
 -