Skip to content

Commit 883bb29

Browse files
authored
[DOCS] EQL: Document math functions (#55810)
Documents the following EQL functions: * `add` * `divide` * `module` * `multiply` * `subtract`
1 parent 7e7f754 commit 883bb29

File tree

2 files changed

+373
-3
lines changed

2 files changed

+373
-3
lines changed

docs/reference/eql/functions.asciidoc

Lines changed: 332 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,74 @@ experimental::[]
88

99
{es} supports the following EQL functions:
1010

11+
* <<eql-fn-add>>
1112
* <<eql-fn-between>>
1213
* <<eql-fn-cidrmatch>>
1314
* <<eql-fn-concat>>
15+
* <<eql-fn-divide>>
1416
* <<eql-fn-endswith>>
1517
* <<eql-fn-indexof>>
1618
* <<eql-fn-length>>
1719
* <<eql-fn-match>>
20+
* <<eql-fn-modulo>>
21+
* <<eql-fn-multiply>>
1822
* <<eql-fn-startswith>>
1923
* <<eql-fn-string>>
2024
* <<eql-fn-stringcontains>>
2125
* <<eql-fn-substring>>
26+
* <<eql-fn-subtract>>
2227
* <<eql-fn-wildcard>>
2328

29+
[discrete]
30+
[[eql-fn-add]]
31+
=== `add`
32+
Returns the sum of two provided addends.
33+
34+
[%collapsible]
35+
====
36+
*Example*
37+
[source,eql]
38+
----
39+
add(4, 5) // returns 9
40+
add(4, 0.5) // returns 4.5
41+
add(0.5, 0.25) // returns 0.75
42+
add(4, -2) // returns 2
43+
add(-2, -2) // returns -4
44+
45+
// process.args_count = 4
46+
add(process.args_count, 5) // returns 9
47+
add(process.args_count, 0.5) // returns 4.5
48+
49+
// process.parent.args_count = 2
50+
add(process.args_count, process.parent.args_count) // returns 6
51+
52+
// null handling
53+
add(null, 4) // returns null
54+
add(4. null) // returns null
55+
add(null, process.args_count) // returns null
56+
add(process.args_count null) // returns null
57+
----
58+
59+
*Syntax*
60+
[source,txt]
61+
----
62+
add(<addend>, <addend>)
63+
----
64+
65+
*Parameters:*
66+
67+
`<addend>`::
68+
(Required, integer or float or `null`)
69+
Addend to add. If `null`, the function returns `null`.
70+
+
71+
Two addends are required. No more than two addends can be provided.
72+
+
73+
If using a field as the argument, this parameter supports only
74+
<<number,`numeric`>> field datatypes.
75+
76+
*Returns:* integer, float, or `null`
77+
====
78+
2479
[discrete]
2580
[[eql-fn-between]]
2681
=== `between`
@@ -232,6 +287,111 @@ If using a field as the argument, this parameter does not support the
232287
*Returns:* string or `null`
233288
====
234289

290+
[discrete]
291+
[[eql-fn-divide]]
292+
==== `divide`
293+
Returns the quotient of a provided dividend and divisor.
294+
295+
[%collapsible]
296+
====
297+
298+
[[eql-divide-fn-float-rounding]]
299+
[WARNING]
300+
=====
301+
If both the dividend and divisor are integers, the `divide` function _rounds
302+
down_ any returned floating point numbers to the nearest integer.
303+
304+
EQL queries in {es} should account for this rounding. To avoid rounding, convert
305+
either the dividend or divisor to a float.
306+
307+
[%collapsible]
308+
.**Example**
309+
======
310+
The `process.args_count` field is a <<number,`long`>> integer field containing a
311+
count of process arguments.
312+
313+
A user might expect the following EQL query to only match events with a
314+
`process.args_count` value of `4`.
315+
316+
[source,eql]
317+
----
318+
process where divide(4, process.args_count) == 1
319+
----
320+
321+
However, the EQL query matches events with a `process.args_count` value of `3`
322+
or `4`.
323+
324+
For events with a `process.args_count` value of `3`, the `divide` function
325+
returns a floating point number of `1.333...`, which is rounded down to `1`.
326+
327+
To match only events with a `process.args_count` value of `4`, convert
328+
either the dividend or divisor to a float.
329+
330+
The following EQL query changes the integer `4` to the equivalent float `4.0`.
331+
332+
[source,eql]
333+
----
334+
process where divide(4.0, process.args_count) == 1
335+
----
336+
======
337+
=====
338+
339+
*Example*
340+
[source,eql]
341+
----
342+
divide(4, 2) // returns 2
343+
divide(4, 3) // returns 1
344+
divide(4, 3.0) // returns 1.333...
345+
divide(4, 0.5) // returns 8
346+
divide(0.5, 4) // returns 0.125
347+
divide(0.5, 0.25) // returns 2.0
348+
divide(4, -2) // returns -2
349+
divide(-4, -2) // returns 2
350+
351+
// process.args_count = 4
352+
divide(process.args_count, 2) // returns 2
353+
divide(process.args_count, 3) // returns 1
354+
divide(process.args_count, 3.0) // returns 1.333...
355+
divide(12, process.args_count) // returns 3
356+
divide(process.args_count, 0.5) // returns 8
357+
divide(0.5, process.args_count) // returns 0.125
358+
359+
// process.parent.args_count = 2
360+
divide(process.args_count, process.parent.args_count) // returns 2
361+
362+
// null handling
363+
divide(null, 4) // returns null
364+
divide(4, null) // returns null
365+
divide(null, process.args_count) // returns null
366+
divide(process.args_count, null) // returns null
367+
----
368+
369+
*Syntax*
370+
[source,txt]
371+
----
372+
divide(<dividend>, <divisor>)
373+
----
374+
375+
*Parameters*
376+
377+
`<dividend>`::
378+
(Required, integer or float or `null`)
379+
Dividend to divide. If `null`, the function returns `null`.
380+
+
381+
If using a field as the argument, this parameter supports only
382+
<<number,`numeric`>> field datatypes.
383+
384+
`<divisor>`::
385+
(Required, integer or float or `null`)
386+
Divisor to divide by. If `null`, the function returns `null`. This value cannot
387+
be zero (`0`).
388+
+
389+
If using a field as the argument, this parameter supports only
390+
<<number,`numeric`>> field datatypes.
391+
392+
*Returns:* integer, float, or null
393+
====
394+
235395
[discrete]
236396
[[eql-fn-endswith]]
237397
=== `endsWith`
@@ -261,7 +421,7 @@ endsWith(file.name, ".exe") // returns false
261421
262422
// null handling
263423
endsWith("regsvr32.exe", null) // returns null
264-
endsWith("", null) // returns null
424+
endsWith("", null) // returns null
265425
endsWith(null, ".exe") // returns null
266426
endsWith(null, null) // returns null
267427
----
@@ -532,6 +692,119 @@ Fields are not supported as arguments.
532692
*Returns:* boolean or `null`
533693
====
534694

695+
[discrete]
696+
[[eql-fn-modulo]]
697+
=== `modulo`
698+
Returns the remainder of the division of a provided dividend and divisor.
699+
700+
[%collapsible]
701+
====
702+
*Example*
703+
[source,eql]
704+
----
705+
modulo(10, 6) // returns 4
706+
modulo(10, 5) // returns 0
707+
modulo(10, 0.5) // returns 0
708+
modulo(10, -6) // returns 4
709+
modulo(-10, -6) // returns -4
710+
711+
// process.args_count = 10
712+
modulo(process.args_count, 6) // returns 4
713+
modulo(process.args_count, 5) // returns 0
714+
modulo(106, process.args_count) // returns 6
715+
modulo(process.args_count, -6) // returns 4
716+
modulo(process.args_count, 0.5) // returns 0
717+
718+
// process.parent.args_count = 6
719+
add(process.args_count, process.parent.args_count) // returns 4
720+
721+
// null handling
722+
modulo(null, 5) // returns null
723+
modulo(7, null) // returns null
724+
modulo(null, process.args_count) // returns null
725+
modulo(process.args_count, null) // returns null
726+
----
727+
728+
*Syntax*
729+
[source,txt]
730+
----
731+
modulo(<dividend>, <divisor>)
732+
----
733+
734+
*Parameters*
735+
736+
`<dividend>`::
737+
(Required, integer or float or `null`)
738+
Dividend to divide. If `null`, the function returns `null`. Floating point
739+
numbers return `0`.
740+
+
741+
If using a field as the argument, this parameter supports only
742+
<<number,`numeric`>> field datatypes.
743+
744+
`<divisor>`::
745+
(Required, integer or float or `null`)
746+
Divisor to divide by. If `null`, the function returns `null`. Floating point
747+
numbers return `0`. This value cannot be zero (`0`).
748+
+
749+
If using a field as the argument, this parameter supports only
750+
<<number,`numeric`>> field datatypes.
751+
752+
*Returns:* integer, float, or `null`
753+
====
754+
755+
[discrete]
756+
[[eql-fn-multiply]]
757+
=== `multiply`
758+
759+
Returns the product of two provided factors.
760+
761+
[%collapsible]
762+
====
763+
*Example*
764+
[source,eql]
765+
----
766+
multiply(2, 2) // returns 4
767+
multiply(0.5, 2) // returns 1
768+
multiply(0.25, 2) // returns 0.5
769+
multiply(-2, 2) // returns -4
770+
multiply(-2, -2) // returns 4
771+
772+
// process.args_count = 2
773+
multiply(process.args_count, 2) // returns 4
774+
multiply(0.5, process.args_count) // returns 1
775+
multiply(0.25, process.args_count) // returns 0.5
776+
777+
// process.parent.args_count = 3
778+
multiply(process.args_count, process.parent.args_count) // returns 6
779+
780+
// null handling
781+
multiply(null, 2) // returns null
782+
multiply(2, null) // returns null
783+
----
784+
785+
*Syntax*
786+
[source,txt]
787+
----
788+
multiply(<factor, <factor>)
789+
----
790+
791+
*Parameters*
792+
793+
`<factor>`::
794+
+
795+
--
796+
(Required, integer or float or `null`)
797+
Factor to multiply. If `null`, the function returns `null`.
798+
799+
Two factors are required. No more than two factors can be provided.
800+
801+
If using a field as the argument, this parameter supports only
802+
<<number,`numeric`>> field datatypes.
803+
--
804+
805+
*Returns:* integer, float, or `null`
806+
====
807+
535808
[discrete]
536809
[[eql-fn-startswith]]
537810
=== `startsWith`
@@ -561,7 +834,7 @@ startsWith(process.name, "regsvr32") // returns false
561834
562835
// null handling
563836
startsWith("regsvr32.exe", null) // returns null
564-
startsWith("", null) // returns null
837+
startsWith("", null) // returns null
565838
startsWith(null, "regsvr32") // returns null
566839
startsWith(null, null) // returns null
567840
----
@@ -764,9 +1037,65 @@ Positions are zero-indexed. Negative offsets are supported.
7641037
*Returns:* string
7651038
====
7661039

1040+
[discrete]
1041+
[[eql-fn-subtract]]
1042+
=== `subtract`
1043+
Returns the difference between a provided minuend and subtrahend.
1044+
1045+
[%collapsible]
1046+
====
1047+
*Example*
1048+
[source,eql]
1049+
----
1050+
subtract(10, 2) // returns 8
1051+
subtract(10.5, 0.5) // returns 10
1052+
subtract(1, 0.2) // returns 0.8
1053+
subtract(-2, 4) // returns -8
1054+
subtract(-2, -4) // returns 8
1055+
1056+
// process.args_count = 10
1057+
subtract(process.args_count, 6) // returns 4
1058+
subtract(process.args_count, 5) // returns 5
1059+
subtract(15, process.args_count) // returns 5
1060+
subtract(process.args_count, 0.5) // returns 9.5
1061+
1062+
// process.parent.args_count = 6
1063+
subtract(process.args_count, process.parent.args_count) // returns 4
1064+
1065+
// null handling
1066+
subtract(null, 2) // returns null
1067+
subtract(2, null) // returns null
1068+
----
1069+
1070+
*Syntax*
1071+
[source,txt]
1072+
----
1073+
subtract(<minuend>, <subtrahend>)
1074+
----
1075+
1076+
*Parameters*
1077+
1078+
`<minuend>`::
1079+
(Required, integer or float or `null`)
1080+
Minuend to subtract from.
1081+
+
1082+
If using a field as the argument, this parameter supports only
1083+
<<number,`numeric`>> field datatypes.
1084+
1085+
`<subtrahend>`::
1086+
(Optional, integer or float or `null`)
1087+
Subtrahend to subtract. If `null`, the function returns `null`.
1088+
+
1089+
If using a field as the argument, this parameter supports only
1090+
<<number,`numeric`>> field datatypes.
1091+
1092+
*Returns:* integer, float, or `null`
1093+
====
1094+
7671095
[discrete]
7681096
[[eql-fn-wildcard]]
7691097
=== `wildcard`
1098+
7701099
Returns `true` if a source string matches one or more provided wildcard
7711100
expressions.
7721101

@@ -824,7 +1153,7 @@ field datatypes:
8241153
(Required{multi-arg-ref}, string)
8251154
Wildcard expression used to match the source string. If `null`, the function
8261155
returns `null`. Fields are not supported as arguments.
827-
--
1156+
--
8281157
8291158
*Returns:* boolean
8301159
====

0 commit comments

Comments
 (0)