* for query dsl index page rewrites for proper index page Signed-off-by: alicejw <[email protected]> * fix formatting in table Signed-off-by: alicejw <[email protected]> * update query table intro Signed-off-by: alicejw <[email protected]> * rmv proprietary from overview Signed-off-by: alicejw <[email protected]> * awkward sentence fix Signed-off-by: alicejw <[email protected]> * to add list of all query categories Signed-off-by: alicejw <[email protected]> * for query category descriptions Signed-off-by: alicejw <[email protected]> * remove commented note Signed-off-by: alicejw <[email protected]> * update term-level query page Signed-off-by: alicejw <[email protected]> * for clarity about term and full-text query use cases Signed-off-by: alicejw <[email protected]> * for parallel bullet list of queries Signed-off-by: alicejw <[email protected]> * remove redundant word Signed-off-by: alicejw <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/term.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/term.md Co-authored-by: kolchfa-aws <[email protected]> * for tech review feedback Signed-off-by: alicejw <[email protected]> * for entire list of query types we support, even though we don't have document topic pages for them yet. Signed-off-by: alicejw <[email protected]> * to include full list of query types we support Signed-off-by: alicejw <[email protected]> * change Boolean to type for consistency in the section Signed-off-by: alicejw <[email protected]> * update query type category list title Signed-off-by: alicejw <[email protected]> * for compound query type definitions Signed-off-by: alicejw <[email protected]> * for additional descriptions Signed-off-by: alicejw <[email protected]> * for query context descriptions Signed-off-by: alicejw <[email protected]> * for additional edits to query descriptions list Signed-off-by: alicejw <[email protected]> * create span query category page and update bullet list on index to cross-reference to it. Signed-off-by: alicejw <[email protected]> * add pages for geo and shape query category, and add cross-references Signed-off-by: alicejw <[email protected]> * remove regex it is part of term-level queries Signed-off-by: alicejw <[email protected]> * for bullet list granular edits Signed-off-by: alicejw <[email protected]> * put bullet list in alphabetical order Signed-off-by: alicejw <[email protected]> * for doc review updates Signed-off-by: alicejw <[email protected]> * reword for reviewer feedback Signed-off-by: alicejw <[email protected]> * small rewording Signed-off-by: alicejw <[email protected]> * typo space Signed-off-by: alicejw <[email protected]> * put topics in alphabetical order in left nav Signed-off-by: alicejw <[email protected]> * additional reviewer's comment Signed-off-by: alicejw <[email protected]> * for second doc reviewer's feedback updates Signed-off-by: alicejw <[email protected]> * for doc reviewer comment that was hidden Signed-off-by: alicejw <[email protected]> * Update _opensearch/query-dsl/geo-and-shape.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/index.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/span-query.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/span-query.md Co-authored-by: kolchfa-aws <[email protected]> * Update _opensearch/query-dsl/term.md Co-authored-by: kolchfa-aws <[email protected]> * updates from third doc review for tech accuracy requested by editorial Signed-off-by: alicejw <[email protected]> * create compound query sub-page to move descriptions to make bullet list parallel Signed-off-by: alicejw <[email protected]> * fix compound query page title Signed-off-by: alicejw <[email protected]> * add fuzzy query definition Signed-off-by: alicejw <[email protected]> * for editorial feedback updates Signed-off-by: alicejw <[email protected]> * Update _opensearch/query-dsl/term.md Co-authored-by: kolchfa-aws <[email protected]> * Refactor Query DSL section Signed-off-by: Fanit Kolchina <[email protected]> * Adds doc review comments Signed-off-by: Fanit Kolchina <[email protected]> * Fix typo Signed-off-by: Fanit Kolchina <[email protected]> * Implemented editorial comments Signed-off-by: Fanit Kolchina <[email protected]> * Changed periods to colons when introducing code blocks Signed-off-by: Fanit Kolchina <[email protected]> --------- Signed-off-by: alicejw <[email protected]> Signed-off-by: Fanit Kolchina <[email protected]> Co-authored-by: alicejw <[email protected]> Co-authored-by: Alice Williams <[email protected]>
491 lines
12 KiB
Markdown
491 lines
12 KiB
Markdown
---
|
|
layout: default
|
|
title: Full-Text Search
|
|
parent: SQL and PPL
|
|
nav_order: 11
|
|
---
|
|
|
|
# Full-text search
|
|
|
|
Use SQL commands for full-text search. The SQL plugin supports a subset of full-text queries available in OpenSearch.
|
|
|
|
To learn about full-text queries in OpenSearch, see [Full-text queries]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index).
|
|
|
|
## Match
|
|
|
|
Use the `MATCH` function to search documents that match a `string`, `number`, `date`, or `boolean` value for a given field.
|
|
|
|
### Syntax
|
|
|
|
```sql
|
|
match(field_expression, query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
You can specify the following options in any order:
|
|
|
|
- `analyzer`
|
|
- `auto_generate_synonyms_phrase`
|
|
- `fuzziness`
|
|
- `max_expansions`
|
|
- `prefix_length`
|
|
- `fuzzy_transpositions`
|
|
- `fuzzy_rewrite`
|
|
- `lenient`
|
|
- `operator`
|
|
- `minimum_should_match`
|
|
- `zero_terms_query`
|
|
- `boost`
|
|
|
|
Refer to the `match` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#match) for parameter descriptions and supported values.
|
|
|
|
### Example 1: Search the `message` field for the text "this is a test":
|
|
|
|
```json
|
|
GET my_index/_search
|
|
{
|
|
"query": {
|
|
"match": {
|
|
"message": "this is a test"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
*SQL query:*
|
|
```sql
|
|
SELECT message FROM my_index WHERE match(message, "this is a test")
|
|
```
|
|
*PPL query:*
|
|
```ppl
|
|
SOURCE=my_index | WHERE match(message, "this is a test") | FIELDS message
|
|
```
|
|
|
|
### Example 2: Search the `message` field with the `operator` parameter:
|
|
|
|
```json
|
|
GET my_index/_search
|
|
{
|
|
"query": {
|
|
"match": {
|
|
"message": {
|
|
"query": "this is a test",
|
|
"operator": "and"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
*SQL query:*
|
|
```sql
|
|
SELECT message FROM my_index WHERE match(message, "this is a test", operator='and')
|
|
```
|
|
*PPL query:*
|
|
```ppl
|
|
SOURCE=my_index | WHERE match(message, "this is a test", operator='and') | FIELDS message
|
|
```
|
|
|
|
### Example 3: Search the `message` field with the `operator` and `zero_terms_query` parameters:
|
|
|
|
```json
|
|
GET my_index/_search
|
|
{
|
|
"query": {
|
|
"match": {
|
|
"message": {
|
|
"query": "to be or not to be",
|
|
"operator": "and",
|
|
"zero_terms_query": "all"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
*SQL query:*
|
|
```sql
|
|
SELECT message FROM my_index WHERE match(message, "this is a test", operator='and', zero_terms_query='all')
|
|
```
|
|
*PPL query:*
|
|
```sql
|
|
SOURCE=my_index | WHERE match(message, "this is a test", operator='and', zero_terms_query='all') | FIELDS message
|
|
```
|
|
|
|
## Multi-match
|
|
|
|
To search for text in multiple fields, use `MULTI_MATCH` function. This function maps to the `multi_match` query used in search engine, to returns the documents that match a provided text, number, date or boolean value with a given field or fields.
|
|
|
|
### Syntax
|
|
|
|
The `MULTI_MATCH` function lets you *boost* certain fields using **^** character. Boosts are multipliers that weigh matches in one field more heavily than matches in other fields. The syntax allows to specify the fields in double quotes, single quotes, surrounded by backticks, or unquoted. Use star ``"*"`` to search all fields. Star symbol should be quoted.
|
|
|
|
```sql
|
|
multi_match([field_expression+], query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The weight is optional and is specified after the field name. It could be delimited by the `caret` character -- `^` or by whitespace. Please, refer to examples below:
|
|
|
|
```sql
|
|
multi_match(["Tags" ^ 2, 'Title' 3.4, `Body`, Comments ^ 0.3], ...)
|
|
multi_match(["*"], ...)
|
|
```
|
|
|
|
You can specify the following options for `MULTI_MATCH` in any order:
|
|
|
|
- `analyzer`
|
|
- `auto_generate_synonyms_phrase`
|
|
- `cutoff_frequency`
|
|
- `fuzziness`
|
|
- `fuzzy_transpositions`
|
|
- `lenient`
|
|
- `max_expansions`
|
|
- `minimum_should_match`
|
|
- `operator`
|
|
- `prefix_length`
|
|
- `tie_breaker`
|
|
- `type`
|
|
- `slop`
|
|
- `zero_terms_query`
|
|
- `boost`
|
|
|
|
Please, refer to `multi_match` query [documentation](#multi-match) for parameter description and supported values.
|
|
|
|
### For example, REST API search for `Dale` in either the `firstname` or `lastname` fields:
|
|
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"multi_match": {
|
|
"query": "Lane Street",
|
|
"fields": [ "address" ],
|
|
}
|
|
}
|
|
}
|
|
```
|
|
could be called from *SQL* using `multi_match` function
|
|
```sql
|
|
SELECT firstname, lastname
|
|
FROM accounts
|
|
WHERE multi_match(['*name'], 'Dale')
|
|
```
|
|
or `multi_match` *PPL* function
|
|
```sql
|
|
SOURCE=accounts | WHERE multi_match(['*name'], 'Dale') | fields firstname, lastname
|
|
```
|
|
|
|
| firstname | lastname
|
|
:--- | :---
|
|
Dale | Adams
|
|
|
|
## Query string
|
|
|
|
To split text based on operators, use the `QUERY_STRING` function. The `QUERY_STRING` function supports logical connectives, wildcard, regex, and proximity search.
|
|
This function maps to the to the `query_string` query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields.
|
|
|
|
### Syntax
|
|
|
|
The `QUERY_STRING` function has syntax similar to `MATCH_QUERY` and lets you *boost* certain fields using **^** character. Boosts are multipliers that weigh matches in one field more heavily than matches in other fields. The syntax allows to specify the fields in double quotes, single quotes, surrounded by backticks, or unquoted. Use star ``"*"`` to search all fields. Star symbol should be quoted.
|
|
|
|
```sql
|
|
query_string([field_expression+], query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The weight is optional and is specified after the field name. It could be delimited by the `caret` character -- `^` or by whitespace. Please, refer to examples below:
|
|
|
|
```sql
|
|
query_string(["Tags" ^ 2, 'Title' 3.4, `Body`, Comments ^ 0.3], ...)
|
|
query_string(["*"], ...)
|
|
```
|
|
|
|
You can specify the following options for `QUERY_STRING` in any order:
|
|
|
|
- `analyzer`
|
|
- `allow_leading_wildcard`
|
|
- `analyze_wildcard`
|
|
- `auto_generate_synonyms_phrase_query`
|
|
- `boost`
|
|
- `default_operator`
|
|
- `enable_position_increments`
|
|
- `fuzziness`
|
|
- `fuzzy_rewrite`
|
|
- `escape`
|
|
- `fuzzy_max_expansions`
|
|
- `fuzzy_prefix_length`
|
|
- `fuzzy_transpositions`
|
|
- `lenient`
|
|
- `max_determinized_states`
|
|
- `minimum_should_match`
|
|
- `quote_analyzer`
|
|
- `phrase_slop`
|
|
- `quote_field_suffix`
|
|
- `rewrite`
|
|
- `type`
|
|
- `tie_breaker`
|
|
- `time_zone`
|
|
|
|
Refer to the `query_string` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#query-string) for parameter descriptions and supported values.
|
|
|
|
### Example of using `query_string` in SQL and PPL queries:
|
|
|
|
The REST API search request
|
|
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"query_string": {
|
|
"query": "Lane Street",
|
|
"fields": [ "address" ],
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
could be called from *SQL*
|
|
|
|
```sql
|
|
SELECT account_number, address
|
|
FROM accounts
|
|
WHERE query_string(['address'], 'Lane Street', default_operator='OR')
|
|
```
|
|
|
|
or from *PPL*
|
|
|
|
```sql
|
|
SOURCE=accounts | WHERE query_string(['address'], 'Lane Street', default_operator='OR') | fields account_number, address
|
|
```
|
|
|
|
| account_number | address
|
|
:--- | :---
|
|
1 | 880 Holmes Lane
|
|
6 | 671 Bristol Street
|
|
13 | 789 Madison Street
|
|
|
|
## Match phrase
|
|
|
|
To search for exact phrases, use `MATCHPHRASE` or `MATCH_PHRASE` functions.
|
|
|
|
### Syntax
|
|
|
|
```sql
|
|
matchphrasequery(field_expression, query_expression)
|
|
matchphrase(field_expression, query_expression[, option=<option_value>]*)
|
|
match_phrase(field_expression, query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The `MATCHPHRASE`/`MATCH_PHRASE` functions let you specify the following options in any order:
|
|
|
|
- `analyzer`
|
|
- `slop`
|
|
- `zero_terms_query`
|
|
- `boost`
|
|
|
|
Refer to the `match_phrase` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#match-phrase) for parameter descriptions and supported values.
|
|
|
|
### Example of using `match_phrase` in SQL and PPL queries:
|
|
|
|
The REST API search request
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"match_phrase": {
|
|
"address": {
|
|
"query": "880 Holmes Lane"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
could be called from *SQL*
|
|
```sql
|
|
SELECT account_number, address
|
|
FROM accounts
|
|
WHERE match_phrase(address, '880 Holmes Lane')
|
|
```
|
|
or *PPL*
|
|
```sql
|
|
SOURCE=accounts | WHERE match_phrase(address, '880 Holmes Lane') | FIELDS account_number, address
|
|
```
|
|
|
|
| account_number | address
|
|
:--- | :---
|
|
1 | 880 Holmes Lane
|
|
|
|
|
|
## Simple query string
|
|
|
|
The `simple_query_string` function maps to the `simple_query_string` query in OpenSearch. It returns the documents that match a provided text, number, date or boolean value with a given field or fields.
|
|
The **^** lets you *boost* certain fields. Boosts are multipliers that weigh matches in one field more heavily than matches in other fields.
|
|
|
|
### Syntax
|
|
|
|
The syntax allows to specify the fields in double quotes, single quotes, surrounded by backticks, or unquoted. Use star ``"*"`` to search all fields. Star symbol should be quoted.
|
|
|
|
```sql
|
|
simple_query_string([field_expression+], query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The weight is optional and is specified after the field name. It could be delimited by the `caret` character -- `^` or by whitespace. Please, refer to examples below:
|
|
|
|
```sql
|
|
simple_query_string(["Tags" ^ 2, 'Title' 3.4, `Body`, Comments ^ 0.3], ...)
|
|
simple_query_string(["*"], ...)
|
|
```
|
|
|
|
You can specify the following options for `SIMPLE_QUERY_STRING` in any order:
|
|
|
|
- `analyze_wildcard`
|
|
- `analyzer`
|
|
- `auto_generate_synonyms_phrase_query`
|
|
- `boost`
|
|
- `default_operator`
|
|
- `flags`
|
|
- `fuzzy_max_expansions`
|
|
- `fuzzy_prefix_length`
|
|
- `fuzzy_transpositions`
|
|
- `lenient`
|
|
- `minimum_should_match`
|
|
- `quote_field_suffix`
|
|
|
|
Refer to the `simple_query_string` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#simple-query-string) for parameter descriptions and supported values.
|
|
|
|
### *Example* of using `simple_query_string` in SQL and PPL queries:
|
|
|
|
The REST API search request
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"simple_query_string": {
|
|
"query": "Lane Street",
|
|
"fields": [ "address" ],
|
|
}
|
|
}
|
|
}
|
|
```
|
|
could be called from *SQL*
|
|
```sql
|
|
SELECT account_number, address
|
|
FROM accounts
|
|
WHERE simple_query_string(['address'], 'Lane Street', default_operator='OR')
|
|
```
|
|
or from *PPL*
|
|
```sql
|
|
SOURCE=accounts | WHERE simple_query_string(['address'], 'Lane Street', default_operator='OR') | fields account_number, address
|
|
```
|
|
|
|
| account_number | address
|
|
:--- | :---
|
|
1 | 880 Holmes Lane
|
|
6 | 671 Bristol Street
|
|
13 | 789 Madison Street
|
|
|
|
## Match phrase prefix
|
|
|
|
To search for phrases by given prefix, use `MATCH_PHRASE_PREFIX` function to make a prefix query out of the last term in the query string.
|
|
|
|
### Syntax
|
|
|
|
```sql
|
|
match_phrase_prefix(field_expression, query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The `MATCH_PHRASE_PREFIX` function lets you specify the following options in any order:
|
|
|
|
- `analyzer`
|
|
- `slop`
|
|
- `max_expansions`
|
|
- `zero_terms_query`
|
|
- `boost`
|
|
|
|
Refer to the `match_phrase_prefix` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#match-phrase-prefix) for parameter descriptions and supported values.
|
|
|
|
### *Example* of using `match_phrase_prefix` in SQL and PPL queries:
|
|
|
|
The REST API search request
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"match_phrase_prefix": {
|
|
"author": {
|
|
"query": "Alexander Mil"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
could be called from *SQL*
|
|
```sql
|
|
SELECT author, title
|
|
FROM books
|
|
WHERE match_phrase_prefix(author, 'Alexander Mil')
|
|
```
|
|
or *PPL*
|
|
```sql
|
|
source=books | where match_phrase_prefix(author, 'Alexander Mil') | fields author, title
|
|
```
|
|
|
|
| author | title
|
|
:--- | :---
|
|
Alan Alexander Milne | The House at Pooh Corner
|
|
Alan Alexander Milne | Winnie-the-Pooh
|
|
|
|
|
|
## Match boolean prefix
|
|
|
|
Use the `match_bool_prefix` function to search documents that match text only for a given field prefix.
|
|
|
|
### Syntax
|
|
|
|
```sql
|
|
match_bool_prefix(field_expression, query_expression[, option=<option_value>]*)
|
|
```
|
|
|
|
The `MATCH_BOOL_PREFIX` function lets you specify the following options in any order:
|
|
|
|
- `minimum_should_match`
|
|
- `fuzziness`
|
|
- `prefix_length`
|
|
- `max_expansions`
|
|
- `fuzzy_transpositions`
|
|
- `fuzzy_rewrite`
|
|
- `boost`
|
|
- `analyzer`
|
|
- `operator`
|
|
|
|
Refer to the `match_bool_prefix` query [documentation]({{site.url}}{{site.baseurl}}/opensearch/query-dsl/full-text/index#match-boolean-prefix) for parameter descriptions and supported values.
|
|
|
|
### Example of using `match_bool_prefix` in SQL and PPL queries:
|
|
|
|
The REST API search request
|
|
```json
|
|
GET accounts/_search
|
|
{
|
|
"query": {
|
|
"match_bool_prefix": {
|
|
"address": {
|
|
"query": "Bristol Stre"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
could be called from *SQL*
|
|
```sql
|
|
SELECT firstname, address
|
|
FROM accounts
|
|
WHERE match_bool_prefix(address, 'Bristol Stre')
|
|
```
|
|
or *PPL*
|
|
```sql
|
|
source=accounts | where match_bool_prefix(address, 'Bristol Stre') | fields firstname, address
|
|
```
|
|
|
|
| firstname | address
|
|
:--- | :---
|
|
Hattie | 671 Bristol Street
|
|
Nanette | 789 Madison Street
|