Search result summaries
Document content is often long and cannot be displayed in full in search results. In this case, you need to configure summaries and highlighting. The system extracts several snippets that contain the matched content so that users can see what was matched and quickly determine whether a result is what they want. You can customize how search results are displayed in the console. After the configuration is complete, the system automatically retrieves your configuration and adds it to the query when you call the API. You do not need to pass it again. You can also control specific queries by using the summary parameter in the API request.
Main parameters
-
Field: the field for which you want to configure a summary.
-
Snippet Length: the maximum length of the entire summary.
-
Highlight Tag: the HTML tag used to highlight keywords.
-
Snippet Connector: the connector between snippets.
-
Number of Snippets: the number of snippets required within the summary length.
Configure summaries in the console
1. In the console, choose Feature Extensions > Search Result Display and configure search result summaries.

2. The following example shows the highlight tag configuration. The highlight tag is em.
In the example, a summary is configured for the title field. The snippet length is 50, the highlight tag is em, the snippet connector is …, and the number of snippets is 5.
Configure summaries by using SDKs or the API
-
In the API parameters, specify the configuration by using the summary parameter.
-
SDK configuration: The following demo uses the Java SDK as an example:
// Configure search result summaries. Adding the summary by using the following SearchParams object is relatively simple. Summary summ = new Summary("name"); summ.setSummary_field("name");// The field to which the summary applies. This field must be of the TEXT type and support tokenization. summ.setSummary_len("50");// Snippet length summ.setSummary_element("em"); // Highlight tag summ.setSummary_ellipsis("...");// Snippet connector summ.setSummary_snippet("1");// Number of snippets // Add the Summary object parameterTips:
-
You cannot specify the highlight prefix and suffix (which must be complete HTML tags) in the summary object parameter of the SearchParams class in the SDK. The default prefix and suffix are <>. For example, if you set the highlight tag to em, the returned JSON result after highlighting is in the following format: Alibaba Cloud <em>OpenSearch</em> product documentation.
-
To specify the highlight prefix and suffix in the SDK, use the searchParamsBuilder object.
// A utility class for SearchParams that provides more convenient operations SearchParamsBuilder paramsBuilder = SearchParamsBuilder.create(searchParams); // Use the SearchParamsBuilder object to add search result summaries paramsBuilder.addCustomParam("summary", "summary_field:name,summary_ellipsis:...,summary_snipped:1,summary_len:50,summary_element_prefix:<abc>,summary_element_postfix:</abc>"); // Separate multiple summary_field entries with semicolonsUsage notes
-
Only the search terms in the query are highlighted, and the highlighted fields must be indexed. Otherwise, the content is displayed abnormally.
-
Summaries and highlighting cannot be configured separately.
-
If you configure multiple summary fields and the values of these fields contain tokens of the search keywords specified for the index, the corresponding tokens in all of these summary fields are included in summaries and highlighted.
-
If a matched term appears late in the content and exceeds the maximum limit of 10,000 bytes, it is not highlighted.
-
By default, highlighting escapes both < and > in HTML to < and >.
-
If you create indexes of different analyzer types for the same field in an application, for example, both a Chinese basic analyzer index and a Chinese single-character analyzer index, summary highlighting for the Chinese single-character analyzer may not work correctly. The highlighted summary content matches only the Chinese basic analyzer, or incorrect content is highlighted.
-
If a single query uses indexes of two or more different analyzer types for retrieval, content may not be highlighted or may be highlighted abnormally.
-
If a highlighted snippet contains special characters, the special characters are filtered out of the returned documents. To display special characters, you can set the custom clause kvpairs=filter_punc:0 to skip special character filtering.
Example of summary highlighting
After you search for the keyword friendship, a summary snippet is displayed below each record in the search result list, and the matched keywords in the summary are highlighted. Each result contains fields such as the title, source, author, category, status, word count, and rating, and provides a Start Reading button. The top of the page also supports filtering by category, word count, and status, and sorting by dimensions such as update time, number of ratings, and number of subscriptions.