Full-text search

    To learn about full-text queries in OpenSearch, see Full-text queries.

    Use the command to search documents that match a string, number, date, or boolean value for a given field.

    You can specify the following options:

    • analyzer
    • auto_generate_synonyms_phrase
    • fuzziness
    • max_expansions
    • prefix_length
    • fuzzy_transpositions
    • fuzzy_rewrite
    • lenient
    • operator
    • minimum_should_match
    • zero_terms_query
    • boost

    Example 1: Search the message field:

    1. GET my_index/_search
    2. {
    3. "match": {
    4. "message": "this is a test"
    5. }
    6. }
    7. }

    SQL query:

    1. SELECT message FROM my_index WHERE match(message, "this is a test")
    1. GET my_index/_search
    2. {
    3. "query": {
    4. "match": {
    5. "message": {
    6. "query": "this is a test",
    7. "operator": "and"
    8. }
    9. }
    10. }
    11. }

    SQL query:

    Example 3: Search the message field with the operator and zero_terms_query parameters:

    1. GET my_index/_search
    2. {
    3. "query": {
    4. "message": {
    5. "query": "to be or not to be",
    6. "operator": "and",
    7. "zero_terms_query": "all"
    8. }
    9. }
    10. }
    11. }

    SQL query:

    1. SELECT message FROM my_index WHERE match(message, "this is a test", operator=and, zero_terms_query=all)

    To search for text in a single field, use or MATCH_QUERY functions.

    Pass in your search query and the field name that you want to search against.

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

    To search for text in multiple fields, use MULTI_MATCH, MULTIMATCH, or MULTIMATCHQUERY functions.

    For example, search for Dale in either the firstname or lastname fields:

    1. SELECT firstname, lastname
    2. FROM accounts
    3. WHERE MULTI_MATCH('query'='Dale', 'fields'='*name')

    To split text based on operators, use the QUERY function.

    1. SELECT account_number, address
    2. FROM accounts
    3. WHERE QUERY('address:Lane OR address:Street')

    The QUERY function supports logical connectives, wildcard, regex, and proximity search.

    To search for exact phrases, use MATCHPHRASE, MATCH_PHRASE, or MATCHPHRASEQUERY functions.

    1. SELECT account_number, address
    2. FROM accounts

    You need to pass in two arguments. The first is the expression. The second is an optional floating point number to boost the score (default value is 1.0).