Skip to content

Commit 9160586

Browse files
authored
Term query for ES|QL (#117359)
This commit adds a `term` function for ES|QL to run `TermQueries`. For example: FROM test | WHERE term(content, "dog")
1 parent 7bd5c69 commit 9160586

File tree

23 files changed

+883
-3
lines changed

23 files changed

+883
-3
lines changed

docs/changelog/117359.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 117359
2+
summary: Term query for ES|QL
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

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

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Loading

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

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
###############################################
2+
# Tests for Term function
3+
#
4+
5+
termWithTextField
6+
required_capability: term_function
7+
8+
// tag::term-with-field[]
9+
FROM books
10+
| WHERE TERM(author, "gabriel")
11+
| KEEP book_no, title
12+
| LIMIT 3;
13+
// end::term-with-field[]
14+
ignoreOrder:true
15+
16+
book_no:keyword | title:text
17+
4814 | El Coronel No Tiene Quien Le Escriba / No One Writes to the Colonel (Spanish Edition)
18+
4917 | Autumn of the Patriarch
19+
6380 | La hojarasca (Spanish Edition)
20+
;
21+
22+
termWithKeywordField
23+
required_capability: term_function
24+
25+
from employees
26+
| where term(first_name, "Guoxiang")
27+
| keep emp_no, first_name;
28+
29+
// tag::term-with-keyword-field-result[]
30+
emp_no:integer | first_name:keyword
31+
10015 | Guoxiang
32+
;
33+
// end::term-with-keyword-field-result[]
34+
35+
termWithQueryExpressions
36+
required_capability: term_function
37+
38+
from books
39+
| where term(author, CONCAT("gab", "riel"))
40+
| keep book_no, title;
41+
ignoreOrder:true
42+
43+
book_no:keyword | title:text
44+
4814 | El Coronel No Tiene Quien Le Escriba / No One Writes to the Colonel (Spanish Edition)
45+
4917 | Autumn of the Patriarch
46+
6380 | La hojarasca (Spanish Edition)
47+
;
48+
49+
termAfterKeep
50+
required_capability: term_function
51+
52+
from books
53+
| keep book_no, author
54+
| where term(author, "faulkner")
55+
| sort book_no
56+
| limit 5;
57+
58+
book_no:keyword | author:text
59+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
60+
2713 | William Faulkner
61+
2847 | Colleen Faulkner
62+
2883 | William Faulkner
63+
3293 | Danny Faulkner
64+
;
65+
66+
termAfterDrop
67+
required_capability: term_function
68+
69+
from books
70+
| drop ratings, description, year, publisher, title, author.keyword
71+
| where term(author, "william")
72+
| keep book_no, author
73+
| sort book_no
74+
| limit 2;
75+
76+
book_no:keyword | author:text
77+
2713 | William Faulkner
78+
2883 | William Faulkner
79+
;
80+
81+
termAfterEval
82+
required_capability: term_function
83+
84+
from books
85+
| eval stars = to_long(ratings / 2.0)
86+
| where term(author, "colleen")
87+
| sort book_no
88+
| keep book_no, author, stars
89+
| limit 2;
90+
91+
book_no:keyword | author:text | stars:long
92+
2847 | Colleen Faulkner | 3
93+
4502 | Colleen Faulkner | 3
94+
;
95+
96+
termWithConjunction
97+
required_capability: term_function
98+
99+
from books
100+
| where term(author, "tolkien") and ratings > 4.95
101+
| eval author = mv_sort(author)
102+
| keep book_no, ratings, author;
103+
ignoreOrder:true
104+
105+
book_no:keyword | ratings:double | author:keyword
106+
2301 | 5.0 | John Ronald Reuel Tolkien
107+
3254 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
108+
7350 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
109+
;
110+
111+
termWithConjunctionAndSort
112+
required_capability: term_function
113+
114+
from books
115+
| where term(author, "tolkien") and ratings > 4.95
116+
| eval author = mv_sort(author)
117+
| keep book_no, ratings, author
118+
| sort book_no;
119+
120+
book_no:keyword | ratings:double | author:keyword
121+
2301 | 5.0 | John Ronald Reuel Tolkien
122+
3254 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
123+
7350 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
124+
;
125+
126+
termWithFunctionPushedToLucene
127+
required_capability: term_function
128+
129+
from hosts
130+
| where term(host, "beta") and cidr_match(ip1, "127.0.0.2/32", "127.0.0.3/32")
131+
| keep card, host, ip0, ip1;
132+
ignoreOrder:true
133+
134+
card:keyword |host:keyword |ip0:ip |ip1:ip
135+
eth1 |beta |127.0.0.1 |127.0.0.2
136+
;
137+
138+
termWithNonPushableConjunction
139+
required_capability: term_function
140+
141+
from books
142+
| where term(title, "rings") and length(title) > 75
143+
| keep book_no, title;
144+
ignoreOrder:true
145+
146+
book_no:keyword | title:text
147+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
148+
;
149+
150+
termWithMultipleWhereClauses
151+
required_capability: term_function
152+
153+
from books
154+
| where term(title, "rings")
155+
| where term(title, "lord")
156+
| keep book_no, title;
157+
ignoreOrder:true
158+
159+
book_no:keyword | title:text
160+
2675 | The Lord of the Rings - Boxed Set
161+
2714 | Return of the King Being the Third Part of The Lord of the Rings
162+
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
163+
7140 | The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
164+
;
165+
166+
termWithMultivaluedField
167+
required_capability: term_function
168+
169+
from employees
170+
| where term(job_positions, "Data Scientist")
171+
| keep emp_no, first_name, last_name
172+
| sort emp_no asc
173+
| limit 2;
174+
ignoreOrder:true
175+
176+
emp_no:integer | first_name:keyword | last_name:keyword
177+
10014 | Berni | Genin
178+
10017 | Cristinel | Bouloucos
179+
;
180+
181+
testWithMultiValuedFieldWithConjunction
182+
required_capability: term_function
183+
184+
from employees
185+
| where term(job_positions, "Data Scientist") and term(first_name, "Cristinel")
186+
| keep emp_no, first_name, last_name
187+
| limit 1;
188+
189+
emp_no:integer | first_name:keyword | last_name:keyword
190+
10017 | Cristinel | Bouloucos
191+
;
192+
193+
termWithConjQueryStringFunctions
194+
required_capability: term_function
195+
required_capability: qstr_function
196+
197+
from employees
198+
| where term(job_positions, "Data Scientist") and qstr("first_name: Cristinel and gender: F")
199+
| keep emp_no, first_name, last_name
200+
| sort emp_no ASC
201+
| limit 1;
202+
ignoreOrder:true
203+
204+
emp_no:integer | first_name:keyword | last_name:keyword
205+
10017 | Cristinel | Bouloucos
206+
;

0 commit comments

Comments
 (0)