syntax.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[eql-syntax]]
  4. == EQL syntax reference
  5. experimental::[]
  6. [IMPORTANT]
  7. ====
  8. {es} supports a subset of EQL syntax.
  9. ====
  10. [discrete]
  11. [[eql-basic-syntax]]
  12. === Basic syntax
  13. EQL queries require an event category and a matching condition. The `where`
  14. keyword connects them.
  15. [source,eql]
  16. ----
  17. event_category where condition
  18. ----
  19. For example, the following EQL query matches `process` events with a
  20. `process.name` field value of `svchost.exe`:
  21. [source,eql]
  22. ----
  23. process where process.name == "svchost.exe"
  24. ----
  25. [discrete]
  26. [[eql-syntax-event-categories]]
  27. ==== Event categories
  28. In {es}, an event category is a valid, indexed value of the
  29. <<eql-required-fields,event category field>>. You can set the event category
  30. field using the `event_category_field` parameter of the EQL search API.
  31. [discrete]
  32. [[eql-syntax-match-any-event-category]]
  33. ===== Match any event category
  34. To match events of any category, use the `any` keyword. You can also use the
  35. `any` keyword to search for documents without a event category field.
  36. For example, the following EQL query matches any documents with a
  37. `network.protocol` field value of `http`:
  38. [source,eql]
  39. ----
  40. any where network.protocol == "http"
  41. ----
  42. [discrete]
  43. [[eql-syntax-conditions]]
  44. ==== Conditions
  45. A condition consists of one or more criteria an event must match.
  46. You can specify and combine these criteria using the following operators:
  47. [discrete]
  48. [[eql-syntax-comparison-operators]]
  49. ===== Comparison operators
  50. [source,eql]
  51. ----
  52. < <= == != >= >
  53. ----
  54. .*Definitions*
  55. [%collapsible]
  56. ====
  57. `<` (less than)::
  58. Returns `true` if the value to the left of the operator is less than the value
  59. to the right. Otherwise returns `false`.
  60. `<=` (less than or equal) ::
  61. Returns `true` if the value to the left of the operator is less than or equal to
  62. the value to the right. Otherwise returns `false`.
  63. `==` (equal)::
  64. Returns `true` if the values to the left and right of the operator are equal.
  65. Otherwise returns `false`.
  66. `!=` (not equal)::
  67. Returns `true` if the values to the left and right of the operator are not
  68. equal. Otherwise returns `false`.
  69. `>=` (greater than or equal) ::
  70. Returns `true` if the value to the left of the operator is greater than or equal
  71. to the value to the right. Otherwise returns `false`.
  72. `>` (greater than)::
  73. Returns `true` if the value to the left of the operator is greater than the
  74. value to the right. Otherwise returns `false`.
  75. ====
  76. [discrete]
  77. [[eql-syntax-logical-operators]]
  78. ===== Logical operators
  79. [source,eql]
  80. ----
  81. and or not
  82. ----
  83. .*Definitions*
  84. [%collapsible]
  85. ====
  86. `and`::
  87. Returns `true` only if the condition to the left and right _both_ return `true`.
  88. Otherwise returns `false.
  89. `or`::
  90. Returns `true` if one of the conditions to the left or right `true`.
  91. Otherwise returns `false.
  92. `not`::
  93. Returns `true` if the condition to the right is `false`.
  94. ====
  95. [discrete]
  96. [[eql-syntax-lookup-operators]]
  97. ===== Lookup operators
  98. [source,eql]
  99. ----
  100. user.name in ("Administrator", "SYSTEM", "NETWORK SERVICE")
  101. user.name not in ("Administrator", "SYSTEM", "NETWORK SERVICE")
  102. ----
  103. .*Definitions*
  104. [%collapsible]
  105. ====
  106. `in`::
  107. Returns `true` if the value is contained in the provided list.
  108. `not in`::
  109. Returns `true` if the value is not contained in the provided list.
  110. ====
  111. [discrete]
  112. [[eql-syntax-math-operators]]
  113. ===== Math operators
  114. [source,eql]
  115. ----
  116. + - * / %
  117. ----
  118. .*Definitions*
  119. [%collapsible]
  120. ====
  121. `+` (add)::
  122. Adds the values to the left and right of the operator.
  123. `-` (Subtract)::
  124. Subtracts the value to the right of the operator from the value to the left.
  125. `*` (Subtract)::
  126. Multiplies the values to the left and right of the operator.
  127. `/` (Divide)::
  128. Divides the value to the left of the operator by the value to the right.
  129. `%` (modulo)::
  130. Divides the value to the left of the operator by the value to the right. Returns only the remainder.
  131. ====
  132. [discrete]
  133. [[eql-syntax-strings]]
  134. ==== Strings
  135. Strings are enclosed with double quotes (`"`) or single quotes (`'`).
  136. [source,eql]
  137. ----
  138. "hello world"
  139. "hello world with 'substring'"
  140. ----
  141. [discrete]
  142. [[eql-syntax-wildcards]]
  143. ===== Wildcards
  144. You can use the wildcard operator (`*`) within a string to match specific
  145. patterns. You can use wildcards with the `==` (equal) or `!=` (not equal)
  146. operators:
  147. [source,eql]
  148. ----
  149. field == "example*wildcard"
  150. field != "example*wildcard"
  151. ----
  152. [discrete]
  153. [[eql-syntax-match-any-condition]]
  154. ===== Match any condition
  155. To match events solely on event category, use the `where true` condition.
  156. For example, the following EQL query matches any `file` events:
  157. [source,eql]
  158. ----
  159. file where true
  160. ----
  161. To match any event, you can combine the `any` keyword with the `where true`
  162. condition:
  163. [source,eql]
  164. ----
  165. any where true
  166. ----
  167. [discrete]
  168. [[eql-syntax-escaped-characters]]
  169. ===== Escaped characters
  170. When used within a string, special characters, such as a carriage return or
  171. double quote (`"`), must be escaped with a preceding backslash (`\`).
  172. [source,eql]
  173. ----
  174. "example \t of \n escaped \r characters"
  175. ----
  176. .*Escape sequences*
  177. [%collapsible]
  178. ====
  179. [options="header"]
  180. |====
  181. | Escape sequence | Literal character
  182. |`\n` | A newline (linefeed) character
  183. |`\r` | A carriage return character
  184. |`\t` | A tab character
  185. |`\\` | A backslash (`\`) character
  186. |`\"` | A double quote (`"`) character
  187. |`\'` | A single quote (`'`) character
  188. |====
  189. ====
  190. [discrete]
  191. [[eql-syntax-raw-strings]]
  192. ===== Raw strings
  193. Raw strings are preceded by a question mark (`?`) and treat backslashes (`\`) as
  194. literal characters.
  195. [source,eql]
  196. ----
  197. ?"String with a literal 'blackslash' \ character included"
  198. ----
  199. You can escape single quotes (`'`) and double quotes (`"`) with a backslash, but
  200. the backslash remains in the resulting string.
  201. [source,eql]
  202. ----
  203. ?"\""
  204. ----
  205. [NOTE]
  206. ====
  207. Raw strings cannot contain only a single backslash. Additionally, raw strings
  208. cannot end in an odd number of backslashes.
  209. ====
  210. [discrete]
  211. [[eql-syntax-non-alpha-field-names]]
  212. ==== Non-alphanumeric field names
  213. Field names containing non-alphanumeric characters, such as underscores (`_`),
  214. dots (`.`), hyphens (`-`), or spaces, must be escaped using backticks (+++`+++).
  215. [source,eql]
  216. ----
  217. `my_field`
  218. `my.field`
  219. `my-field`
  220. `my field`
  221. ----