Skip to content

Commit 14c1c3c

Browse files
authored
[8.x] Add ESQL match function (#113374) (#114695)
1 parent 86455d7 commit 14c1c3c

File tree

41 files changed

+3435
-2273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3435
-2273
lines changed

docs/changelog/113374.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 113374
2+
summary: Add ESQL match function
3+
area: ES|QL
4+
type: feature
5+
issues: []

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

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+13
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

+85
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

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/signature/match.svg

+1
Loading

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

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ public static TypeResolution isNotNullAndFoldable(Expression e, String operation
155155
return resolution;
156156
}
157157

158-
public static TypeResolution isNotFoldable(Expression e, String operationName, ParamOrdinal paramOrd) {
159-
if (e.foldable()) {
158+
public static TypeResolution isNotNull(Expression e, String operationName, ParamOrdinal paramOrd) {
159+
if (e.dataType() == DataType.NULL) {
160160
return new TypeResolution(
161161
format(
162162
null,
163-
"{}argument of [{}] must be a table column, found constant [{}]",
163+
"{}argument of [{}] cannot be null, received [{}]",
164164
paramOrd == null || paramOrd == DEFAULT ? "" : paramOrd.name().toLowerCase(Locale.ROOT) + " ",
165165
operationName,
166166
Expressions.name(e)
167167
)
168168
);
169169
}
170+
170171
return TypeResolution.TYPE_RESOLVED;
171172
}
172173

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
###############################################
2+
# Tests for Match function
3+
#
4+
5+
matchWithField
6+
required_capability: match_function
7+
8+
// tag::match-with-field[]
9+
from books
10+
| where match(author, "Faulkner")
11+
| keep book_no, author
12+
| sort book_no
13+
| limit 5;
14+
// end::match-with-field[]
15+
16+
// tag::match-with-field-result[]
17+
book_no:keyword | author:text
18+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
19+
2713 | William Faulkner
20+
2847 | Colleen Faulkner
21+
2883 | William Faulkner
22+
3293 | Danny Faulkner
23+
;
24+
// end::match-with-field-result[]
25+
26+
matchWithMultipleFunctions
27+
required_capability: match_function
28+
29+
from books
30+
| where match(title, "Return") AND match(author, "Tolkien")
31+
| keep book_no, title;
32+
ignoreOrder:true
33+
34+
book_no:keyword | title:text
35+
2714 | Return of the King Being the Third Part of The Lord of the Rings
36+
7350 | Return of the Shadow
37+
;
38+
39+
matchWithQueryExpressions
40+
required_capability: match_function
41+
42+
from books
43+
| where match(title, CONCAT("Return ", " King"))
44+
| keep book_no, title;
45+
ignoreOrder:true
46+
47+
book_no:keyword | title:text
48+
2714 | Return of the King Being the Third Part of The Lord of the Rings
49+
7350 | Return of the Shadow
50+
;
51+
52+
matchAfterKeep
53+
required_capability: match_function
54+
55+
from books
56+
| keep book_no, author
57+
| where match(author, "Faulkner")
58+
| sort book_no
59+
| limit 5;
60+
61+
book_no:keyword | author:text
62+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
63+
2713 | William Faulkner
64+
2847 | Colleen Faulkner
65+
2883 | William Faulkner
66+
3293 | Danny Faulkner
67+
;
68+
69+
matchAfterDrop
70+
required_capability: match_function
71+
72+
from books
73+
| drop ratings, description, year, publisher, title, author.keyword
74+
| where match(author, "Faulkner")
75+
| keep book_no, author
76+
| sort book_no
77+
| limit 5;
78+
79+
book_no:keyword | author:text
80+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
81+
2713 | William Faulkner
82+
2847 | Colleen Faulkner
83+
2883 | William Faulkner
84+
3293 | Danny Faulkner
85+
;
86+
87+
matchAfterEval
88+
required_capability: match_function
89+
90+
from books
91+
| eval stars = to_long(ratings / 2.0)
92+
| where match(author, "Faulkner")
93+
| sort book_no
94+
| keep book_no, author, stars
95+
| limit 5;
96+
97+
book_no:keyword | author:text | stars:long
98+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott] | 3
99+
2713 | William Faulkner | 2
100+
2847 | Colleen Faulkner | 3
101+
2883 | William Faulkner | 2
102+
3293 | Danny Faulkner | 2
103+
;
104+
105+
matchWithConjunction
106+
required_capability: match_function
107+
108+
from books
109+
| where match(title, "Rings") and ratings > 4.6
110+
| keep book_no, title;
111+
ignoreOrder:true
112+
113+
book_no:keyword | title:text
114+
4023 |A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
115+
7140 |The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
116+
;
117+
118+
matchWithFunctionPushedToLucene
119+
required_capability: match_function
120+
121+
from hosts
122+
| where match(host, "beta") and cidr_match(ip1, "127.0.0.2/32", "127.0.0.3/32")
123+
| keep card, host, ip0, ip1;
124+
ignoreOrder:true
125+
126+
card:keyword |host:keyword |ip0:ip |ip1:ip
127+
eth1 |beta |127.0.0.1 |127.0.0.2
128+
;
129+
130+
matchWithNonPushableConjunction
131+
required_capability: match_function
132+
133+
from books
134+
| where match(title, "Rings") and length(title) > 75
135+
| keep book_no, title;
136+
ignoreOrder:true
137+
138+
book_no:keyword | title:text
139+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
140+
;
141+
142+
matchWithMultipleWhereClauses
143+
required_capability: match_function
144+
145+
from books
146+
| where match(title, "rings")
147+
| where match(title, "lord")
148+
| keep book_no, title;
149+
ignoreOrder:true
150+
151+
book_no:keyword | title:text
152+
2675 | The Lord of the Rings - Boxed Set
153+
2714 | Return of the King Being the Third Part of The Lord of the Rings
154+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
155+
7140 | The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
156+
;
157+
158+
matchMultivaluedField
159+
required_capability: match_function
160+
161+
from employees
162+
| where match(job_positions, "Tech Lead") and match(job_positions, "Reporting Analyst")
163+
| keep emp_no, first_name, last_name;
164+
ignoreOrder:true
165+
166+
emp_no:integer | first_name:keyword | last_name:keyword
167+
10004 | Chirstian | Koblick
168+
10010 | Duangkaew | Piveteau
169+
10011 | Mary | Sluis
170+
10088 | Jungsoon | Syrzycki
171+
10093 | Sailaja | Desikan
172+
10097 | Remzi | Waschkowski
173+
;
174+
175+
testMultiValuedFieldWithConjunction
176+
required_capability: match_function
177+
178+
from employees
179+
| where match(job_positions, "Data Scientist") and match(job_positions, "Support Engineer")
180+
| keep emp_no, first_name, last_name;
181+
ignoreOrder:true
182+
183+
emp_no:integer | first_name:keyword | last_name:keyword
184+
10043 | Yishay | Tzvieli
185+
;
186+
187+
testMatchAndQueryStringFunctions
188+
required_capability: match_function
189+
required_capability: qstr_function
190+
191+
from employees
192+
| where match(job_positions, "Data Scientist") and qstr("job_positions: (Support Engineer) and gender: F")
193+
| keep emp_no, first_name, last_name;
194+
ignoreOrder:true
195+
196+
emp_no:integer | first_name:keyword | last_name:keyword
197+
10041 | Uri | Lenart
198+
10043 | Yishay | Tzvieli
199+
;

0 commit comments

Comments
 (0)