Skip to content

Commit

Permalink
Term query for ES|QL (elastic#117359)
Browse files Browse the repository at this point in the history
This commit adds a `term` function for ES|QL to run `TermQueries`.

For example:
FROM test | WHERE term(content, "dog")
  • Loading branch information
tteofili authored Dec 6, 2024
1 parent 7bd5c69 commit 9160586
Show file tree
Hide file tree
Showing 23 changed files with 883 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/117359.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 117359
summary: Term query for ES|QL
area: ES|QL
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/description/term.asciidoc

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

13 changes: 13 additions & 0 deletions docs/reference/esql/functions/examples/term.asciidoc

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

85 changes: 85 additions & 0 deletions docs/reference/esql/functions/kibana/definition/term.json

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

13 changes: 13 additions & 0 deletions docs/reference/esql/functions/kibana/docs/term.md

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

17 changes: 17 additions & 0 deletions docs/reference/esql/functions/layout/term.asciidoc

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

9 changes: 9 additions & 0 deletions docs/reference/esql/functions/parameters/term.asciidoc

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

1 change: 1 addition & 0 deletions docs/reference/esql/functions/signature/term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/reference/esql/functions/types/term.asciidoc

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
###############################################
# Tests for Term function
#

termWithTextField
required_capability: term_function

// tag::term-with-field[]
FROM books
| WHERE TERM(author, "gabriel")
| KEEP book_no, title
| LIMIT 3;
// end::term-with-field[]
ignoreOrder:true

book_no:keyword | title:text
4814 | El Coronel No Tiene Quien Le Escriba / No One Writes to the Colonel (Spanish Edition)
4917 | Autumn of the Patriarch
6380 | La hojarasca (Spanish Edition)
;

termWithKeywordField
required_capability: term_function

from employees
| where term(first_name, "Guoxiang")
| keep emp_no, first_name;

// tag::term-with-keyword-field-result[]
emp_no:integer | first_name:keyword
10015 | Guoxiang
;
// end::term-with-keyword-field-result[]

termWithQueryExpressions
required_capability: term_function

from books
| where term(author, CONCAT("gab", "riel"))
| keep book_no, title;
ignoreOrder:true

book_no:keyword | title:text
4814 | El Coronel No Tiene Quien Le Escriba / No One Writes to the Colonel (Spanish Edition)
4917 | Autumn of the Patriarch
6380 | La hojarasca (Spanish Edition)
;

termAfterKeep
required_capability: term_function

from books
| keep book_no, author
| where term(author, "faulkner")
| sort book_no
| limit 5;

book_no:keyword | author:text
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
2713 | William Faulkner
2847 | Colleen Faulkner
2883 | William Faulkner
3293 | Danny Faulkner
;

termAfterDrop
required_capability: term_function

from books
| drop ratings, description, year, publisher, title, author.keyword
| where term(author, "william")
| keep book_no, author
| sort book_no
| limit 2;

book_no:keyword | author:text
2713 | William Faulkner
2883 | William Faulkner
;

termAfterEval
required_capability: term_function

from books
| eval stars = to_long(ratings / 2.0)
| where term(author, "colleen")
| sort book_no
| keep book_no, author, stars
| limit 2;

book_no:keyword | author:text | stars:long
2847 | Colleen Faulkner | 3
4502 | Colleen Faulkner | 3
;

termWithConjunction
required_capability: term_function

from books
| where term(author, "tolkien") and ratings > 4.95
| eval author = mv_sort(author)
| keep book_no, ratings, author;
ignoreOrder:true

book_no:keyword | ratings:double | author:keyword
2301 | 5.0 | John Ronald Reuel Tolkien
3254 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
7350 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
;

termWithConjunctionAndSort
required_capability: term_function

from books
| where term(author, "tolkien") and ratings > 4.95
| eval author = mv_sort(author)
| keep book_no, ratings, author
| sort book_no;

book_no:keyword | ratings:double | author:keyword
2301 | 5.0 | John Ronald Reuel Tolkien
3254 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
7350 | 5.0 | [Christopher Tolkien, John Ronald Reuel Tolkien]
;

termWithFunctionPushedToLucene
required_capability: term_function

from hosts
| where term(host, "beta") and cidr_match(ip1, "127.0.0.2/32", "127.0.0.3/32")
| keep card, host, ip0, ip1;
ignoreOrder:true

card:keyword |host:keyword |ip0:ip |ip1:ip
eth1 |beta |127.0.0.1 |127.0.0.2
;

termWithNonPushableConjunction
required_capability: term_function

from books
| where term(title, "rings") and length(title) > 75
| keep book_no, title;
ignoreOrder:true

book_no:keyword | title:text
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
;

termWithMultipleWhereClauses
required_capability: term_function

from books
| where term(title, "rings")
| where term(title, "lord")
| keep book_no, title;
ignoreOrder:true

book_no:keyword | title:text
2675 | The Lord of the Rings - Boxed Set
2714 | Return of the King Being the Third Part of The Lord of the Rings
4023 | A Tolkien Compass: Including J. R. R. Tolkien's Guide to the Names in The Lord of the Rings
7140 | The Lord of the Rings Poster Collection: Six Paintings by Alan Lee (No. 1)
;

termWithMultivaluedField
required_capability: term_function

from employees
| where term(job_positions, "Data Scientist")
| keep emp_no, first_name, last_name
| sort emp_no asc
| limit 2;
ignoreOrder:true

emp_no:integer | first_name:keyword | last_name:keyword
10014 | Berni | Genin
10017 | Cristinel | Bouloucos
;

testWithMultiValuedFieldWithConjunction
required_capability: term_function

from employees
| where term(job_positions, "Data Scientist") and term(first_name, "Cristinel")
| keep emp_no, first_name, last_name
| limit 1;

emp_no:integer | first_name:keyword | last_name:keyword
10017 | Cristinel | Bouloucos
;

termWithConjQueryStringFunctions
required_capability: term_function
required_capability: qstr_function

from employees
| where term(job_positions, "Data Scientist") and qstr("first_name: Cristinel and gender: F")
| keep emp_no, first_name, last_name
| sort emp_no ASC
| limit 1;
ignoreOrder:true

emp_no:integer | first_name:keyword | last_name:keyword
10017 | Cristinel | Bouloucos
;
Loading

0 comments on commit 9160586

Please sign in to comment.