All Products
Search
Document Center

OpenSearch:Search result summary

Last Updated:Jun 20, 2026

Documents are often long and cannot be displayed in full in search results. To address this, you can configure search result summaries and highlighting. The system extracts segments that contain the query terms, helping users quickly determine if a result is relevant. You can customize how search results are displayed in the console. Once configured in the console, these settings are automatically applied to your API search queries and do not need to be specified in each request. You can also override these settings for a specific query by using the summary parameter in your API request. For more information, see Initiate search requests.

Parameters

  • Field: The field for which to generate a search result summary.

  • Segment length: The maximum length of the entire search result summary.

  • Highlight tag: The HTML tag used to highlight query terms.

  • Segment connector: The character or string used to join segments.

  • Number of segments: The number of segments to display within the specified summary length.

Configure in the console

1. In the console, navigate to OpenSearch High-performance Search Edition > Feature Extensions > Search Result Display, and configure the settings in the Search Result Summary section.

2. The following example shows the configuration for highlighting. The highlight tag is set to em.

In the Search Result Summary section of the console, the segment length for the title field is set to 50, the highlight tag is set to em, the segment connector is set to ..., and the number of segments is set to 5.

API and SDK configuration

  • API: Specify the summary parameter in your request. For more information, see Initiate search requests.

  • SDK: The following example shows how to configure the search result summary by using the Java SDK:

    // Configure the search result summary. The SearchParams object provides a simple way to do this.
        Summary summ = new Summary("name");
        summ.setSummary_field("name");// The field to which the summary applies. This must be an analyzable text field.
        summ.setSummary_len("50");// The segment length.
        summ.setSummary_element("em"); // The highlight tag.
        summ.setSummary_ellipsis("...");// The segment connector.
        summ.setSummary_snippet("1");// The number of segments.
        

    Note:

  • When using the summary object of the SearchParams class, you cannot specify custom prefixes or postfixes for the highlight tag. You must use a complete HTML tag name. The prefix and postfix default to < and >, respectively. For example, if you set the highlight tag to em, the returned JSON result is formatted as Alibaba Cloud<em>OpenSearch</em>product document.

  • To set a custom prefix and postfix for the highlight tag in the SDK, use the searchParamsBuilder object.

    // A utility class for SearchParams that simplifies operations.
          SearchParamsBuilder paramsBuilder = SearchParamsBuilder.create(searchParams);
          // Use the SearchParamsBuilder object to add the search result summary.
    paramsBuilder.addCustomParam("summary", "summary_field:name,summary_ellipsis:...,summary_snipped:1,summary_len:50,summary_element_prefix:<abc>,summary_element_postfix:</abc>");
         // To specify multiple summary_field values, separate them with semicolons (;).

    Usage notes

  • Highlighting applies only to the terms in your query. The field to be highlighted must be indexed. Otherwise, highlighting may not work correctly.

  • You cannot configure summaries and highlighting separately.

  • If you configure summaries for multiple fields, matching query terms are highlighted in all specified fields.

  • If a matching term appears far into the content, beyond the 10,000-byte limit, it will not be highlighted.

  • If you create different analyzer types for the same field, such as a standard Chinese analyzer and a single-character analyzer, highlighting may not work correctly. For example, content might be highlighted based on only one analyzer, or incorrect content might be highlighted.

  • Highlighting may not work correctly if a query uses multiple analyzers.

  • By default, special characters in highlighted segments are filtered from the returned document. To display these characters, add the custom clause kvpairs=filter_punc:0 to your query to disable this filtering.