Functions

    The MATCHQUERY and MATCH_QUERY functions are synonyms for the relevance function. They don’t accept additional arguments but provide an alternate syntax.

    To use matchquery or match_query, pass in your search query and the field name that you want to search against:

    You can specify the following options in any order:

    • analyzer
    • boost

    Example

    You can use MATCHQUERY to replace MATCH:

    1. SELECT account_number, address
    2. WHERE MATCHQUERY(address, 'Holmes')

    Alternatively, you can use MATCH_QUERY to replace MATCH:

    1. SELECT account_number, address
    2. FROM accounts
    3. WHERE address = MATCH_QUERY('Holmes')

    The results contain documents in which the address contains “Holmes”:

    Multi-match

    There are three synonyms for , each with a slightly different syntax. They accept a query string and a fields list with weights. They can also accept additional optional parameters.

    Syntax

    1. multimatch('query'=query_expression[, 'fields'=field_expression][, option=<option_value>]*)
    2. multi_match('query'=query_expression[, 'fields'=field_expression][, option=<option_value>]*)
    3. multimatchquery('query'=query_expression[, 'fields'=field_expression][, option=<option_value>]*)

    The fields parameter is optional and can contain a single field or a comma-separated list (whitespace characters are not allowed). The weight for each field is optional and is specified after the field name. It should be delimited by the caret character – ^ – without whitespace.

    Example

    You can specify the following options in any order:

    • boost
    • slop
    • type
    • tie_breaker
    • operator

    The QUERY function is a synonym for .

    1. query('query'=query_expression[, 'fields'=field_expression][, option=<option_value>]*)

    The fields parameter is optional and can contain a single field or a comma-separated list (whitespace characters are not allowed). The weight for each field is optional and is specified after the field name. It should be delimited by the caret character – ^ – without whitespace.

    Example

    The following queries show the fields parameter of a multi-match query with a single field and a field list:

    1. query('fields' = "Tags^2,Title^3.4,Body,Comments^0.3", ...)
    2. query('fields' = "Tags", ...)

    You can specify the following options in any order:

    • analyzer
    • boost
    • slop
    • default_field

    Example of using query_string in SQL and PPL queries:

    The following is a sample REST API search request in OpenSearch DSL.

    1. GET accounts/_search
    2. "query": {
    3. "query_string": {
    4. "query": "Lane Street",
    5. "fields": [ "address" ],
    6. }
    7. }

    The request above is equivalent to the following query function:

    The results contain addresses that contain “Lane” or “Street”:

    Match phrase

    Syntax

    1. matchphrasequery(query_expression, field_expression[, option=<option_value>]*)

    You can specify the following options in any order:

    • analyzer
    • boost
    • slop

    To return a relevance score along with every matching document, use the SCORE, SCOREQUERY, or SCORE_QUERY functions.

    The SCORE function expects two arguments. The first argument is the expression. The second argument is an optional floating-point number to boost the score (the default value is 1.0):

    1. SCORE(match_query_expression, score)
    2. SCOREQUERY(match_query_expression, score)
    3. SCORE_QUERY(match_query_expression, score)

    Example

    The following example uses the SCORE function to boost the documents’ scores:

    1. SELECT account_number, address, _score
    2. FROM accounts
    3. WHERE SCORE(MATCH_QUERY(address, 'Lane'), 0.5) OR
    4. SCORE(MATCH_QUERY(address, 'Street'), 100)
    5. ORDER BY _score

    The results contain matches with corresponding scores:

    Wildcard query

    To search documents by a given wildcard, use the WILDCARDQUERY or WILDCARD_QUERY functions.

    Syntax

    Example

    The following example uses a wildcard query:

    1. SELECT account_number, address

    The results contain documents that match the wildcard expression: