Skip to content

Commit 6ee641b

Browse files
authored
ESQL - Update WHERE command docs with MATCH and full text functions examples (#118987)
1 parent 9af1402 commit 6ee641b

File tree

7 files changed

+53
-8
lines changed

7 files changed

+53
-8
lines changed

docs/reference/esql/esql-limitations.asciidoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ it is necessary to use the search function, like <<esql-match>>, in a <<esql-whe
112112
directly after the <<esql-from>> source command, or close enough to it.
113113
Otherwise, the query will fail with a validation error.
114114
Another limitation is that any <<esql-where>> command containing a full-text search function
115-
cannot also use disjunctions (`OR`).
115+
cannot also use disjunctions (`OR`) unless all functions used in the OR clauses are full-text functions themselves.
116116

117117
For example, this query is valid:
118118

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

142+
However this query will succeed because it uses full text functions on both `OR` clauses:
143+
144+
[source,esql]
145+
----
146+
FROM books
147+
| WHERE MATCH(author, "Faulkner") OR QSTR("author: Hemingway")
148+
----
149+
150+
142151
Note that, because of <<esql-limitations-text-fields,the way {esql} treats `text` values>>,
143152
any queries on `text` fields that do not explicitly use the full-text functions,
144153
<<esql-match>> or <<esql-qstr>>, will behave as if the fields are actually `keyword` fields:

docs/reference/esql/functions/description/match.asciidoc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/definition/match.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/docs/match.md

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/search-functions.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
++++
77

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

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

14+
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`
15+
1416
See <<esql-limitations-full-text-search,full text search limitations>> for information on the limitations of full text search.
1517

1618
{esql} supports these full-text search functions:

docs/reference/esql/processing-commands/where.asciidoc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ the input table for which the provided condition evaluates to `true`.
77

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

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

61+
For matching text, you can use <<esql-search-functions,full text search functions>> like `MATCH`.
62+
63+
Use <<esql-match,`MATCH`>> to perform a <<query-dsl-match-query,match query>> on a specified field.
64+
65+
Match can be used on text fields, as well as other field types like boolean, dates, and numeric types.
66+
67+
[source.merge.styled,esql]
68+
----
69+
include::{esql-specs}/match-function.csv-spec[tag=match-with-field]
70+
----
71+
[%header.monospaced.styled,format=dsv,separator=|]
72+
|===
73+
include::{esql-specs}/match-function.csv-spec[tag=match-with-field-result]
74+
|===
75+
76+
[TIP]
77+
====
78+
You can also use the shorthand <<esql-search-operators,match operator>> `:` instead of `MATCH`.
79+
====
80+
6181
include::../functions/like.asciidoc[tag=body]
6282

6383
include::../functions/rlike.asciidoc[tag=body]

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ public class Match extends FullTextFunction implements Validatable {
9898
@FunctionInfo(
9999
returnType = "boolean",
100100
preview = true,
101-
description = "Performs a <<query-dsl-match-query,match query>> on the specified field. "
102-
+ "Returns true if the provided query matches the row.",
101+
description = """
102+
Use `MATCH` to perform a <<query-dsl-match-query,match query>> on the specified field.
103+
Using `MATCH` is equivalent to using the `match` query in the Elasticsearch Query DSL.
104+
105+
Match can be used on text fields, as well as other field types like boolean, dates, and numeric types.
106+
107+
For a simplified syntax, you can use the <<esql-search-operators,match operator>> `:` operator instead of `MATCH`.
108+
109+
`MATCH` returns true if the provided query matches the row.""",
103110
examples = { @Example(file = "match-function", tag = "match-with-field") }
104111
)
105112
public Match(

0 commit comments

Comments
 (0)