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:
GET my_index/_search
{
"match": {
"message": "this is a test"
}
}
}
SQL query:
SELECT message FROM my_index WHERE match(message, "this is a test")
GET my_index/_search
{
"query": {
"match": {
"message": {
"query": "this is a test",
"operator": "and"
}
}
}
}
SQL query:
Example 3: Search the message
field with the operator
and zero_terms_query
parameters:
GET my_index/_search
{
"query": {
"message": {
"query": "to be or not to be",
"operator": "and",
"zero_terms_query": "all"
}
}
}
}
SQL query:
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.
SELECT account_number, address
FROM accounts
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:
SELECT firstname, lastname
FROM accounts
WHERE MULTI_MATCH('query'='Dale', 'fields'='*name')
To split text based on operators, use the QUERY
function.
SELECT account_number, address
FROM accounts
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.
SELECT account_number, address
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).