syntax.asciidoc 31 KB

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