syntax.asciidoc 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[eql-syntax]]
  4. == EQL syntax reference
  5. ++++
  6. <titleabbrev>Syntax reference</titleabbrev>
  7. ++++
  8. [discrete]
  9. [[eql-basic-syntax]]
  10. === Basic syntax
  11. EQL queries require an event category and a matching condition. The `where`
  12. keyword connects them.
  13. [source,eql]
  14. ----
  15. event_category where condition
  16. ----
  17. For example, the following EQL query matches `process` events with a
  18. `process.name` field value of `svchost.exe`:
  19. [source,eql]
  20. ----
  21. process where process.name == "svchost.exe"
  22. ----
  23. [discrete]
  24. [[eql-syntax-event-categories]]
  25. === Event categories
  26. An event category is a valid, indexed value of the
  27. <<eql-required-fields,event category field>>. You can set the event category
  28. field using the `event_category_field` parameter of the EQL search API.
  29. [discrete]
  30. [[eql-syntax-match-any-event-category]]
  31. === Match any event category
  32. To match events of any category, use the `any` keyword. You can also use the
  33. `any` keyword to search for documents without a event category field.
  34. For example, the following EQL query matches any documents with a
  35. `network.protocol` field value of `http`:
  36. [source,eql]
  37. ----
  38. any where network.protocol == "http"
  39. ----
  40. [discrete]
  41. [[eql-syntax-escape-an-event-category]]
  42. === Escape an event category
  43. Use enclosing double quotes (`"`) or three enclosing double quotes (`"""`) to
  44. escape event categories that:
  45. * Contain a special character, such as a hyphen (`-`) or dot (`.`)
  46. * Contain a space
  47. * Start with a numeral
  48. [source,eql]
  49. ----
  50. ".my.event.category"
  51. "my-event-category"
  52. "my event category"
  53. "6eventcategory"
  54. """.my.event.category"""
  55. """my-event-category"""
  56. """my event category"""
  57. """6eventcategory"""
  58. ----
  59. [discrete]
  60. [[eql-syntax-escape-a-field-name]]
  61. === Escape a field name
  62. Use enclosing backticks (+++`+++) to escape field names that:
  63. * Contain a hyphen (`-`)
  64. * Contain a space
  65. * Start with a numeral
  66. [source,eql]
  67. ----
  68. `my-field`
  69. `my field`
  70. `6myfield`
  71. ----
  72. Use double backticks (+++``+++) to escape any backticks (+++`+++) in the field
  73. name.
  74. [source,eql]
  75. ----
  76. my`field -> `my``field`
  77. ----
  78. [discrete]
  79. [[eql-syntax-conditions]]
  80. === Conditions
  81. A condition consists of one or more criteria an event must match.
  82. You can specify and combine these criteria using the following operators. Most
  83. EQL operators are case-sensitive by default.
  84. [discrete]
  85. [[eql-syntax-comparison-operators]]
  86. === Comparison operators
  87. [source,eql]
  88. ----
  89. < <= == : != >= >
  90. ----
  91. `<` (less than)::
  92. Returns `true` if the value to the left of the operator is less than the value
  93. to the right. Otherwise returns `false`.
  94. `<=` (less than or equal) ::
  95. Returns `true` if the value to the left of the operator is less than or equal to
  96. the value to the right. Otherwise returns `false`.
  97. `==` (equal, case-sensitive)::
  98. Returns `true` if the values to the left and right of the operator are equal.
  99. Otherwise returns `false`. Wildcards are not supported.
  100. `:` (equal, case-insensitive)::
  101. Returns `true` if strings to the left and right of the operator are equal.
  102. Otherwise returns `false`. Can only be used to compare strings. Supports
  103. <<eql-syntax-wildcards,wildcards>> and <<eql-syntax-lookup-operators,list
  104. lookups>>.
  105. `!=` (not equal, case-sensitive)::
  106. Returns `true` if the values to the left and right of the operator are not
  107. equal. Otherwise returns `false`. Wildcards are not supported.
  108. `>=` (greater than or equal) ::
  109. Returns `true` if the value to the left of the operator is greater than or equal
  110. to the value to the right. Otherwise returns `false`. When comparing strings,
  111. the operator uses a case-sensitive lexicographic order.
  112. `>` (greater than)::
  113. Returns `true` if the value to the left of the operator is greater than the
  114. value to the right. Otherwise returns `false`. When comparing strings,
  115. the operator uses a case-sensitive lexicographic order.
  116. NOTE: `=` is not supported as an equal operator. Use `==` or `:` instead.
  117. [discrete]
  118. [[eql-syntax-pattern-comparison-keywords]]
  119. === Pattern comparison keywords
  120. [source,eql]
  121. ----
  122. my_field like "VALUE*" // case-sensitive wildcard matching
  123. my_field like~ "value*" // case-insensitive wildcard matching
  124. my_field regex "VALUE[^Z].?" // case-sensitive regex matching
  125. my_field regex~ "value[^z].?" // case-insensitive regex matching
  126. ----
  127. `like` (case-sensitive)::
  128. Returns `true` if the string to the left of the keyword matches a
  129. <<eql-syntax-wildcards,wildcard pattern>> to the right. Supports
  130. <<eql-syntax-lookup-operators,list lookups>>. Can only be used to compare
  131. strings. For case-insensitive matching, use `like~`.
  132. `regex` (case-sensitive)::
  133. Returns `true` if the string to the left of the keyword matches a regular
  134. expression to the right. For supported regular expression syntax, see
  135. <<regexp-syntax>>. Supports <<eql-syntax-lookup-operators,list lookups>>. Can
  136. only be used to compare strings. For case-insensitive matching, use `regex~`.
  137. [discrete]
  138. [[limitations-for-comparisons]]
  139. === Limitations for comparisons
  140. You cannot chain comparisons. Instead, use a
  141. <<eql-syntax-logical-operators,logical operator>> between comparisons. For
  142. example, `foo < bar <= baz` is not supported. However, you can rewrite the
  143. expression as `foo < bar and bar <= baz`, which is supported.
  144. You also cannot compare a field to another field, even if the fields are changed
  145. using a <<eql-functions,function>>.
  146. *Example* +
  147. The following EQL query compares the `process.parent_name` field
  148. value to a static value, `foo`. This comparison is supported.
  149. However, the query also compares the `process.parent.name` field value to the
  150. `process.name` field. This comparison is not supported and will return an
  151. error for the entire query.
  152. [source,eql]
  153. ----
  154. process where process.parent.name == "foo" and process.parent.name == process.name
  155. ----
  156. Instead, you can rewrite the query to compare both the `process.parent.name`
  157. and `process.name` fields to static values.
  158. [source,eql]
  159. ----
  160. process where process.parent.name == "foo" and process.name == "foo"
  161. ----
  162. [discrete]
  163. [[eql-syntax-logical-operators]]
  164. === Logical operators
  165. [source,eql]
  166. ----
  167. and or not
  168. ----
  169. `and`::
  170. Returns `true` only if the condition to the left and right _both_ return `true`.
  171. Otherwise returns `false`.
  172. `or`::
  173. Returns `true` if one of the conditions to the left or right `true`.
  174. Otherwise returns `false`.
  175. `not`::
  176. Returns `true` if the condition to the right is `false`.
  177. [discrete]
  178. [[eql-syntax-lookup-operators]]
  179. === Lookup operators
  180. [source,eql]
  181. ----
  182. my_field in ("Value-1", "VALUE2", "VAL3") // case-sensitive
  183. my_field in~ ("value-1", "value2", "val3") // case-insensitive
  184. my_field not in ("Value-1", "VALUE2", "VAL3") // case-sensitive
  185. my_field not in~ ("value-1", "value2", "val3") // case-insensitive
  186. my_field : ("value-1", "value2", "val3") // case-insensitive
  187. my_field like ("Value-*", "VALUE2", "VAL?") // case-sensitive
  188. my_field like~ ("value-*", "value2", "val?") // case-insensitive
  189. my_field regex ("[vV]alue-[0-9]", "VALUE[^2].?", "VAL3") // case-sensitive
  190. my_field regex~ ("value-[0-9]", "value[^2].?", "val3") // case-sensitive
  191. ----
  192. `in` (case-sensitive)::
  193. Returns `true` if the value is contained in the provided list. For
  194. case-insensitive matching, use `in~`.
  195. `not in` (case-sensitive)::
  196. Returns `true` if the value is not contained in the provided list. For
  197. case-insensitive matching, use `not in~`.
  198. `:` (case-insensitive)::
  199. Returns `true` if the string is contained in the provided list. Can only be used
  200. to compare strings.
  201. `like` (case-sensitive)::
  202. Returns `true` if the string matches a <<eql-syntax-wildcards,wildcard pattern>>
  203. in the provided list. Can only be used to compare strings. For case-insensitive
  204. matching, use `like~`.
  205. `regex` (case-sensitive)::
  206. Returns `true` if the string matches a regular expression pattern in the
  207. provided list. For supported regular expression syntax, see <<regexp-syntax>>.
  208. Can only be used to compare strings. For case-insensitive matching, use
  209. `regex~`.
  210. [discrete]
  211. [[eql-syntax-math-operators]]
  212. === Math operators
  213. [source,eql]
  214. ----
  215. + - * / %
  216. ----
  217. `+` (add)::
  218. Adds the values to the left and right of the operator.
  219. `-` (subtract)::
  220. Subtracts the value to the right of the operator from the value to the left.
  221. `*` (multiply)::
  222. Multiplies the values to the left and right of the operator.
  223. `/` (divide)::
  224. Divides the value to the left of the operator by the value to the right.
  225. +
  226. [[eql-divide-operator-float-rounding]]
  227. [WARNING]
  228. ====
  229. If both the dividend and divisor are integers, the divide (`\`) operation
  230. _rounds down_ any returned floating point numbers to the nearest integer. To
  231. avoid rounding, convert either the dividend or divisor to a float.
  232. *Example* +
  233. The `process.args_count` field is a <<number,`long`>> integer field containing a
  234. count of process arguments.
  235. A user might expect the following EQL query to only match events with a
  236. `process.args_count` value of `4`.
  237. [source,eql]
  238. ----
  239. process where ( 4 / process.args_count ) == 1
  240. ----
  241. However, the EQL query matches events with a `process.args_count` value of `3`
  242. or `4`.
  243. For events with a `process.args_count` value of `3`, the divide operation
  244. returns a float of `1.333...`, which is rounded down to `1`.
  245. To match only events with a `process.args_count` value of `4`, convert
  246. either the dividend or divisor to a float.
  247. The following EQL query changes the integer `4` to the equivalent float `4.0`.
  248. [source,eql]
  249. ----
  250. process where ( 4.0 / process.args_count ) == 1
  251. ----
  252. ====
  253. `%` (modulo)::
  254. Divides the value to the left of the operator by the value to the right. Returns only the remainder.
  255. [discrete]
  256. [[eql-syntax-match-any-condition]]
  257. === Match any condition
  258. To match events solely on event category, use the `where true` condition.
  259. For example, the following EQL query matches any `file` events:
  260. [source,eql]
  261. ----
  262. file where true
  263. ----
  264. To match any event, you can combine the `any` keyword with the `where true`
  265. condition:
  266. [source,eql]
  267. ----
  268. any where true
  269. ----
  270. [discrete]
  271. [[eql-syntax-check-field-exists]]
  272. === Check if a field exists
  273. To match events containing any value for a field, compare the field to `null`
  274. using the `!=` operator:
  275. [source,eql]
  276. ----
  277. my_field != null
  278. ----
  279. To match events that do not contain a field value, compare the field to `null`
  280. using the `==` operator:
  281. [source,eql]
  282. ----
  283. my_field == null
  284. ----
  285. IMPORTANT: To avoid errors, the field must contain a non-`null` value in at
  286. least one document or be <<explicit-mapping,explicitly mapped>>.
  287. [discrete]
  288. [[eql-syntax-strings]]
  289. === Strings
  290. Strings are enclosed in double quotes (`"`).
  291. [source,eql]
  292. ----
  293. "hello world"
  294. ----
  295. Strings enclosed in single quotes (`'`) are not supported.
  296. [discrete]
  297. [[eql-syntax-escape-characters]]
  298. === Escape characters in a string
  299. When used within a string, special characters, such as a carriage return or
  300. double quote (`"`), must be escaped with a preceding backslash (`\`).
  301. [source,eql]
  302. ----
  303. "example \r of \" escaped \n characters"
  304. ----
  305. [options="header"]
  306. |====
  307. | Escape sequence | Literal character
  308. |`\n` | A newline (linefeed) character
  309. |`\r` | A carriage return character
  310. |`\t` | A tab character
  311. |`\\` | A backslash (`\`) character
  312. |`\"` | A double quote (`"`) character
  313. |====
  314. IMPORTANT: The single quote (`'`) character is reserved for future use. You
  315. cannot use an escaped single quote (`\'`) for literal strings. Use an escaped
  316. double quote (`\"`) instead.
  317. [discrete]
  318. [[eql-syntax-raw-strings]]
  319. === Raw strings
  320. Raw strings treat special characters, such as backslashes (`\`), as literal
  321. characters. Raw strings are enclosed in three double quotes (`"""`).
  322. [source,eql]
  323. ----
  324. """Raw string with a literal double quote " and blackslash \ included"""
  325. ----
  326. A raw string cannot contain three consecutive double quotes (`"""`). Instead,
  327. use a regular string with the `\"` escape sequence.
  328. [source,eql]
  329. ----
  330. "String containing \"\"\" three double quotes"
  331. ----
  332. [discrete]
  333. [[eql-syntax-wildcards]]
  334. === Wildcards
  335. For string comparisons using the `:` operator or `like` keyword, you can use the
  336. `*` and `?` wildcards to match specific patterns. The `*` wildcard matches zero
  337. or more characters:
  338. [source,eql]
  339. ----
  340. my_field : "doc*" // Matches "doc", "docs", or "document" but not "DOS"
  341. my_field : "*doc" // Matches "adoc" or "asciidoc"
  342. my_field : "d*c" // Matches "doc" or "disc"
  343. my_field like "DOC*" // Matches "DOC", "DOCS", "DOCs", or "DOCUMENT" but not "DOS"
  344. my_field like "D*C" // Matches "DOC", "DISC", or "DisC"
  345. ----
  346. The `?` wildcard matches exactly one character:
  347. [source,eql]
  348. ----
  349. my_field : "doc?" // Matches "docs" but not "doc", "document", or "DOS"
  350. my_field : "?doc" // Matches "adoc" but not "asciidoc"
  351. my_field : "d?c" // Matches "doc" but not "disc"
  352. my_field like "DOC?" // Matches "DOCS" or "DOCs" but not "DOC", "DOCUMENT", or "DOS"
  353. my_field like "D?c" // Matches "DOC" but not "DISC"
  354. ----
  355. The `:` operator and `like` keyword also support wildcards in
  356. <<eql-syntax-lookup-operators,list lookups>>:
  357. [source,eql]
  358. ----
  359. my_field : ("doc*", "f*o", "ba?", "qux")
  360. my_field like ("Doc*", "F*O", "BA?", "QUX")
  361. ----
  362. [discrete]
  363. [[eql-sequences]]
  364. === Sequences
  365. You can use EQL sequences to describe and match an ordered series of events.
  366. Each item in a sequence is an event category and event condition,
  367. surrounded by square brackets (`[ ]`). Events are listed in ascending
  368. chronological order, with the most recent event listed last.
  369. [source,eql]
  370. ----
  371. sequence
  372. [ event_category_1 where condition_1 ]
  373. [ event_category_2 where condition_2 ]
  374. ...
  375. ----
  376. *Example* +
  377. The following EQL sequence query matches this series of ordered events:
  378. . Start with an event with:
  379. +
  380. --
  381. * An event category of `file`
  382. * A `file.extension` of `exe`
  383. --
  384. . Followed by an event with an event category of `process`
  385. [source,eql]
  386. ----
  387. sequence
  388. [ file where file.extension == "exe" ]
  389. [ process where true ]
  390. ----
  391. [discrete]
  392. [[eql-with-maxspan-keywords]]
  393. === `with maxspan` keywords
  394. You can use the `with maxspan` keywords to constrain a sequence to a specified
  395. timespan. All events in a matching sequence must occur within this duration,
  396. starting at the first event's timestamp.
  397. The `maxspan` keyword accepts <<time-units,time value>> arguments.
  398. [source,eql]
  399. ----
  400. sequence with maxspan=30s
  401. [ event_category_1 where condition_1 ] by field_baz
  402. [ event_category_2 where condition_2 ] by field_bar
  403. ...
  404. ----
  405. *Example* +
  406. The following sequence query uses a `maxspan` value of `15m` (15 minutes).
  407. Events in a matching sequence must occur within 15 minutes of the first event's
  408. timestamp.
  409. [source,eql]
  410. ----
  411. sequence with maxspan=15m
  412. [ file where file.extension == "exe" ]
  413. [ process where true ]
  414. ----
  415. [discrete]
  416. [[eql-by-keyword]]
  417. === `by` keyword
  418. You can use the `by` keyword with sequences to only match events that share the
  419. same field values. If a field value should be shared across all events, you
  420. can use `sequence by`.
  421. [source,eql]
  422. ----
  423. sequence by field_foo
  424. [ event_category_1 where condition_1 ] by field_baz
  425. [ event_category_2 where condition_2 ] by field_bar
  426. ...
  427. ----
  428. *Example* +
  429. The following sequence query uses the `by` keyword to constrain matching events
  430. to:
  431. * Events with the same `user.name` value
  432. * `file` events with a `file.path` value equal to the following `process`
  433. event's `process.path` value.
  434. [source,eql]
  435. ----
  436. sequence
  437. [ file where file.extension == "exe" ] by user.name, file.path
  438. [ process where true ] by user.name, process.path
  439. ----
  440. Because the `user.name` field is shared across all events in the sequence, it
  441. can be included using `sequence by`. The following sequence is equivalent to the
  442. prior one.
  443. [source,eql]
  444. ----
  445. sequence by user.name
  446. [ file where file.extension == "exe" ] by file.path
  447. [ process where true ] by process.path
  448. ----
  449. You can combine the `sequence by` and `with maxspan` keywords to constrain a
  450. sequence by both field values and a timespan.
  451. [source,eql]
  452. ----
  453. sequence by field_foo with maxspan=30s
  454. [ event_category_1 where condition_1 ] by field_baz
  455. [ event_category_2 where condition_2 ] by field_bar
  456. ...
  457. ----
  458. *Example* +
  459. The following sequence query uses the `sequence by` keyword and `with maxspan`
  460. keywords to match only a sequence of events that:
  461. * Share the same `user.name` field values
  462. * Occur within `15m` (15 minutes) of the first matching event
  463. [source,eql]
  464. ----
  465. sequence by user.name with maxspan=15m
  466. [ file where file.extension == "exe" ] by file.path
  467. [ process where true ] by process.path
  468. ----
  469. [discrete]
  470. [[eql-until-keyword]]
  471. === `until` keyword
  472. You can use the `until` keyword to specify an expiration event for a sequence.
  473. If this expiration event occurs _between_ matching events in a sequence, the
  474. sequence expires and is not considered a match. If the expiration event occurs
  475. _after_ matching events in a sequence, the sequence is still considered a
  476. match. The expiration event is not included in the results.
  477. [source,eql]
  478. ----
  479. sequence
  480. [ event_category_1 where condition_1 ]
  481. [ event_category_2 where condition_2 ]
  482. ...
  483. until [ event_category_3 where condition_3 ]
  484. ----
  485. *Example* +
  486. A dataset contains the following event sequences, grouped by shared IDs:
  487. [source,txt]
  488. ----
  489. A, B
  490. A, B, C
  491. A, C, B
  492. ----
  493. The following EQL query searches the dataset for sequences containing
  494. event `A` followed by event `B`. Event `C` is used as an expiration event.
  495. [source,eql]
  496. ----
  497. sequence by ID
  498. A
  499. B
  500. until C
  501. ----
  502. The query matches sequences `A, B` and `A, B, C` but not `A, C, B`.
  503. [TIP]
  504. ====
  505. The `until` keyword can be useful when searching for process sequences in
  506. Windows event logs.
  507. In Windows, a process ID (PID) is unique only while a process is running. After
  508. a process terminates, its PID can be reused.
  509. You can search for a sequence of events with the same PID value using the `by`
  510. and `sequence by` keywords.
  511. *Example* +
  512. The following EQL query uses the `sequence by` keyword to match a
  513. sequence of events that share the same `process.pid` value.
  514. [source,eql]
  515. ----
  516. sequence by process.pid
  517. [ process where event.type == "start" and process.name == "cmd.exe" ]
  518. [ process where file.extension == "exe" ]
  519. ----
  520. However, due to PID reuse, this can result in a matching sequence that
  521. contains events across unrelated processes. To prevent false positives, you can
  522. use the `until` keyword to end matching sequences before a process termination
  523. event.
  524. The following EQL query uses the `until` keyword to end sequences before
  525. `process` events with an `event.type` of `stop`. These events indicate a process
  526. has been terminated.
  527. [source,eql]
  528. ----
  529. sequence by process.pid
  530. [ process where event.type == "start" and process.name == "cmd.exe" ]
  531. [ process where file.extension == "exe" ]
  532. until [ process where event.type == "stop" ]
  533. ----
  534. ====
  535. [discrete]
  536. [[eql-functions]]
  537. === Functions
  538. You can use EQL functions to convert data types, perform math, manipulate
  539. strings, and more. For a list of supported functions, see <<eql-function-ref>>.
  540. [discrete]
  541. [[eql-case-insensitive-functions]]
  542. === Case-insensitive functions
  543. Most EQL functions are case-sensitive by default. To make a function
  544. case-insensitive, use the `~` operator after the function name:
  545. [source,eql]
  546. ----
  547. stringContains(process.name,".exe") // Matches ".exe" but not ".EXE" or ".Exe"
  548. stringContains~(process.name,".exe") // Matches ".exe", ".EXE", or ".Exe"
  549. ----
  550. [discrete]
  551. [[eql-how-functions-impact-search-performance]]
  552. === How functions impact search performance
  553. Using functions in EQL queries can result in slower search speeds. If you
  554. often use functions to transform indexed data, you can speed up search by making
  555. these changes during indexing instead. However, that often means slower index
  556. speeds.
  557. *Example* +
  558. An index contains the `file.path` field. `file.path` contains the full path to a
  559. file, including the file extension.
  560. When running EQL searches, users often use the `endsWith` function with the
  561. `file.path` field to match file extensions:
  562. [source,eql]
  563. ----
  564. file where endsWith(file.path,".exe") or endsWith(file.path,".dll")
  565. ----
  566. While this works, it can be repetitive to write and can slow search speeds. To
  567. speed up search, you can do the following instead:
  568. . <<indices-put-mapping,Add a new field>>, `file.extension`, to the index. The
  569. `file.extension` field will contain only the file extension from the
  570. `file.path` field.
  571. . Use an <<ingest,ingest pipeline>> containing the <<grok-processor,`grok`>>
  572. processor or another preprocessor tool to extract the file extension from the
  573. `file.path` field before indexing.
  574. . Index the extracted file extension to the `file.extension` field.
  575. These changes may slow indexing but allow for faster searches. Users
  576. can use the `file.extension` field instead of multiple `endsWith` function
  577. calls:
  578. [source,eql]
  579. ----
  580. file where file.extension in ("exe", "dll")
  581. ----
  582. We recommend testing and benchmarking any indexing changes before deploying them
  583. in production. See <<tune-for-indexing-speed>> and <<tune-for-search-speed>>.
  584. [discrete]
  585. [[eql-pipes]]
  586. === Pipes
  587. EQL pipes filter, aggregate, and post-process events returned by
  588. an EQL query. You can use pipes to narrow down EQL query results or make them
  589. more specific.
  590. Pipes are delimited using the pipe (`|`) character.
  591. [source,eql]
  592. ----
  593. event_category where condition | pipe
  594. ----
  595. *Example* +
  596. The following EQL query uses the `tail` pipe to return only the 10 most recent
  597. events matching the query.
  598. [source,eql]
  599. ----
  600. authentication where agent.id == 4624
  601. | tail 10
  602. ----
  603. You can pass the output of a pipe to another pipe. This lets you use multiple
  604. pipes with a single query.
  605. For a list of supported pipes, see <<eql-pipe-ref>>.
  606. [discrete]
  607. [[eql-syntax-limitations]]
  608. === Limitations
  609. EQL does not support the following features and syntax.
  610. [discrete]
  611. [[eql-compare-fields]]
  612. ==== Comparing fields
  613. You cannot use EQL comparison operators to compare a field to
  614. another field. This applies even if the fields are changed using a
  615. <<eql-functions,function>>.
  616. [discrete]
  617. [[eql-text-fields]]
  618. ==== Text fields are not supported
  619. EQL searches do not support <<text,`text`>> fields. To a search a `text` field,
  620. use the EQL search API's <<eql-search-filter-query-dsl,Query DSL `filter`>>
  621. parameter.
  622. [discrete]
  623. [[eql-array-fields]]
  624. ==== Array field values are not supported
  625. EQL does not support <<array,array>> field values, also known as
  626. multi-value fields. EQL searches on array field values may return inconsistent
  627. results.
  628. [discrete]
  629. [[eql-nested-fields]]
  630. ==== EQL search on nested fields
  631. You cannot use EQL to search the values of a <<nested,`nested`>> field or the
  632. sub-fields of a `nested` field. However, data streams and indices containing
  633. `nested` field mappings are otherwise supported.
  634. [discrete]
  635. [[eql-unsupported-syntax]]
  636. ==== Differences from Endgame EQL syntax
  637. {es} EQL differs from the {eql-ref}/index.html[Elastic Endgame EQL syntax] as
  638. follows:
  639. * In {es} EQL, most operators are case-sensitive. For example,
  640. `process_name == "cmd.exe"` is not equivalent to
  641. `process_name == "Cmd.exe"`.
  642. * In {es} EQL, functions are case-sensitive. To make a function
  643. case-insensitive, use `~`, such as `endsWith~(process_name, ".exe")`.
  644. * For case-insensitive equality comparisons, use the `:` operator. Both `*` and
  645. `?` are recognized wildcard characters.
  646. * The `==` and `!=` operators do not expand wildcard characters. For example,
  647. `process_name == "cmd*.exe"` interprets `*` as a literal asterisk, not a
  648. wildcard.
  649. * For wildcard matching, use the `like` keyword when case-sensitive and
  650. `like~` when case-insensitive. The `:` operator is equivalent to `like~`.
  651. * For regular expression matching, use `regex` or `regex~`.
  652. * `=` cannot be substituted for the `==` operator.
  653. * Strings enclosed in single quotes (`'`) are not supported. Enclose strings in
  654. double quotes (`"`) instead.
  655. * `?"` and `?'` do not indicate raw strings. Enclose raw strings in
  656. three double quotes (`"""`) instead.
  657. * {es} EQL does not support:
  658. ** Array functions:
  659. *** {eql-ref}/functions.html#arrayContains[`arrayContains`]
  660. *** {eql-ref}/functions.html#arrayCount[`arrayCount`]
  661. *** {eql-ref}/functions.html#arraySearch[`arraySearch`]
  662. ** The {eql-ref}//functions.html#match[`match`] function
  663. ** {eql-ref}/joins.html[Joins]
  664. ** {eql-ref}/basic-syntax.html#event-relationships[Lineage-related keywords]:
  665. *** `child of`
  666. *** `descendant of`
  667. *** `event of`
  668. ** The following {eql-ref}/pipes.html[pipes]:
  669. *** {eql-ref}/pipes.html#count[`count`]
  670. *** {eql-ref}/pipes.html#filter[`filter`]
  671. *** {eql-ref}/pipes.html#sort[`sort`]
  672. *** {eql-ref}/pipes.html#unique[`unique`]
  673. *** {eql-ref}/pipes.html#unique-count[`unique_count`]
  674. [discrete]
  675. [[eql-how-sequence-queries-handle-matches]]
  676. ==== How sequence queries handle matches
  677. <<eql-sequences,Sequence queries>> don't find all potential matches for a
  678. sequence. This approach would be too slow and costly for large event data sets.
  679. Instead, a sequence query handles pending sequence matches as a
  680. {wikipedia}/Finite-state_machine[state machine]:
  681. * Each event item in the sequence query is a state in the machine.
  682. * Only one pending sequence can be in each state at a time.
  683. * If two pending sequences are in the same state at the same time, the most
  684. recent sequence overwrites the older one.
  685. * If the query includes <<eql-by-keyword,`by` fields>>, the query uses a
  686. separate state machine for each unique `by` field value.
  687. .*Example*
  688. [%collapsible]
  689. ====
  690. A data set contains the following `process` events in ascending chronological
  691. order:
  692. [source,js]
  693. ----
  694. { "index" : { "_id": "1" } }
  695. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  696. { "index" : { "_id": "2" } }
  697. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  698. { "index" : { "_id": "3" } }
  699. { "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}
  700. { "index" : { "_id": "4" } }
  701. { "user": { "name": "root" }, "process": { "name": "bash" }, ...}
  702. { "index" : { "_id": "5" } }
  703. { "user": { "name": "root" }, "process": { "name": "bash" }, ...}
  704. { "index" : { "_id": "6" } }
  705. { "user": { "name": "elkbee" }, "process": { "name": "attrib" }, ...}
  706. { "index" : { "_id": "7" } }
  707. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  708. { "index" : { "_id": "8" } }
  709. { "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}
  710. { "index" : { "_id": "9" } }
  711. { "user": { "name": "root" }, "process": { "name": "cat" }, ...}
  712. { "index" : { "_id": "10" } }
  713. { "user": { "name": "elkbee" }, "process": { "name": "cat" }, ...}
  714. { "index" : { "_id": "11" } }
  715. { "user": { "name": "root" }, "process": { "name": "cat" }, ...}
  716. ----
  717. // NOTCONSOLE
  718. An EQL sequence query searches the data set:
  719. [source,eql]
  720. ----
  721. sequence by user.name
  722. [process where process.name == "attrib"]
  723. [process where process.name == "bash"]
  724. [process where process.name == "cat"]
  725. ----
  726. The query's event items correspond to the following states:
  727. * State A: `[process where process.name == "attrib"]`
  728. * State B: `[process where process.name == "bash"]`
  729. * Complete: `[process where process.name == "cat"]`
  730. image::images/eql/sequence-state-machine.svg[align="center"]
  731. To find matching sequences, the query uses separate state machines for each
  732. unique `user.name` value. Based on the data set, you can expect two state
  733. machines: one for the `root` user and one for `elkbee`.
  734. image::images/eql/separate-state-machines.svg[align="center"]
  735. Pending sequence matches move through each machine's states as follows:
  736. [source,txt]
  737. ----
  738. { "index" : { "_id": "1" } }
  739. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  740. // Creates sequence [1] in state A for the "root" user.
  741. //
  742. // +------------------------"root"------------------------+
  743. // | +-----------+ +-----------+ +------------+ |
  744. // | | State A | | State B | | Complete | |
  745. // | +-----------+ +-----------+ +------------+ |
  746. // | | [1] | | | | | |
  747. // | +-----------+ +-----------+ +------------+ |
  748. // +------------------------------------------------------+
  749. { "index" : { "_id": "2" } }
  750. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  751. // Creates sequence [2] in state A for "root", overwriting sequence [1].
  752. //
  753. // +------------------------"root"------------------------+
  754. // | +-----------+ +-----------+ +------------+ |
  755. // | | State A | | State B | | Complete | |
  756. // | +-----------+ +-----------+ +------------+ |
  757. // | | [2] | | | | | |
  758. // | +-----------+ +-----------+ +------------+ |
  759. // +------------------------------------------------------+
  760. { "index" : { "_id": "3" } }
  761. { "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}
  762. // Nothing happens. The "elkbee" user has no pending sequence to move
  763. // from state A to state B.
  764. //
  765. // +-----------------------"elkbee"-----------------------+
  766. // | +-----------+ +-----------+ +------------+ |
  767. // | | State A | | State B | | Complete | |
  768. // | +-----------+ +-----------+ +------------+ |
  769. // | | | | | | | |
  770. // | +-----------+ +-----------+ +------------+ |
  771. // +------------------------------------------------------+
  772. { "index" : { "_id": "4" } }
  773. { "user": { "name": "root" }, "process": { "name": "bash" }, ...}
  774. // Sequence [2] moves out of state A for "root".
  775. // State B for "root" now contains [2, 4].
  776. // State A for "root" is empty.
  777. //
  778. // +------------------------"root"------------------------+
  779. // | +-----------+ +-----------+ +------------+ |
  780. // | | State A | | State B | | Complete | |
  781. // | +-----------+ --> +-----------+ +------------+ |
  782. // | | | | [2, 4] | | | |
  783. // | +-----------+ +-----------+ +------------+ |
  784. // +------------------------------------------------------+
  785. { "index" : { "_id": "5" } }
  786. { "user": { "name": "root" }, "process": { "name": "bash" }, ...}
  787. // Nothing happens. State A is empty for "root".
  788. //
  789. // +------------------------"root"------------------------+
  790. // | +-----------+ +-----------+ +------------+ |
  791. // | | State A | | State B | | Complete | |
  792. // | +-----------+ +-----------+ +------------+ |
  793. // | | | | [2, 4] | | | |
  794. // | +-----------+ +-----------+ +------------+ |
  795. // +------------------------------------------------------+
  796. { "index" : { "_id": "6" } }
  797. { "user": { "name": "elkbee" }, "process": { "name": "attrib" }, ...}
  798. // Creates sequence [6] in state A for "elkbee".
  799. //
  800. // +-----------------------"elkbee"-----------------------+
  801. // | +-----------+ +-----------+ +------------+ |
  802. // | | State A | | State B | | Complete | |
  803. // | +-----------+ +-----------+ +------------+ |
  804. // | | [6] | | | | | |
  805. // | +-----------+ +-----------+ +------------+ |
  806. // +------------------------------------------------------+
  807. { "index" : { "_id": "7" } }
  808. { "user": { "name": "root" }, "process": { "name": "attrib" }, ...}
  809. // Creates sequence [7] in state A for "root".
  810. // Sequence [2, 4] remains in state B for "root".
  811. //
  812. // +------------------------"root"------------------------+
  813. // | +-----------+ +-----------+ +------------+ |
  814. // | | State A | | State B | | Complete | |
  815. // | +-----------+ +-----------+ +------------+ |
  816. // | | [7] | | [2, 4] | | | |
  817. // | +-----------+ +-----------+ +------------+ |
  818. // +------------------------------------------------------+
  819. { "index" : { "_id": "8" } }
  820. { "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}
  821. // Sequence [6, 8] moves to state B for "elkbee".
  822. // State A for "elkbee" is now empty.
  823. //
  824. // +-----------------------"elkbee"-----------------------+
  825. // | +-----------+ +-----------+ +------------+ |
  826. // | | State A | | State B | | Complete | |
  827. // | +-----------+ --> +-----------+ +------------+ |
  828. // | | | | [6, 8] | | | |
  829. // | +-----------+ +-----------+ +------------+ |
  830. // +------------------------------------------------------+
  831. { "index" : { "_id": "9" } }
  832. { "user": { "name": "root" }, "process": { "name": "cat" }, ...}
  833. // Sequence [2, 4, 9] is complete for "root".
  834. // State B for "root" is now empty.
  835. // Sequence [7] remains in state A.
  836. //
  837. // +------------------------"root"------------------------+
  838. // | +-----------+ +-----------+ +------------+ |
  839. // | | State A | | State B | | Complete | |
  840. // | +-----------+ +-----------+ --> +------------+ |
  841. // | | [7] | | | | [2, 4, 9] |
  842. // | +-----------+ +-----------+ +------------+ |
  843. // +------------------------------------------------------+
  844. { "index" : { "_id": "10" } }
  845. { "user": { "name": "elkbee" }, "process": { "name": "cat" }, ...}
  846. // Sequence [6, 8, 10] is complete for "elkbee".
  847. // State A and B for "elkbee" are now empty.
  848. //
  849. // +-----------------------"elkbee"-----------------------+
  850. // | +-----------+ +-----------+ +------------+ |
  851. // | | State A | | State B | | Complete | |
  852. // | +-----------+ +-----------+ --> +------------+ |
  853. // | | | | | | [6, 8, 10] |
  854. // | +-----------+ +-----------+ +------------+ |
  855. // +------------------------------------------------------+
  856. { "index" : { "_id": "11" } }
  857. { "user": { "name": "root" }, "process": { "name": "cat" }, ...}
  858. // Nothing happens.
  859. // The machines for "root" and "elkbee" remain the same.
  860. //
  861. // +------------------------"root"------------------------+
  862. // | +-----------+ +-----------+ +------------+ |
  863. // | | State A | | State B | | Complete | |
  864. // | +-----------+ +-----------+ +------------+ |
  865. // | | [7] | | | | [2, 4, 9] |
  866. // | +-----------+ +-----------+ +------------+ |
  867. // +------------------------------------------------------+
  868. //
  869. // +-----------------------"elkbee"-----------------------+
  870. // | +-----------+ +-----------+ +------------+ |
  871. // | | State A | | State B | | Complete | |
  872. // | +-----------+ +-----------+ +------------+ |
  873. // | | | | | | [6, 8, 10] |
  874. // | +-----------+ +-----------+ +------------+ |
  875. // +------------------------------------------------------+
  876. ----
  877. ====