Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESQL - Update WHERE command docs with MATCH and full text functions examples #118987

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/reference/esql/esql-limitations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ it is necessary to use the search function, like <<esql-match>>, in a <<esql-whe
directly after the <<esql-from>> source command, or close enough to it.
Otherwise, the query will fail with a validation error.
Another limitation is that any <<esql-where>> command containing a full-text search function
cannot also use disjunctions (`OR`).
cannot also use disjunctions (`OR`) unless all functions used in the OR clauses are full-text functions themselves.

For example, this query is valid:

Expand All @@ -139,6 +139,15 @@ FROM books
| WHERE MATCH(author, "Faulkner") OR author LIKE "Hemingway"
----

but this one will succeed, as it uses full text functions on both OR clauses:
carlosdelest marked this conversation as resolved.
Show resolved Hide resolved

[source,esql]
----
FROM books
| WHERE MATCH(author, "Faulkner") OR QSTR("author: Hemingway")
----


Note that, because of <<esql-limitations-text-fields,the way {esql} treats `text` values>>,
any queries on `text` fields that do not explicitly use the full-text functions,
<<esql-match>> or <<esql-qstr>>, will behave as if the fields are actually `keyword` fields:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/esql/functions/description/match.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/definition/match.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion docs/reference/esql/functions/kibana/docs/match.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion docs/reference/esql/functions/search-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
++++

Full text functions are used to search for text in fields.
<<analysis, Text analysiss>> is used to analyze the query before it is searched.
<<analysis, Text analysis>> is used to analyze the query before it is searched.

Full text functions can be used to match <<esql-multivalued-fields,multivalued fields>>.
A multivalued field that contains a value that matches a full text query is considered to match the query.

Full text functions are significantly more performant for text search use cases on large data sets than using pattern matching or regular expressions with `LIKE` or `RLIKE`

See <<esql-limitations-full-text-search,full text search limitations>> for information on the limitations of full text search.

{esql} supports these full-text search functions:
Expand Down
19 changes: 18 additions & 1 deletion docs/reference/esql/processing-commands/where.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the input table for which the provided condition evaluates to `true`.

[TIP]
====
In case of value exclusions, fields with `null` values will be excluded from search results.
In case of value exclusions, fields with `null` values will be excluded from search results.
In this context a `null` means either there is an explicit `null` value in the document or there is no value at all.
For example: `WHERE field != "value"` will be interpreted as `WHERE field != "value" AND field IS NOT NULL`.
====
Expand Down Expand Up @@ -58,6 +58,23 @@ For a complete list of all functions, refer to <<esql-functions>>.

include::../functions/predicates.asciidoc[tag=body]

For matching text, you can use <<esql-search-functions,full text search functions>> like `MATCH`.

Use <<esql-match,`MATCH`>> to perform a <<query-dsl-match-query,match query>> on a specified field.

Match can be used on text fields, as well as other field types like boolean, dates, and numeric types.

[source.merge.styled,esql]
----
include::{esql-specs}/match-function.csv-spec[tag=match-with-field]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/match-function.csv-spec[tag=match-with-field-result]
|===

For a simplified syntax, you can use the <<esql-search-operators,match operator>> `:` instead of `MATCH`.
carlosdelest marked this conversation as resolved.
Show resolved Hide resolved

include::../functions/like.asciidoc[tag=body]

include::../functions/rlike.asciidoc[tag=body]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ public class Match extends FullTextFunction implements Validatable {
@FunctionInfo(
returnType = "boolean",
preview = true,
description = "Performs a <<query-dsl-match-query,match query>> on the specified field. "
+ "Returns true if the provided query matches the row.",
description = """
Use `MATCH` to perform a <<query-dsl-match-query,match query>> on the specified field.
Using `MATCH` is equivalent to using the `match` query in the Elasticsearch Query DSL.

Match can be used on text fields, as well as other field types like boolean, dates, and numeric types.

For a simplified syntax, you can use the <<esql-search-operators,match operator>> `:` operator instead of `MATCH`.

`MATCH` returns true if the provided query matches the row.""",
examples = { @Example(file = "match-function", tag = "match-with-field") }
)
public Match(
Expand Down