syntax.asciidoc 33 KB

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