Skip to content

Commit ff58d89

Browse files
authored
ES|QL kql function. (#116764)
1 parent 105d4f8 commit ff58d89

File tree

29 files changed

+1149
-66
lines changed

29 files changed

+1149
-66
lines changed

docs/reference/esql/functions/description/kql.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/kql.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/kql.json

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

docs/reference/esql/functions/kibana/docs/kql.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/kql.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/kql.asciidoc

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

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

+1
Loading

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

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

x-pack/plugin/esql/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies {
3434
compileOnly project(':modules:lang-painless:spi')
3535
compileOnly project(xpackModule('esql-core'))
3636
compileOnly project(xpackModule('ml'))
37+
implementation project(xpackModule('kql'))
3738
implementation project('compute')
3839
implementation project('compute:ann')
3940
implementation project(':libs:dissect')
@@ -50,6 +51,7 @@ dependencies {
5051
testImplementation(testArtifact(project(xpackModule('core'))))
5152
testImplementation project(path: xpackModule('enrich'))
5253
testImplementation project(path: xpackModule('spatial'))
54+
testImplementation project(path: xpackModule('kql'))
5355

5456
testImplementation project(path: ':modules:reindex')
5557
testImplementation project(path: ':modules:parent-join')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
###############################################
2+
# Tests for KQL function
3+
#
4+
5+
kqlWithField
6+
required_capability: kql_function
7+
8+
// tag::kql-with-field[]
9+
FROM books
10+
| WHERE KQL("author: Faulkner")
11+
| KEEP book_no, author
12+
| SORT book_no
13+
| LIMIT 5;
14+
// end::kql-with-field[]
15+
16+
// tag::kql-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::kql-with-field-result[]
25+
26+
kqlWithMultipleFields
27+
required_capability: kql_function
28+
29+
from books
30+
| where kql("title:Return* AND 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+
kqlWithQueryExpressions
40+
required_capability: kql_function
41+
42+
from books
43+
| where kql(CONCAT("title:Return*", " AND author:*Tolkien"))
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+
kqlWithConjunction
53+
required_capability: kql_function
54+
55+
from books
56+
| where kql("title: Rings") and ratings > 4.6
57+
| keep book_no, title;
58+
ignoreOrder:true
59+
60+
book_no:keyword | title:text
61+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
62+
7140 | The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
63+
;
64+
65+
kqlWithFunctionPushedToLucene
66+
required_capability: kql_function
67+
68+
from hosts
69+
| where kql("host: beta") and cidr_match(ip1, "127.0.0.2/32", "127.0.0.3/32")
70+
| keep card, host, ip0, ip1;
71+
ignoreOrder:true
72+
73+
card:keyword |host:keyword |ip0:ip |ip1:ip
74+
eth1 |beta |127.0.0.1 |127.0.0.2
75+
;
76+
77+
kqlWithNonPushableConjunction
78+
required_capability: kql_function
79+
80+
from books
81+
| where kql("title: Rings") and length(title) > 75
82+
| keep book_no, title;
83+
ignoreOrder:true
84+
85+
book_no:keyword | title:text
86+
4023 |A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
87+
;
88+
89+
kqlWithMultipleWhereClauses
90+
required_capability: kql_function
91+
92+
from books
93+
| where kql("title: rings")
94+
| where kql("year > 1 AND year < 2005")
95+
| keep book_no, title;
96+
ignoreOrder:true
97+
98+
book_no:keyword | title:text
99+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
100+
7140 | The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
101+
;
102+
103+
104+
kqlWithMultivaluedTextField
105+
required_capability: kql_function
106+
107+
from employees
108+
| where kql("job_positions: Tech Lead AND job_positions:(Reporting Analyst)")
109+
| keep emp_no, first_name, last_name;
110+
ignoreOrder:true
111+
112+
emp_no:integer | first_name:keyword | last_name:keyword
113+
10004 | Chirstian | Koblick
114+
10010 | Duangkaew | Piveteau
115+
10011 | Mary | Sluis
116+
10088 | Jungsoon | Syrzycki
117+
10093 | Sailaja | Desikan
118+
10097 | Remzi | Waschkowski
119+
;
120+
121+
kqlWithMultivaluedNumericField
122+
required_capability: kql_function
123+
124+
from employees
125+
| where kql("salary_change > 14")
126+
| keep emp_no, first_name, last_name, salary_change;
127+
ignoreOrder:true
128+
129+
emp_no:integer | first_name:keyword | last_name:keyword | salary_change:double
130+
10003 | Parto | Bamford | [12.82, 14.68]
131+
10015 | Guoxiang | Nooteboom | [12.4, 14.25]
132+
10023 | Bojan | Montemayor | [0.8, 14.63]
133+
10040 | Weiyi | Meriste | [-8.94, 1.92, 6.97, 14.74]
134+
10061 | Tse | Herber | [-2.58, -0.95, 14.39]
135+
10065 | Satosi | Awdeh | [-9.81, -1.47, 14.44]
136+
10099 | Valter | Sullins | [-8.78, -3.98, 10.71, 14.26]
137+
;
138+
139+
testMultiValuedFieldWithConjunction
140+
required_capability: kql_function
141+
142+
from employees
143+
| where (kql("job_positions: (Data Scientist) OR job_positions:(Support Engineer)")) and gender == "F"
144+
| keep emp_no, first_name, last_name;
145+
ignoreOrder:true
146+
147+
emp_no:integer | first_name:keyword | last_name:keyword
148+
10023 | Bojan | Montemayor
149+
10041 | Uri | Lenart
150+
10044 | Mingsen | Casley
151+
10053 | Sanjiv | Zschoche
152+
10069 | Margareta | Bierman
153+
;

x-pack/plugin/esql/qa/testFixtures/src/main/resources/qstr-function.csv-spec

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ book_no:keyword | title:text
101101
;
102102

103103

104-
matchMultivaluedTextField
105-
required_capability: match_function
104+
qstrWithMultivaluedTextField
105+
required_capability: qstr_function
106106

107107
from employees
108108
| where qstr("job_positions: (Tech Lead) AND job_positions:(Reporting Analyst)")
@@ -118,8 +118,8 @@ emp_no:integer | first_name:keyword | last_name:keyword
118118
10097 | Remzi | Waschkowski
119119
;
120120

121-
matchMultivaluedNumericField
122-
required_capability: match_function
121+
qstrWithMultivaluedNumericField
122+
required_capability: qstr_function
123123

124124
from employees
125125
| where qstr("salary_change: [14 TO *]")
@@ -137,7 +137,7 @@ emp_no:integer | first_name:keyword | last_name:keyword | salary_change:double
137137
;
138138

139139
testMultiValuedFieldWithConjunction
140-
required_capability: match_function
140+
required_capability: qstr_function
141141

142142
from employees
143143
| where (qstr("job_positions: (Data Scientist) OR job_positions:(Support Engineer)")) and gender == "F"

0 commit comments

Comments
 (0)