functions.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. [[eql-function-ref]]
  2. == EQL function reference
  3. ++++
  4. <titleabbrev>Function reference</titleabbrev>
  5. ++++
  6. experimental::[]
  7. {es} supports the following EQL functions:
  8. * <<eql-fn-endswith>>
  9. * <<eql-fn-startswith>>
  10. * <<eql-fn-substring>>
  11. [discrete]
  12. [[eql-fn-endswith]]
  13. === `endsWith`
  14. Returns `true` if a source string ends with a provided substring. Matching is
  15. case insensitive.
  16. [%collapsible]
  17. ====
  18. *Example*
  19. [source,eql]
  20. ----
  21. endsWith("regsvr32.exe", ".exe") // returns true
  22. endsWith("regsvr32.exe", ".EXE") // returns true
  23. endsWith("regsvr32.exe", ".dll") // returns false
  24. endsWith("", "") // returns true
  25. // file.name = "regsvr32.exe"
  26. endsWith(file.name, ".exe") // returns true
  27. endsWith(file.name, ".dll") // returns false
  28. // file.extension = ".exe"
  29. endsWith("regsvr32.exe", file.extension) // returns true
  30. endsWith("ntdll.dll", file.name) // returns false
  31. // file.name = [ "ntdll.dll", "regsvr32.exe" ]
  32. endsWith(file.name, ".dll") // returns true
  33. endsWith(file.name, ".exe") // returns false
  34. // null handling
  35. endsWith("regsvr32.exe", null) // returns null
  36. endsWith("", null) // returns null
  37. endsWith(null, ".exe") // returns null
  38. endsWith(null, null) // returns null
  39. ----
  40. *Syntax*
  41. [source,txt]
  42. ----
  43. endsWith(<source>, <substring>)
  44. ----
  45. *Parameters*
  46. `<source>`::
  47. +
  48. --
  49. (Required, string or `null`)
  50. Source string. If `null`, the function returns `null`.
  51. If using a field as the argument, this parameter only supports the following
  52. field datatypes:
  53. * <<keyword,`keyword`>>
  54. * <<constant-keyword,`constant_keyword`>>
  55. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  56. <<constant-keyword,`constant_keyword`>> sub-field
  57. Fields containing array values use the first array item only.
  58. --
  59. `<substring>`::
  60. +
  61. --
  62. (Required, string or `null`)
  63. Substring to search for. If `null`, the function returns `null`.
  64. If using a field as the argument, this parameter only supports the following
  65. field datatypes:
  66. * <<keyword,`keyword`>>
  67. * <<constant-keyword,`constant_keyword`>>
  68. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  69. <<constant-keyword,`constant_keyword`>> sub-field
  70. --
  71. *Returns:* boolean or `null`
  72. ====
  73. [discrete]
  74. [[eql-fn-startswith]]
  75. === `startsWith`
  76. Returns `true` if a source string begins with a provided substring. Matching is
  77. case insensitive.
  78. [%collapsible]
  79. ====
  80. *Example*
  81. [source,eql]
  82. ----
  83. startsWith("regsvr32.exe", "regsvr32") // returns true
  84. startsWith("regsvr32.exe", "RegSvr32") // returns true
  85. startsWith("regsvr32.exe", "explorer") // returns false
  86. startsWith("", "") // returns true
  87. // process.name = "regsvr32.exe"
  88. startsWith(process.name, "regsvr32") // returns true
  89. startsWith(process.name, "explorer") // returns false
  90. // process.name = "regsvr32"
  91. startsWith("regsvr32.exe", process.name) // returns true
  92. startsWith("explorer.exe", process.name) // returns false
  93. // process.name = [ "explorer.exe", "regsvr32.exe" ]
  94. startsWith(process.name, "explorer") // returns true
  95. startsWith(process.name, "regsvr32") // returns false
  96. // null handling
  97. startsWith("regsvr32.exe", null) // returns null
  98. startsWith("", null) // returns null
  99. startsWith(null, "regsvr32") // returns null
  100. startsWith(null, null) // returns null
  101. ----
  102. *Syntax*
  103. [source,txt]
  104. ----
  105. startsWith(<source>, <substring>)
  106. ----
  107. *Parameters*
  108. `<source>`::
  109. +
  110. --
  111. (Required, string or `null`)
  112. Source string. If `null`, the function returns `null`.
  113. If using a field as the argument, this parameter only supports the following
  114. field datatypes:
  115. * <<keyword,`keyword`>>
  116. * <<constant-keyword,`constant_keyword`>>
  117. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  118. <<constant-keyword,`constant_keyword`>> sub-field
  119. Fields containing array values use the first array item only.
  120. --
  121. `<substring>`::
  122. +
  123. --
  124. (Required, string or `null`)
  125. Substring to search for. If `null`, the function returns `null`.
  126. If using a field as the argument, this parameter only supports the following
  127. field datatypes:
  128. * <<keyword,`keyword`>>
  129. * <<constant-keyword,`constant_keyword`>>
  130. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  131. <<constant-keyword,`constant_keyword`>> sub-field
  132. --
  133. *Returns:* boolean or `null`
  134. ====
  135. [discrete]
  136. [[eql-fn-substring]]
  137. === `substring`
  138. Extracts a substring from a source string at provided start and end positions.
  139. If no end position is provided, the function extracts the remaining string.
  140. [%collapsible]
  141. ====
  142. *Example*
  143. [source,eql]
  144. ----
  145. substring("start regsvr32.exe", 6) // returns "regsvr32.exe"
  146. substring("start regsvr32.exe", 0, 5) // returns "start"
  147. substring("start regsvr32.exe", 6, 14) // returns "regsvr32"
  148. substring("start regsvr32.exe", -4) // returns ".exe"
  149. substring("start regsvr32.exe", -4, -1) // returns ".ex"
  150. ----
  151. *Syntax*
  152. [source,txt]
  153. ----
  154. substring(<source>, <start_pos>[, <end_pos>])
  155. ----
  156. *Parameters*
  157. `<source>`::
  158. (Required, string)
  159. Source string.
  160. `<start_pos>`::
  161. +
  162. --
  163. (Required, integer)
  164. Starting position for extraction.
  165. If this position is higher than the `<end_pos>` position or the length of the
  166. `<source>` string, the function returns an empty string.
  167. Positions are zero-indexed. Negative offsets are supported.
  168. --
  169. `<end_pos>`::
  170. (Optional, integer)
  171. Exclusive end position for extraction. If this position is not provided, the
  172. function returns the remaining string.
  173. +
  174. Positions are zero-indexed. Negative offsets are supported.
  175. *Returns:* string
  176. ====