eql.asciidoc 22 KB

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