All Products
Search
Document Center

Tablestore:Summary and highlighting

Last Updated:Aug 11, 2026

Use the Tablestore SDK for Go to return text fragments from a Text field and mark matched terms.

Prerequisites

Before you begin, complete the following preparations:

Description

Summary and highlighting extracts fragments from a matched Text field and marks matched terms with configured tags. The Tablestore SDK for Go supports highlighting for term, terms, prefix, wildcard, range, Boolean, constant score, match, match phrase, and nested queries (by using InnerHits).

Important
  • If you use MatchQuery or MatchPhraseQuery, a matched term may be enclosed by multiple pairs of pre-tags and post-tags.

  • If maximum semantic tokenization is used for a Text field, MatchPhraseQuery does not support summary and highlighting.

  • A fragment boundary may split a matched term. In this case, the term is not highlighted.

highlight := search.NewHighlight().
    AddFieldHighlightParameter(
        "title",
        search.NewHighlightParameter().
            SetNumberOfFragments(3).
            SetPreTag("<em>").
            SetPostTag("</em>"),
    )

searchQuery := search.NewSearchQuery().
    SetQuery(&search.MatchQuery{FieldName: "title", Text: "go search"}).
    SetHighlight(highlight)

response, err := client.Search(&tablestore.SearchRequest{
    TableName:   "example_table",
    IndexName:   "example_index",
    SearchQuery: searchQuery,
})
if err != nil {
    log.Fatal(err)
}

for _, hit := range response.SearchHits {
    fmt.Println(hit.HighlightResultItem)
}

Parameters

Highlight configuration

Name

Type

Description

FieldHighlightParameters (required)

map[string]*search.HighlightParameter

A mapping between field names and highlight parameters. A field must have summary and highlighting enabled and be used in a supported query condition. Otherwise, no highlighted fragments are returned for the field.

HighlightEncoder (optional)

*search.HighlightEncoder

The encoding method for the original fragment text. Valid values:

  • PlainMode: returns the original text. This is the default value.

  • HtmlMode: escapes HTML special characters and is suitable for direct webpage rendering. The following characters are escaped:

    • < as &lt;.

    • > as &gt;.

    • " as &quot;.

    • ' as &#x27;.

    • / as &#x2F;.

Field highlight parameters

Name

Type

Description

NumberOfFragments (optional)

*int32

The maximum number of fragments to return. Recommended value: 1.

FragmentSize (optional)

*int32

The target length of each fragment. Default value: 100. The actual fragment length may differ.

PreTag (optional)

*string

The tag inserted before a matched term. Default value: <em>. The tag supports < > " ' /, letters, and digits.

PostTag (optional)

*string

The tag inserted after a matched term. Default value: </em>. The tag supports < > " ' /, letters, and digits.

HighlightFragmentOrder (optional)

*search.HighlightFragmentOrder

The fragment sort order. TextSequence sorts fragments by their positions in the source text and is the default. Score sorts fragments by match score.

Response

After highlighting is configured, read field fragments from SearchResponse.SearchHits[].HighlightResultItem.HighlightFields. For a nested query, read highlighting results from the hits in SearchInnerHits.