Skip to content

Commit 8938100

Browse files
authored
[ES|QL] Add optional parameters support to KQL function (#135895)
1 parent 227bc08 commit 8938100

File tree

21 files changed

+798
-119
lines changed

21 files changed

+798
-119
lines changed

docs/changelog/135895.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 135895
2+
summary: Add optional parameters support to KQL function
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 135823

docs/reference/query-languages/esql/_snippets/functions/examples/kql.md

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

docs/reference/query-languages/esql/_snippets/functions/functionNamedParams/kql.md

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

docs/reference/query-languages/esql/_snippets/functions/layout/kql.md

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

docs/reference/query-languages/esql/_snippets/functions/parameters/kql.md

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

docs/reference/query-languages/esql/_snippets/functions/types/kql.md

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

docs/reference/query-languages/esql/images/functions/kql.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/reference/query-languages/esql/kibana/definition/functions/kql.json

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

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,106 @@ c: long | scalerank: long
287287
10 | 3
288288
15 | 2
289289
;
290+
291+
kqlWithOptions
292+
required_capability: kql_function
293+
required_capability: kql_function_options
294+
295+
296+
FROM employees
297+
| WHERE KQL("first_name: Mary", {"case_insensitive": false})
298+
| KEEP emp_no, first_name, last_name
299+
;
300+
301+
emp_no:integer | first_name:keyword | last_name:keyword
302+
10011 | Mary | Sluis
303+
;
304+
305+
kqlWithCaseInsensitiveOption
306+
required_capability: kql_function
307+
required_capability: kql_function_options
308+
309+
FROM employees
310+
| WHERE KQL("first_name: mary", {"case_insensitive": true})
311+
| KEEP emp_no, first_name, last_name
312+
;
313+
314+
emp_no:integer | first_name:keyword | last_name:keyword
315+
10011 | Mary | Sluis
316+
;
317+
318+
kqlWithTimeZoneOption
319+
required_capability: kql_function
320+
required_capability: kql_function_options
321+
322+
FROM logs
323+
| WHERE KQL("@timestamp > \"2023-10-23T09:56:00\" AND @timestamp < \"2023-10-23T09:57:00\"", {"time_zone": "America/New_York"})
324+
| KEEP @timestamp, message
325+
| SORT @timestamp ASC
326+
;
327+
328+
@timestamp:date | message:text
329+
2023-10-23T13:56:01.543Z | No response
330+
2023-10-23T13:56:01.544Z | Running cats (cycle 2)
331+
;
332+
333+
kqlWithDefaultFieldOption
334+
required_capability: kql_function
335+
required_capability: kql_function_options
336+
337+
FROM employees
338+
| WHERE KQL("Support Engineer", {"default_field": "job_positions"})
339+
| KEEP emp_no, first_name, last_name, job_positions
340+
| SORT emp_no
341+
| LIMIT 3
342+
;
343+
344+
emp_no:integer | first_name:keyword | last_name:keyword | job_positions:keyword
345+
10004 | Chirstian | Koblick | [Head Human Resources, Reporting Analyst, Support Engineer, Tech Lead]
346+
10015 | Guoxiang | Nooteboom | [Head Human Resources, Junior Developer, Principal Support Engineer, Support Engineer]
347+
10021 | Ramzi | Erde | Support Engineer
348+
;
349+
350+
kqlWithBoostOption
351+
required_capability: kql_function
352+
required_capability: kql_function_options
353+
354+
FROM employees METADATA _score
355+
| WHERE KQL("job_positions: Support Engineer", {"boost": 2.5})
356+
| KEEP emp_no, first_name, last_name, job_positions
357+
| SORT emp_no
358+
| LIMIT 3
359+
;
360+
361+
emp_no:integer | first_name:keyword | last_name:keyword | job_positions:keyword
362+
10004 | Chirstian | Koblick | [Head Human Resources, Reporting Analyst, Support Engineer, Tech Lead]
363+
10015 | Guoxiang | Nooteboom | [Head Human Resources, Junior Developer, Principal Support Engineer, Support Engineer]
364+
10021 | Ramzi | Erde | Support Engineer
365+
;
366+
367+
kqlWithMultipleOptions
368+
required_capability: kql_function
369+
required_capability: kql_function_options
370+
// tag::kql-with-options[]
371+
FROM employees
372+
| WHERE KQL("mary", {"case_insensitive": true, "default_field": "first_name", "boost": 1.5})
373+
// end::kql-with-options[]
374+
| KEEP emp_no, first_name, last_name
375+
;
376+
377+
emp_no:integer | first_name:keyword | last_name:keyword
378+
10011 | Mary | Sluis
379+
;
380+
381+
kqlWithWildcardDefaultField
382+
required_capability: kql_function
383+
required_capability: kql_function_options
384+
385+
FROM employees
386+
| WHERE KQL("Mary", {"default_field": "*_name"})
387+
| KEEP emp_no, first_name, last_name
388+
;
389+
390+
emp_no:integer | first_name:keyword | last_name:keyword
391+
10011 | Mary | Sluis
392+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,11 @@ public enum Cap {
734734
*/
735735
KQL_FUNCTION,
736736

737+
/**
738+
* Support for optional parameters in KQL function (case_insensitive, time_zone, default_field, boost).
739+
*/
740+
KQL_FUNCTION_OPTIONS,
741+
737742
/**
738743
* Hash function
739744
*/

0 commit comments

Comments
 (0)