eql.asciidoc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[eql]]
  4. = EQL search
  5. ++++
  6. <titleabbrev>EQL</titleabbrev>
  7. ++++
  8. Event Query Language (EQL) is a query language for event-based time series
  9. data, such as logs, metrics, and traces.
  10. [discrete]
  11. [[eql-advantages]]
  12. === Advantages of EQL
  13. * *EQL lets you express relationships between events.* +
  14. Many query languages allow you to match single events. EQL lets you match a
  15. sequence of events across different event categories and time spans.
  16. * *EQL has a low learning curve.* +
  17. <<eql-syntax,EQL syntax>> looks like other common query languages, such as SQL.
  18. EQL lets you write and read queries intuitively, which makes for quick,
  19. iterative searching.
  20. * *EQL is designed for security use cases.* +
  21. While you can use it for any event-based data, we created EQL for threat
  22. hunting. EQL not only supports indicator of compromise (IOC) searches but can
  23. describe activity that goes beyond IOCs.
  24. [discrete]
  25. [[eql-required-fields]]
  26. === Required fields
  27. To run an EQL search, the searched data stream or index must contain a
  28. _timestamp_ and _event category_ field. By default, EQL uses the `@timestamp`
  29. and `event.category` fields from the {ecs-ref}[Elastic Common Schema
  30. (ECS)]. To use a different timestamp or event category field, see
  31. <<specify-a-timestamp-or-event-category-field>>.
  32. TIP: While no schema is required to use EQL, we recommend using the
  33. {ecs-ref}[ECS]. EQL searches are designed to work with core ECS fields by
  34. default.
  35. [discrete]
  36. [[run-an-eql-search]]
  37. === Run an EQL search
  38. Use the <<eql-search-api,EQL search API>> to run a <<eql-basic-syntax,basic EQL
  39. query>>.
  40. ////
  41. [source,console]
  42. ----
  43. DELETE /_data_stream/*
  44. DELETE /_index_template/*
  45. ----
  46. // TEARDOWN
  47. ////
  48. [source,console]
  49. ----
  50. GET /my-data-stream/_eql/search
  51. {
  52. "query": """
  53. process where process.name == "regsvr32.exe"
  54. """
  55. }
  56. ----
  57. // TEST[setup:sec_logs]
  58. By default, basic EQL queries return the 10 most recent matching events in the
  59. `hits.events` property. These hits are sorted by timestamp, converted to
  60. milliseconds since the {wikipedia}/Unix_time[Unix epoch], in ascending order.
  61. [source,console-result]
  62. ----
  63. {
  64. "is_partial": false,
  65. "is_running": false,
  66. "took": 60,
  67. "timed_out": false,
  68. "hits": {
  69. "total": {
  70. "value": 2,
  71. "relation": "eq"
  72. },
  73. "events": [
  74. {
  75. "_index": ".ds-my-data-stream-2099.12.07-000001",
  76. "_id": "OQmfCaduce8zoHT93o4H",
  77. "_source": {
  78. "@timestamp": "2099-12-07T11:07:09.000Z",
  79. "event": {
  80. "category": "process",
  81. "id": "aR3NWVOs",
  82. "sequence": 4
  83. },
  84. "process": {
  85. "pid": 2012,
  86. "name": "regsvr32.exe",
  87. "command_line": "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll",
  88. "executable": "C:\\Windows\\System32\\regsvr32.exe"
  89. }
  90. }
  91. },
  92. {
  93. "_index": ".ds-my-data-stream-2099.12.07-000001",
  94. "_id": "xLkCaj4EujzdNSxfYLbO",
  95. "_source": {
  96. "@timestamp": "2099-12-07T11:07:10.000Z",
  97. "event": {
  98. "category": "process",
  99. "id": "GTSmSqgz0U",
  100. "sequence": 6,
  101. "type": "termination"
  102. },
  103. "process": {
  104. "pid": 2012,
  105. "name": "regsvr32.exe",
  106. "executable": "C:\\Windows\\System32\\regsvr32.exe"
  107. }
  108. }
  109. }
  110. ]
  111. }
  112. }
  113. ----
  114. // TESTRESPONSE[s/"took": 60/"took": $body.took/]
  115. // TESTRESPONSE[s/"_index": ".ds-my-data-stream-2099.12.07-000001"/"_index": $body.hits.events.0._index/]
  116. // TESTRESPONSE[s/"_id": "OQmfCaduce8zoHT93o4H"/"_id": $body.hits.events.0._id/]
  117. // TESTRESPONSE[s/"_id": "xLkCaj4EujzdNSxfYLbO"/"_id": $body.hits.events.1._id/]
  118. Use the `size` parameter to get a smaller or larger set of hits:
  119. [source,console]
  120. ----
  121. GET /my-data-stream/_eql/search
  122. {
  123. "query": """
  124. process where process.name == "regsvr32.exe"
  125. """,
  126. "size": 50
  127. }
  128. ----
  129. // TEST[setup:sec_logs]
  130. [discrete]
  131. [[eql-search-sequence]]
  132. === Search for a sequence of events
  133. Use EQL's <<eql-sequences,sequence syntax>> to search for a series of
  134. ordered events. List the event items in ascending chronological order,
  135. with the most recent event listed last:
  136. [source,console]
  137. ----
  138. GET /my-data-stream/_eql/search
  139. {
  140. "query": """
  141. sequence
  142. [ process where process.name == "regsvr32.exe" ]
  143. [ file where stringContains(file.name, "scrobj.dll") ]
  144. """
  145. }
  146. ----
  147. // TEST[setup:sec_logs]
  148. The response's `hits.sequences` property contains the 10 most recent matching
  149. sequences.
  150. [source,console-result]
  151. ----
  152. {
  153. ...
  154. "hits": {
  155. "total": ...,
  156. "sequences": [
  157. {
  158. "events": [
  159. {
  160. "_index": ".ds-my-data-stream-2099.12.07-000001",
  161. "_id": "OQmfCaduce8zoHT93o4H",
  162. "_source": {
  163. "@timestamp": "2099-12-07T11:07:09.000Z",
  164. "event": {
  165. "category": "process",
  166. "id": "aR3NWVOs",
  167. "sequence": 4
  168. },
  169. "process": {
  170. "pid": 2012,
  171. "name": "regsvr32.exe",
  172. "command_line": "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll",
  173. "executable": "C:\\Windows\\System32\\regsvr32.exe"
  174. }
  175. }
  176. },
  177. {
  178. "_index": ".ds-my-data-stream-2099.12.07-000001",
  179. "_id": "yDwnGIJouOYGBzP0ZE9n",
  180. "_source": {
  181. "@timestamp": "2099-12-07T11:07:10.000Z",
  182. "event": {
  183. "category": "file",
  184. "id": "tZ1NWVOs",
  185. "sequence": 5
  186. },
  187. "process": {
  188. "pid": 2012,
  189. "name": "regsvr32.exe",
  190. "executable": "C:\\Windows\\System32\\regsvr32.exe"
  191. },
  192. "file": {
  193. "path": "C:\\Windows\\System32\\scrobj.dll",
  194. "name": "scrobj.dll"
  195. }
  196. }
  197. }
  198. ]
  199. }
  200. ]
  201. }
  202. }
  203. ----
  204. // TESTRESPONSE[s/ \.\.\.\n/"is_partial": false, "is_running": false, "took": $body.took, "timed_out": false,/]
  205. // TESTRESPONSE[s/"total": \.\.\.,/"total": { "value": 1, "relation": "eq" },/]
  206. // TESTRESPONSE[s/"_index": ".ds-my-data-stream-2099.12.07-000001"/"_index": $body.hits.sequences.0.events.0._index/]
  207. // TESTRESPONSE[s/"_id": "OQmfCaduce8zoHT93o4H"/"_id": $body.hits.sequences.0.events.0._id/]
  208. // TESTRESPONSE[s/"_id": "yDwnGIJouOYGBzP0ZE9n"/"_id": $body.hits.sequences.0.events.1._id/]
  209. Use the <<eql-with-maxspan-keywords,`with maxspan` keywords>> to constrain
  210. matching sequences to a timespan:
  211. [source,console]
  212. ----
  213. GET /my-data-stream/_eql/search
  214. {
  215. "query": """
  216. sequence with maxspan=1h
  217. [ process where process.name == "regsvr32.exe" ]
  218. [ file where stringContains(file.name, "scrobj.dll") ]
  219. """
  220. }
  221. ----
  222. // TEST[setup:sec_logs]
  223. Use the <<eql-by-keyword,`by` keyword>> to match events that share the
  224. same field values:
  225. [source,console]
  226. ----
  227. GET /my-data-stream/_eql/search
  228. {
  229. "query": """
  230. sequence with maxspan=1h
  231. [ process where process.name == "regsvr32.exe" ] by process.pid
  232. [ file where stringContains(file.name, "scrobj.dll") ] by process.pid
  233. """
  234. }
  235. ----
  236. // TEST[setup:sec_logs]
  237. If a field value should be shared across all events, use the `sequence by`
  238. keyword. The following query is equivalent to the previous one.
  239. [source,console]
  240. ----
  241. GET /my-data-stream/_eql/search
  242. {
  243. "query": """
  244. sequence by process.pid with maxspan=1h
  245. [ process where process.name == "regsvr32.exe" ]
  246. [ file where stringContains(file.name, "scrobj.dll") ]
  247. """
  248. }
  249. ----
  250. // TEST[setup:sec_logs]
  251. The `hits.sequences.join_keys` property contains the shared field values.
  252. [source,console-result]
  253. ----
  254. {
  255. ...
  256. "hits": ...,
  257. "sequences": [
  258. {
  259. "join_keys": [
  260. 2012
  261. ],
  262. "events": ...
  263. }
  264. ]
  265. }
  266. }
  267. ----
  268. // TESTRESPONSE[s/ \.\.\.\n/"is_partial": false, "is_running": false, "took": $body.took, "timed_out": false,/]
  269. // TESTRESPONSE[s/"hits": \.\.\.,/"hits": { "total": { "value": 1, "relation": "eq" },/]
  270. // TESTRESPONSE[s/"events": \.\.\./"events": $body.hits.sequences.0.events/]
  271. Use the <<eql-until-keyword,`until` keyword>> to specify an expiration
  272. event for sequences. Matching sequences must end before this event.
  273. [source,console]
  274. ----
  275. GET /my-data-stream/_eql/search
  276. {
  277. "query": """
  278. sequence by process.pid with maxspan=1h
  279. [ process where process.name == "regsvr32.exe" ]
  280. [ file where stringContains(file.name, "scrobj.dll") ]
  281. until [ process where event.type == "termination" ]
  282. """
  283. }
  284. ----
  285. // TEST[setup:sec_logs]
  286. [discrete]
  287. [[retrieve-selected-fields]]
  288. === Retrieve selected fields
  289. By default, each hit in the search response includes the document `_source`,
  290. which is the entire JSON object that was provided when indexing the document.
  291. You can use the <<common-options-response-filtering,`filter_path`>> query
  292. parameter to filter the API response. For example, the following search returns
  293. only the timestamp and PID from the `_source` of each matching event.
  294. [source,console]
  295. ----
  296. GET /my-data-stream/_eql/search?filter_path=hits.events._source.@timestamp,hits.events._source.process.pid
  297. {
  298. "query": """
  299. process where process.name == "regsvr32.exe"
  300. """
  301. }
  302. ----
  303. // TEST[setup:sec_logs]
  304. The API returns the following response.
  305. [source,console-result]
  306. ----
  307. {
  308. "hits": {
  309. "events": [
  310. {
  311. "_source": {
  312. "@timestamp": "2099-12-07T11:07:09.000Z",
  313. "process": {
  314. "pid": 2012
  315. }
  316. }
  317. },
  318. {
  319. "_source": {
  320. "@timestamp": "2099-12-07T11:07:10.000Z",
  321. "process": {
  322. "pid": 2012
  323. }
  324. }
  325. }
  326. ]
  327. }
  328. }
  329. ----
  330. You can also use the `fields` parameter to retrieve and format specific fields
  331. in the response. This field is identical to the search API's
  332. <<search-fields,`fields` parameter>>.
  333. include::{es-repo-dir}/search/search-your-data/retrieve-selected-fields.asciidoc[tag=fields-param-desc]
  334. The following search request uses the `fields` parameter to retrieve values for
  335. the `event.type` field, all fields starting with `process.`, and the
  336. `@timestamp` field. The request also uses the `filter_path` query parameter to
  337. exclude the `_source` of each hit.
  338. [source,console]
  339. ----
  340. GET /my-data-stream/_eql/search?filter_path=-hits.events._source
  341. {
  342. "query": """
  343. process where process.name == "regsvr32.exe"
  344. """,
  345. "fields": [
  346. "event.type",
  347. "process.*", <1>
  348. {
  349. "field": "@timestamp",
  350. "format": "epoch_millis" <2>
  351. }
  352. ]
  353. }
  354. ----
  355. // TEST[setup:sec_logs]
  356. include::{es-repo-dir}/search/search-your-data/retrieve-selected-fields.asciidoc[tag=fields-param-callouts]
  357. The response includes values as a flat list in the `fields` section for each
  358. hit.
  359. [source,console-result]
  360. ----
  361. {
  362. ...
  363. "hits": {
  364. "total": ...,
  365. "events": [
  366. {
  367. "_index": ".ds-my-data-stream-2099.12.07-000001",
  368. "_id": "OQmfCaduce8zoHT93o4H",
  369. "fields": {
  370. "process.name": [
  371. "regsvr32.exe"
  372. ],
  373. "process.name.keyword": [
  374. "regsvr32.exe"
  375. ],
  376. "@timestamp": [
  377. "4100324829000"
  378. ],
  379. "process.command_line": [
  380. "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll"
  381. ],
  382. "process.command_line.keyword": [
  383. "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll"
  384. ],
  385. "process.executable.keyword": [
  386. "C:\\Windows\\System32\\regsvr32.exe"
  387. ],
  388. "process.pid": [
  389. 2012
  390. ],
  391. "process.executable": [
  392. "C:\\Windows\\System32\\regsvr32.exe"
  393. ]
  394. }
  395. },
  396. ....
  397. ]
  398. }
  399. }
  400. ----
  401. // TESTRESPONSE[s/ \.\.\.\n/"is_partial": false, "is_running": false, "took": $body.took, "timed_out": false,/]
  402. // TESTRESPONSE[s/"total": \.\.\.,/"total": { "value": 2, "relation": "eq" },/]
  403. // TESTRESPONSE[s/"_index": ".ds-my-data-stream-2099.12.07-000001"/"_index": $body.hits.events.0._index/]
  404. // TESTRESPONSE[s/"_id": "OQmfCaduce8zoHT93o4H"/"_id": $body.hits.events.0._id/]
  405. // TESTRESPONSE[s/ \.\.\.\.\n/$body.hits.events.1/]
  406. [discrete]
  407. [[eql-use-runtime-fields]]
  408. === Use runtime fields
  409. Use the `runtime_mappings` parameter to extract and create <<runtime,runtime
  410. fields>> during a search. Use the `fields` parameter to include runtime fields
  411. in the response.
  412. The following search creates a `day_of_week` runtime field from the `@timestamp`
  413. and returns it in the response.
  414. [source,console]
  415. ----
  416. GET /my-data-stream/_eql/search?filter_path=-hits.events._source
  417. {
  418. "runtime_mappings": {
  419. "day_of_week": {
  420. "type": "keyword",
  421. "script": "emit(doc['@timestamp'].value.dayOfWeekEnum.toString())"
  422. }
  423. },
  424. "query": """
  425. process where process.name == "regsvr32.exe"
  426. """,
  427. "fields": [
  428. "@timestamp",
  429. "day_of_week"
  430. ]
  431. }
  432. ----
  433. // TEST[setup:sec_logs]
  434. The API returns:
  435. [source,console-result]
  436. ----
  437. {
  438. ...
  439. "hits": {
  440. "total": ...,
  441. "events": [
  442. {
  443. "_index": ".ds-my-data-stream-2099.12.07-000001",
  444. "_id": "OQmfCaduce8zoHT93o4H",
  445. "fields": {
  446. "@timestamp": [
  447. "2099-12-07T11:07:09.000Z"
  448. ],
  449. "day_of_week": [
  450. "MONDAY"
  451. ]
  452. }
  453. },
  454. ....
  455. ]
  456. }
  457. }
  458. ----
  459. // TESTRESPONSE[s/ \.\.\.\n/"is_partial": false, "is_running": false, "took": $body.took, "timed_out": false,/]
  460. // TESTRESPONSE[s/"total": \.\.\.,/"total": { "value": 2, "relation": "eq" },/]
  461. // TESTRESPONSE[s/"_index": ".ds-my-data-stream-2099.12.07-000001"/"_index": $body.hits.events.0._index/]
  462. // TESTRESPONSE[s/"_id": "OQmfCaduce8zoHT93o4H"/"_id": $body.hits.events.0._id/]
  463. // TESTRESPONSE[s/ \.\.\.\.\n/$body.hits.events.1/]
  464. [discrete]
  465. [[specify-a-timestamp-or-event-category-field]]
  466. === Specify a timestamp or event category field
  467. The EQL search API uses the `@timestamp` and `event.category` fields from the
  468. {ecs-ref}[ECS] by default. To specify different fields, use the
  469. `timestamp_field` and `event_category_field` parameters:
  470. [source,console]
  471. ----
  472. GET /my-data-stream/_eql/search
  473. {
  474. "timestamp_field": "file.accessed",
  475. "event_category_field": "file.type",
  476. "query": """
  477. file where (file.size > 1 and file.type == "file")
  478. """
  479. }
  480. ----
  481. // TEST[setup:sec_logs]
  482. The event category field must be mapped as a <<keyword,`keyword`>> family field
  483. type. The timestamp field should be mapped as a <<date,`date`>> field type.
  484. <<date_nanos,`date_nanos`>> timestamp fields are not supported. You cannot use a
  485. <<nested,`nested`>> field or the sub-fields of a `nested` field as the timestamp
  486. or event category field.
  487. [discrete]
  488. [[eql-search-specify-a-sort-tiebreaker]]
  489. === Specify a sort tiebreaker
  490. By default, the EQL search API returns matching hits by timestamp. If two or
  491. more events share the same timestamp, {es} uses a tiebreaker field value to sort
  492. the events in ascending order. {es} orders events with no
  493. tiebreaker value after events with a value.
  494. If you don't specify a tiebreaker field or the events also share the same
  495. tiebreaker value, {es} considers the events concurrent and may
  496. not return them in a consistent sort order.
  497. To specify a tiebreaker field, use the `tiebreaker_field` parameter. If you use
  498. the {ecs-ref}[ECS], we recommend using `event.sequence` as the tiebreaker field.
  499. [source,console]
  500. ----
  501. GET /my-data-stream/_eql/search
  502. {
  503. "tiebreaker_field": "event.sequence",
  504. "query": """
  505. process where process.name == "cmd.exe" and stringContains(process.executable, "System32")
  506. """
  507. }
  508. ----
  509. // TEST[setup:sec_logs]
  510. [discrete]
  511. [[eql-search-filter-query-dsl]]
  512. === Filter using Query DSL
  513. The `filter` parameter uses <<query-dsl,Query DSL>> to limit the documents on
  514. which an EQL query runs.
  515. [source,console]
  516. ----
  517. GET /my-data-stream/_eql/search
  518. {
  519. "filter": {
  520. "range": {
  521. "@timestamp": {
  522. "gte": "now-1d/d",
  523. "lt": "now/d"
  524. }
  525. }
  526. },
  527. "query": """
  528. file where (file.type == "file" and file.name == "cmd.exe")
  529. """
  530. }
  531. ----
  532. // TEST[setup:sec_logs]
  533. [discrete]
  534. [[eql-search-async]]
  535. === Run an async EQL search
  536. By default, EQL search requests are synchronous and wait for complete results
  537. before returning a response. However, complete results can take longer for
  538. searches across large data sets or <<data-tiers,frozen>> data.
  539. To avoid long waits, run an async EQL search. Set `wait_for_completion_timeout`
  540. to a duration you'd like to wait for synchronous results.
  541. [source,console]
  542. ----
  543. GET /my-data-stream/_eql/search
  544. {
  545. "wait_for_completion_timeout": "2s",
  546. "query": """
  547. process where process.name == "cmd.exe"
  548. """
  549. }
  550. ----
  551. // TEST[setup:sec_logs]
  552. If the request doesn't finish within the timeout period, the search becomes async
  553. and returns a response that includes:
  554. * A search ID
  555. * An `is_partial` value of `true`, indicating the search results are
  556. incomplete
  557. * An `is_running` value of `true`, indicating the search is ongoing
  558. The async search continues to run in the background without blocking other
  559. requests.
  560. [source,console-result]
  561. ----
  562. {
  563. "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",
  564. "is_partial": true,
  565. "is_running": true,
  566. "took": 2000,
  567. "timed_out": false,
  568. "hits": ...
  569. }
  570. ----
  571. // TESTRESPONSE[s/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=/$body.id/]
  572. // TESTRESPONSE[s/"is_partial": true/"is_partial": $body.is_partial/]
  573. // TESTRESPONSE[s/"is_running": true/"is_running": $body.is_running/]
  574. // TESTRESPONSE[s/"took": 2000/"took": $body.took/]
  575. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  576. To check the progress of an async search, use the <<get-async-eql-search-api,get
  577. async EQL search API>> with the search ID. Specify how long you'd like for
  578. complete results in the `wait_for_completion_timeout` parameter.
  579. [source,console]
  580. ----
  581. GET /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?wait_for_completion_timeout=2s
  582. ----
  583. // TEST[skip: no access to search ID]
  584. If the response's `is_running` value is `false`, the async search has finished.
  585. If the `is_partial` value is `false`, the returned search results are
  586. complete.
  587. [source,console-result]
  588. ----
  589. {
  590. "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",
  591. "is_partial": false,
  592. "is_running": false,
  593. "took": 2000,
  594. "timed_out": false,
  595. "hits": ...
  596. }
  597. ----
  598. // TESTRESPONSE[s/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=/$body.id/]
  599. // TESTRESPONSE[s/"took": 2000/"took": $body.took/]
  600. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  601. Another more lightweight way to check the progress of an async search is to use
  602. the <<get-async-eql-status-api,get async EQL status API>> with the search ID.
  603. [source,console]
  604. ----
  605. GET /_eql/search/status/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=
  606. ----
  607. // TEST[skip: no access to search ID]
  608. [source,console-result]
  609. ----
  610. {
  611. "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",
  612. "is_running": false,
  613. "is_partial": false,
  614. "expiration_time_in_millis": 1611690295000,
  615. "completion_status": 200
  616. }
  617. ----
  618. // TESTRESPONSE[s/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=/$body.id/]
  619. // TESTRESPONSE[s/"expiration_time_in_millis": 1611690295000/"expiration_time_in_millis": $body.expiration_time_in_millis/]
  620. [discrete]
  621. [[eql-search-store-async-eql-search]]
  622. === Change the search retention period
  623. By default, the EQL search API stores async searches for five days. After this
  624. period, any searches and their results are deleted. Use the `keep_alive`
  625. parameter to change this retention period:
  626. [source,console]
  627. ----
  628. GET /my-data-stream/_eql/search
  629. {
  630. "keep_alive": "2d",
  631. "wait_for_completion_timeout": "2s",
  632. "query": """
  633. process where process.name == "cmd.exe"
  634. """
  635. }
  636. ----
  637. // TEST[setup:sec_logs]
  638. You can use the <<get-async-eql-search-api,get async EQL search API>>'s
  639. `keep_alive` parameter to later change the retention period. The new retention
  640. period starts after the get request runs.
  641. [source,console]
  642. ----
  643. GET /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?keep_alive=5d
  644. ----
  645. // TEST[skip: no access to search ID]
  646. Use the <<delete-async-eql-search-api,delete async EQL search API>> to
  647. manually delete an async EQL search before the `keep_alive` period ends. If the
  648. search is still ongoing, {es} cancels the search request.
  649. [source,console]
  650. ----
  651. DELETE /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?keep_alive=5d
  652. ----
  653. // TEST[skip: no access to search ID]
  654. [discrete]
  655. [[eql-search-store-sync-eql-search]]
  656. === Store synchronous EQL searches
  657. By default, the EQL search API only stores async searches. To save a synchronous
  658. search, set `keep_on_completion` to `true`:
  659. [source,console]
  660. ----
  661. GET /my-data-stream/_eql/search
  662. {
  663. "keep_on_completion": true,
  664. "wait_for_completion_timeout": "2s",
  665. "query": """
  666. process where process.name == "cmd.exe"
  667. """
  668. }
  669. ----
  670. // TEST[setup:sec_logs]
  671. The response includes a search ID. `is_partial` and `is_running` are `false`,
  672. indicating the EQL search was synchronous and returned complete results.
  673. [source,console-result]
  674. ----
  675. {
  676. "id": "FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=",
  677. "is_partial": false,
  678. "is_running": false,
  679. "took": 52,
  680. "timed_out": false,
  681. "hits": ...
  682. }
  683. ----
  684. // TESTRESPONSE[s/FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=/$body.id/]
  685. // TESTRESPONSE[s/"took": 52/"took": $body.took/]
  686. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  687. Use the <<get-async-eql-search-api,get async EQL search API>> to get the
  688. same results later:
  689. [source,console]
  690. ----
  691. GET /_eql/search/FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=
  692. ----
  693. // TEST[skip: no access to search ID]
  694. Saved synchronous searches are still subject to the `keep_alive` parameter's
  695. retention period. When this period ends, the search and its results are deleted.
  696. You can also check only the status of the saved synchronous search without
  697. results by using <<get-async-eql-status-api,get async EQL status API>>.
  698. You can also manually delete saved synchronous searches using the
  699. <<delete-async-eql-search-api,delete async EQL search API>>.
  700. include::syntax.asciidoc[]
  701. include::functions.asciidoc[]
  702. include::pipes.asciidoc[]
  703. include::detect-threats-with-eql.asciidoc[]