Skip to content

Support highlighting function in SQL/PPL query engine #636

@acarbonetto

Description

@acarbonetto

Related design for relevance-based search in SQL/PPL engine - #182

TODO List

  • Support the highlight function by including it in the search engine
  • Enable highlight function in SQL syntax and parser, including parameters
  • Enable highlight function in PPL syntax and parser, including parameters
  • Add unit tests
  • Add integration tests for highlighting
  • Update the user manual - append to existing match search documentation

Function Details

(reference: https://opensearch.org/docs/latest/opensearch/ux/#highlight-query-matches)

The highlighting function adds search term results to the service response for matched terms in fields. Highlighting only works in tandem with match-search queries. The list of highlighted fields must be present in a relevance-based search function, or else the highlighted fields will result in a syntax error.

Syntax

highlight([field_list, …][, option=<option_value>]*) 

Available Options

  • pre_tags: per-term tag to embed in the highlighted result, default is <em>
  • post_tags: post-term tag to embed in the highlighted result, default is </em>

Sample query

GET shakespeare/_search
{
  "query": {
    "match": {
      "text_entry": "life"
    }
  },
  "highlight": {
    "fields": {
      "text_entry": {}
    }
  }
}

SQL

SELECT highlight("text_entry") as "highlight_text_entry" FROM shakespeare WHERE match("text_entry", "life");

PPL

source=shakespeare | where match("text_entry", "life") | highlight("text_entry")

Sample response

| highlight_text_entry                      |
| "my <em>life</em>, except my <em>life</em>." |

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions