{
  "id": "highlight",
  "title": "Highlighting",
  "url": "https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/highlight/",
  "summary": "Highlighting full-text results",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "a992ae084c1282d64f317ec50a1edc04124b6b39f2046434ed39645d49da1f5d",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Redis Open Source uses advanced algorithms for highlighting and summarizing, which enable only the relevant portions of a document to appear in response to a search query. This feature allows users to immediately understand the relevance of a document to their search criteria, typically highlighting the matching terms in bold text."
    },
    {
      "id": "command-syntax",
      "title": "Command syntax",
      "role": "syntax",
      "text": "[code example]\n\nThere are two sub-commands used for highlighting. The first is `HIGHLIGHT`, which surrounds matching text with an open and/or close tag. The second is `SUMMARIZE`, which splits a field into contextual fragments surrounding the found terms. It is possible to summarize a field, highlight a field, or perform both actions in the same query."
    },
    {
      "id": "summarization",
      "title": "Summarization",
      "role": "content",
      "text": "[code example]\n\nSummarization will fragment the text into smaller sized snippets, each of which containing the found term(s) and some additional surrounding context.\n\nRedis can perform summarization using the `SUMMARIZE` keyword. If no additional arguments are passed, all returned fields are summarized using built-in defaults.\n\nThe `SUMMARIZE` keyword accepts the following arguments:\n\n* **`FIELDS`**: If present, it must be the first argument. This should be followed\n    by the number of fields to summarize, which itself is followed by a list of\n    fields. Each field is summarized. If no `FIELDS` directive is passed,\n    then all returned fields are summarized.\n\n* **`FRAGS`**: The number of fragments to be returned. If not specified, a default is 3.\n\n* **`LEN`**: The number of context words each fragment should contain. Context\n    words surround the found term. A higher value will return a larger block of\n    text. If not specified, the default value is 20.\n\n* **`SEPARATOR`**: The string used to divide individual summary snippets.\n    The default is `... ` which is common among search engines, but you may\n    override this with any other string if you desire to programmatically divide the snippets\n    later on. You may also use a newline sequence, as newlines are stripped from the\n    result body during processing."
    },
    {
      "id": "highlighting",
      "title": "Highlighting",
      "role": "content",
      "text": "[code example]\n\nHighlighting will surround the found term (and its variants) with a user-defined pair of tags. This may be used to display the matched text in a different typeface using a markup language, or to otherwise make the text appear differently.\n\nRedis performs highlighting using the `HIGHLIGHT` keyword. If no additional arguments are passed, all returned fields are highlighted using built-in defaults.\n\nThe `HIGHLIGHT` keyword accepts the following arguments:\n\n* **`FIELDS`**: If present, it must be the first argument. This should be followed\n    by the number of fields to highlight, which itself is followed by a list of\n    fields. Each field present is highlighted. If no `FIELDS` directive is passed,\n    then all returned fields are highlighted.\n    \n* **`TAGS`**: If present, it must be followed by two strings. The first string is prepended\n    to each matched term. The second string is appended to each matched term. If no `TAGS` are\n    specified, a built-in tag pair is prepended and appended to each matched term.\n\n\n#### Field selection\n\nIf no specific fields are passed to the `RETURN`, `SUMMARIZE`, or `HIGHLIGHT` keywords, then all of a document's fields are returned. However, if any of these keywords contain a `FIELD` directive, then the `SEARCH` command will only return the sum total of all fields enumerated in any of those directives.\n\nThe `RETURN` keyword is treated specially, as it overrides any fields specified in `SUMMARIZE` or `HIGHLIGHT`.\n\nIn the command `RETURN 1 foo SUMMARIZE FIELDS 1 bar HIGHLIGHT FIELDS 1 baz`, the fields `foo` is returned as-is, while `bar` and `baz` are not returned, because `RETURN` was specified, but did not include those fields.\n\nIn the command `SUMMARIZE FIELDS 1 bar HIGHLIGHT FIELDS 1 baz`, `bar` is returned summarized and `baz` is returned highlighted."
    }
  ],
  "examples": [
    {
      "id": "command-syntax-ex0",
      "language": "plaintext",
      "code": "FT.SEARCH ...\n    SUMMARIZE [FIELDS {num} {field}] [FRAGS {numFrags}] [LEN {fragLen}] [SEPARATOR {sepstr}]\n    HIGHLIGHT [FIELDS {num} {field}] [TAGS {openTag} {closeTag}]",
      "section_id": "command-syntax"
    },
    {
      "id": "summarization-ex0",
      "language": "plaintext",
      "code": "FT.SEARCH ...\n    SUMMARIZE [FIELDS {num} {field}] [FRAGS {numFrags}] [LEN {fragLen}] [SEPARATOR {sepStr}]",
      "section_id": "summarization"
    },
    {
      "id": "highlighting-ex0",
      "language": "plaintext",
      "code": "FT.SEARCH ... HIGHLIGHT [FIELDS {num} {field}] [TAGS {openTag} {closeTag}]",
      "section_id": "highlighting"
    }
  ]
}
