syntax.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 type and a matching condition. The `where` keyword connects them.
  14. [source,eql]
  15. ----
  16. event_type where condition
  17. ----
  18. For example, the following EQL query matches `process` events with a `process.name`
  19. field value of `svchost.exe`:
  20. [source,eql]
  21. ----
  22. process where process.name == "svchost.exe"
  23. ----
  24. [discrete]
  25. [[eql-syntax-conditions]]
  26. ==== Conditions
  27. A condition consists of one or more criteria an event must match.
  28. You can specify and combine these criteria using the following operators:
  29. [discrete]
  30. [[eql-syntax-comparison-operators]]
  31. ===== Comparison operators
  32. [source,eql]
  33. ----
  34. < <= == != >= >
  35. ----
  36. .*Definitions*
  37. [%collapsible]
  38. ====
  39. `<` (less than)::
  40. Returns `true` if the value to the left of the operator is less than the value
  41. to the right. Otherwise returns `false`.
  42. `<=` (less than or equal) ::
  43. Returns `true` if the value to the left of the operator is less than or equal to
  44. the value to the right. Otherwise returns `false`.
  45. `==` (equal)::
  46. Returns `true` if the values to the left and right of the operator are equal.
  47. Otherwise returns `false`.
  48. `!=` (not equal)::
  49. Returns `true` if the values to the left and right of the operator are not
  50. equal. Otherwise returns `false`.
  51. `>=` (greater than or equal) ::
  52. Returns `true` if the value to the left of the operator is greater than or equal
  53. to the value to the right. Otherwise returns `false`.
  54. `>` (greater than)::
  55. Returns `true` if the value to the left of the operator is greater than the
  56. value to the right. Otherwise returns `false`.
  57. ====
  58. [discrete]
  59. [[eql-syntax-logical-operators]]
  60. ===== Logical operators
  61. [source,eql]
  62. ----
  63. and or not
  64. ----
  65. .*Definitions*
  66. [%collapsible]
  67. ====
  68. `and`::
  69. Returns `true` only if the condition to the left and right _both_ return `true`.
  70. Otherwise returns `false.
  71. `or`::
  72. Returns `true` if one of the conditions to the left or right `true`.
  73. Otherwise returns `false.
  74. `not`::
  75. Returns `true` if the condition to the right is `false`.
  76. ====
  77. [discrete]
  78. [[eql-syntax-lookup-operators]]
  79. ===== Lookup operators
  80. [source,eql]
  81. ----
  82. user.name in ("Administrator", "SYSTEM", "NETWORK SERVICE")
  83. user.name not in ("Administrator", "SYSTEM", "NETWORK SERVICE")
  84. ----
  85. .*Definitions*
  86. [%collapsible]
  87. ====
  88. `in`::
  89. Returns `true` if the value is contained in the provided list.
  90. `not in`::
  91. Returns `true` if the value is not contained in the provided list.
  92. ====
  93. [discrete]
  94. [[eql-syntax-math-operators]]
  95. ===== Math operators
  96. [source,eql]
  97. ----
  98. + - * / %
  99. ----
  100. .*Definitions*
  101. [%collapsible]
  102. ====
  103. `+` (add)::
  104. Adds the values to the left and right of the operator.
  105. `-` (Subtract)::
  106. Subtracts the value to the right of the operator from the value to the left.
  107. `*` (Subtract)::
  108. Multiplies the values to the left and right of the operator.
  109. `/` (Divide)::
  110. Divides the value to the left of the operator by the value to the right.
  111. `%` (modulo)::
  112. Divides the value to the left of the operator by the value to the right. Returns only the remainder.
  113. ====
  114. [discrete]
  115. [[eql-syntax-strings]]
  116. ==== Strings
  117. Strings are enclosed with double quotes (`"`) or single quotes (`'`).
  118. [source,eql]
  119. ----
  120. "hello world"
  121. "hello world with 'substring'"
  122. ----
  123. [discrete]
  124. [[eql-syntax-wildcards]]
  125. ===== Wildcards
  126. You can use the wildcard operator (`*`) within a string to match specific
  127. patterns. You can use wildcards with the `==` (equal) or `!=` (not equal)
  128. operators:
  129. [source,eql]
  130. ----
  131. field == "example*wildcard"
  132. field != "example*wildcard"
  133. ----
  134. [discrete]
  135. [[eql-syntax-escaped-characters]]
  136. ===== Escaped characters
  137. When used within a string, special characters, such as a carriage return or
  138. double quote (`"`), must be escaped with a preceding backslash (`\`).
  139. [source,eql]
  140. ----
  141. "example \t of \n escaped \r characters"
  142. ----
  143. .*Escape sequences*
  144. [%collapsible]
  145. ====
  146. [options="header"]
  147. |====
  148. | Escape sequence | Literal character
  149. |`\n` | A newline (linefeed) character
  150. |`\r` | A carriage return character
  151. |`\t` | A tab character
  152. |`\\` | A backslash (`\`) character
  153. |`\"` | A double quote (`"`) character
  154. |`\'` | A single quote (`'`) character
  155. |====
  156. ====
  157. [discrete]
  158. [[eql-syntax-raw-strings]]
  159. ===== Raw strings
  160. Raw strings are preceded by a question mark (`?`) and treat backslashes (`\`) as
  161. literal characters.
  162. [source,eql]
  163. ----
  164. ?"String with a literal 'blackslash' \ character included"
  165. ----
  166. You can escape single quotes (`'`) and double quotes (`"`) with a backslash, but
  167. the backslash remains in the resulting string.
  168. [source,eql]
  169. ----
  170. ?"\""
  171. ----
  172. [NOTE]
  173. ====
  174. Raw strings cannot contain only a single backslash. Additionally, raw strings
  175. cannot end in an odd number of backslashes.
  176. ====
  177. [discrete]
  178. [[eql-syntax-non-alpha-field-names]]
  179. ==== Non-alphanumeric field names
  180. Field names containing non-alphanumeric characters, such as underscores (`_`),
  181. dots (`.`), hyphens (`-`), or spaces, must be escaped using backticks (+++`+++).
  182. [source,eql]
  183. ----
  184. `my_field`
  185. `my.field`
  186. `my-field`
  187. `my field`
  188. ----