search.asciidoc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[eql-search]]
  4. == Run an EQL search
  5. dev::[]
  6. To start using EQL in {es}, first ensure your event data meets
  7. <<eql-requirements,EQL requirements>>. You can then use the <<eql-search-api,EQL
  8. search API>> to search event data stored in one or more {es} indices.
  9. .*Example*
  10. [%collapsible]
  11. ====
  12. To get started, ingest or add the data to an {es} index.
  13. The following <<docs-bulk,bulk API>> request adds some example log data to the
  14. `sec_logs` index. This log data follows the {ecs-ref}[Elastic Common Schema
  15. (ECS)].
  16. [source,console]
  17. ----
  18. PUT /sec_logs/_bulk?refresh
  19. {"index":{"_index" : "sec_logs", "_id" : "1"}}
  20. { "@timestamp": "2020-12-06T11:04:05.000Z", "agent": { "id": "8a4f500d" }, "event": { "category": "process", "id": "edwCRnyD","sequence": 1 }, "process": { "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe" } }
  21. {"index":{"_index" : "sec_logs", "_id" : "2"}}
  22. { "@timestamp": "2020-12-06T11:04:07.000Z", "agent": { "id": "8a4f500d" }, "event": { "category": "file", "id": "dGCHwoeS", "sequence": 2 }, "file": { "accessed": "2020-12-07T11:07:08.000Z", "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe", "type": "file", "size": 16384 }, "process": { "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe" } }
  23. {"index":{"_index" : "sec_logs", "_id" : "3"}}
  24. { "@timestamp": "2020-12-07T11:06:07.000Z", "agent": { "id": "8a4f500d" }, "event": { "category": "process", "id": "cMyt5SZ2", "sequence": 3 }, "process": { "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe" } }
  25. {"index":{"_index" : "sec_logs", "_id" : "4"}}
  26. { "@timestamp": "2020-12-07T11:07:08.000Z", "agent": { "id": "8a4f500d" }, "event": { "category": "file", "id": "bYA7gPay", "sequence": 4 }, "file": { "accessed": "2020-12-07T11:07:08.000Z", "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe", "type": "file", "size": 16384 }, "process": { "name": "cmd.exe", "path": "C:\\Windows\\System32\\cmd.exe" } }
  27. {"index":{"_index" : "sec_logs", "_id" : "5"}}
  28. { "@timestamp": "2020-12-07T11:07:09.000Z", "agent": { "id": "8a4f500d" }, "event": { "category": "process", "id": "aR3NWVOs", "sequence": 5 }, "process": { "name": "regsvr32.exe", "path": "C:\\Windows\\System32\\regsvr32.exe" } }
  29. ----
  30. // TESTSETUP
  31. [TIP]
  32. =====
  33. You also can set up {beats-ref}/getting-started.html[{beats}], such as
  34. {auditbeat-ref}/auditbeat-getting-started.html[{auditbeat}] or
  35. {winlogbeat-ref}/winlogbeat-getting-started.html[{winlogbeat}], to automatically
  36. send and index your event data in {es}. See
  37. {beats-ref}/getting-started.html[Getting started with {beats}].
  38. =====
  39. You can now use the EQL search API to search this index using an EQL query.
  40. The following request searches the `sec_logs` index using the EQL query
  41. specified in the `query` parameter. The EQL query matches events with an
  42. `event.category` of `process` that have a `process.name` of `cmd.exe`.
  43. [source,console]
  44. ----
  45. GET /sec_logs/_eql/search
  46. {
  47. "query": """
  48. process where process.name == "cmd.exe"
  49. """
  50. }
  51. ----
  52. Because the `sec_log` index follows the ECS, you don't need to specify the
  53. required <<eql-required-fields,event category or timestamp>> fields. The request
  54. uses the `event.category` and `@timestamp` fields by default.
  55. The API returns the following response containing the matching events. Events
  56. in the response are sorted by timestamp, converted to milliseconds since the
  57. https://en.wikipedia.org/wiki/Unix_time[Unix epoch], in ascending order.
  58. [source,console-result]
  59. ----
  60. {
  61. "is_partial": false,
  62. "is_running": false,
  63. "took": 60,
  64. "timed_out": false,
  65. "hits": {
  66. "total": {
  67. "value": 2,
  68. "relation": "eq"
  69. },
  70. "events": [
  71. {
  72. "_index": "sec_logs",
  73. "_id": "1",
  74. "_score": null,
  75. "_source": {
  76. "@timestamp": "2020-12-06T11:04:05.000Z",
  77. "agent": {
  78. "id": "8a4f500d"
  79. },
  80. "event": {
  81. "category": "process",
  82. "id": "edwCRnyD",
  83. "sequence": 1
  84. },
  85. "process": {
  86. "name": "cmd.exe",
  87. "path": "C:\\Windows\\System32\\cmd.exe"
  88. }
  89. },
  90. "sort": [
  91. 1607252645000
  92. ]
  93. },
  94. {
  95. "_index": "sec_logs",
  96. "_id": "3",
  97. "_score": null,
  98. "_source": {
  99. "@timestamp": "2020-12-07T11:06:07.000Z",
  100. "agent": {
  101. "id": "8a4f500d"
  102. },
  103. "event": {
  104. "category": "process",
  105. "id": "cMyt5SZ2",
  106. "sequence": 3
  107. },
  108. "process": {
  109. "name": "cmd.exe",
  110. "path": "C:\\Windows\\System32\\cmd.exe"
  111. }
  112. },
  113. "sort": [
  114. 1607339167000
  115. ]
  116. }
  117. ]
  118. }
  119. }
  120. ----
  121. // TESTRESPONSE[s/"took": 60/"took": $body.took/]
  122. ====
  123. [discrete]
  124. [[eql-search-sequence]]
  125. === Search for a sequence of events
  126. Many query languages allow you to match single events. However, EQL's
  127. <<eql-sequences,sequence syntax>> lets you match an ordered series of events.
  128. .*Example*
  129. [%collapsible]
  130. ====
  131. The following EQL search request matches a sequence that:
  132. . Starts with an event with:
  133. +
  134. --
  135. * An `event.category` of `file`
  136. * A `file.name` of `cmd.exe`
  137. --
  138. . Followed by an event with:
  139. +
  140. --
  141. * An `event.category` of `process`
  142. * A `process.name` that contains the substring `regsvr32`
  143. --
  144. [source,console]
  145. ----
  146. GET /sec_logs/_eql/search
  147. {
  148. "query": """
  149. sequence
  150. [ file where file.name == "cmd.exe" ]
  151. [ process where stringContains(process.name, "regsvr32") ]
  152. """
  153. }
  154. ----
  155. The API returns the following response. Matching events in
  156. the `hits.sequences.events` property are sorted by
  157. <<eql-search-api-timestamp-field,timestamp>>, converted to milliseconds since
  158. the https://en.wikipedia.org/wiki/Unix_time[Unix epoch], in ascending order.
  159. [source,console-result]
  160. ----
  161. {
  162. "is_partial": false,
  163. "is_running": false,
  164. "took": 60,
  165. "timed_out": false,
  166. "hits": {
  167. "total": {
  168. "value": 1,
  169. "relation": "eq"
  170. },
  171. "sequences": [
  172. {
  173. "events": [
  174. {
  175. "_index": "sec_logs",
  176. "_id": "4",
  177. "_score": null,
  178. "_source": {
  179. "@timestamp": "2020-12-07T11:07:08.000Z",
  180. "agent": {
  181. "id": "8a4f500d"
  182. },
  183. "event": {
  184. "category": "file",
  185. "id": "bYA7gPay",
  186. "sequence": 4
  187. },
  188. "file": {
  189. "accessed": "2020-12-07T11:07:08.000Z",
  190. "name": "cmd.exe",
  191. "path": "C:\\Windows\\System32\\cmd.exe",
  192. "type": "file",
  193. "size": 16384
  194. },
  195. "process": {
  196. "name": "cmd.exe",
  197. "path": "C:\\Windows\\System32\\cmd.exe"
  198. }
  199. },
  200. "fields": {
  201. "@timestamp": [
  202. "1607339228000"
  203. ]
  204. },
  205. "sort": [
  206. 1607339228000
  207. ]
  208. },
  209. {
  210. "_index": "sec_logs",
  211. "_id": "5",
  212. "_score": null,
  213. "_source": {
  214. "@timestamp": "2020-12-07T11:07:09.000Z",
  215. "agent": {
  216. "id": "8a4f500d"
  217. },
  218. "event": {
  219. "category": "process",
  220. "id": "aR3NWVOs",
  221. "sequence": 5
  222. },
  223. "process": {
  224. "name": "regsvr32.exe",
  225. "path": "C:\\Windows\\System32\\regsvr32.exe"
  226. }
  227. },
  228. "fields": {
  229. "@timestamp": [
  230. "1607339229000"
  231. ]
  232. },
  233. "sort": [
  234. 1607339229000
  235. ]
  236. }
  237. ]
  238. }
  239. ]
  240. }
  241. }
  242. ----
  243. // TESTRESPONSE[s/"took": 60/"took": $body.took/]
  244. You can further constrain matching event sequences using the `by` keyword.
  245. The following EQL search request adds `by agent.id` to each event item. This
  246. ensures events matching the sequence share the same `agent.id` field value.
  247. [source,console]
  248. ----
  249. GET /sec_logs/_eql/search
  250. {
  251. "query": """
  252. sequence
  253. [ file where file.name == "cmd.exe" ] by agent.id
  254. [ process where stringContains(process.name, "regsvr32") ] by agent.id
  255. """
  256. }
  257. ----
  258. Because the `agent.id` field is shared across all events in the sequence, it
  259. can be included using `sequence by`. The following query is equivalent to the
  260. prior one.
  261. [source,console]
  262. ----
  263. GET /sec_logs/_eql/search
  264. {
  265. "query": """
  266. sequence by agent.id
  267. [ file where file.name == "cmd.exe" ]
  268. [ process where stringContains(process.name, "regsvr32") ]
  269. """
  270. }
  271. ----
  272. The API returns the following response. The `hits.sequences.join_keys` property
  273. contains the shared `agent.id` value for each matching event.
  274. [source,console-result]
  275. ----
  276. {
  277. "is_partial": false,
  278. "is_running": false,
  279. "took": 60,
  280. "timed_out": false,
  281. "hits": {
  282. "total": {
  283. "value": 1,
  284. "relation": "eq"
  285. },
  286. "sequences": [
  287. {
  288. "join_keys": [
  289. "8a4f500d"
  290. ],
  291. "events": [
  292. {
  293. "_index": "sec_logs",
  294. "_id": "4",
  295. "_score": null,
  296. "_source": {
  297. "@timestamp": "2020-12-07T11:07:08.000Z",
  298. "agent": {
  299. "id": "8a4f500d"
  300. },
  301. "event": {
  302. "category": "file",
  303. "id": "bYA7gPay",
  304. "sequence": 4
  305. },
  306. "file": {
  307. "accessed": "2020-12-07T11:07:08.000Z",
  308. "name": "cmd.exe",
  309. "path": "C:\\Windows\\System32\\cmd.exe",
  310. "type": "file",
  311. "size": 16384
  312. },
  313. "process": {
  314. "name": "cmd.exe",
  315. "path": "C:\\Windows\\System32\\cmd.exe"
  316. }
  317. },
  318. "fields": {
  319. "@timestamp": [
  320. "1607339228000"
  321. ]
  322. },
  323. "sort": [
  324. 1607339228000
  325. ]
  326. },
  327. {
  328. "_index": "sec_logs",
  329. "_id": "5",
  330. "_score": null,
  331. "_source": {
  332. "@timestamp": "2020-12-07T11:07:09.000Z",
  333. "agent": {
  334. "id": "8a4f500d"
  335. },
  336. "event": {
  337. "category": "process",
  338. "id": "aR3NWVOs",
  339. "sequence": 5
  340. },
  341. "process": {
  342. "name": "regsvr32.exe",
  343. "path": "C:\\Windows\\System32\\regsvr32.exe"
  344. }
  345. },
  346. "fields": {
  347. "@timestamp": [
  348. "1607339229000"
  349. ]
  350. },
  351. "sort": [
  352. 1607339229000
  353. ]
  354. }
  355. ]
  356. }
  357. ]
  358. }
  359. }
  360. ----
  361. // TESTRESPONSE[s/"took": 60/"took": $body.took/]
  362. ====
  363. [discrete]
  364. [[eql-search-specify-event-category-field]]
  365. === Specify an event category field
  366. The EQL search API uses `event.category` as the required
  367. <<eql-required-fields,event category field>> by default. You can use the
  368. `event_category_field` parameter to specify another event category field.
  369. .*Example*
  370. [%collapsible]
  371. ====
  372. The following request specifies `file.type` as the event category
  373. field.
  374. [source,console]
  375. ----
  376. GET /sec_logs/_eql/search
  377. {
  378. "event_category_field": "file.type",
  379. "query": """
  380. file where agent.id == "8a4f500d"
  381. """
  382. }
  383. ----
  384. ====
  385. [discrete]
  386. [[eql-search-specify-timestamp-field]]
  387. === Specify a timestamp field
  388. The EQL search API uses `@timestamp` as the required <<eql-required-fields,event
  389. timestamp field>> by default. You can use the `timestamp_field` parameter to
  390. specify another timestamp field.
  391. .*Example*
  392. [%collapsible]
  393. ====
  394. The following request specifies `file.accessed` as the event
  395. timestamp field.
  396. [source,console]
  397. ----
  398. GET /sec_logs/_eql/search
  399. {
  400. "timestamp_field": "file.accessed",
  401. "query": """
  402. file where (file.size > 1 and file.type == "file")
  403. """
  404. }
  405. ----
  406. ====
  407. [discrete]
  408. [[eql-search-specify-a-sort-tiebreaker]]
  409. === Specify a sort tiebreaker
  410. By default, the EQL search API sorts matching events in the search response by
  411. timestamp. However, if two or more events share the same timestamp, a tiebreaker
  412. field is used to sort the events in ascending, lexicographic order.
  413. The EQL search API uses `event.sequence` as the default tiebreaker field. You
  414. can use the `tiebreaker_field` parameter to specify another field.
  415. .*Example*
  416. [%collapsible]
  417. ====
  418. The following request specifies `event.start` as the tiebreaker field.
  419. [source,console]
  420. ----
  421. GET /sec_logs/_eql/search
  422. {
  423. "tiebreaker_field": "event.id",
  424. "query": """
  425. process where process.name == "cmd.exe" and stringContains(process.path, "System32")
  426. """
  427. }
  428. ----
  429. The API returns the following response. Note the `sort` property of each
  430. matching event contains an array of two items:
  431. * The first item is the event's <<eql-search-api-timestamp-field,timestamp>>,
  432. converted to milliseconds since the https://en.wikipedia.org/wiki/Unix_time[Unix
  433. epoch].
  434. * The second item is the event's `event.id` value. This value is used as a sort
  435. tiebreaker for events with the same timestamp.
  436. [source,console-result]
  437. ----
  438. {
  439. "is_partial": false,
  440. "is_running": false,
  441. "took": 34,
  442. "timed_out": false,
  443. "hits": {
  444. "total": {
  445. "value": 2,
  446. "relation": "eq"
  447. },
  448. "events": [
  449. {
  450. "_index": "sec_logs",
  451. "_id": "1",
  452. "_score": null,
  453. "_source": {
  454. "@timestamp": "2020-12-06T11:04:05.000Z",
  455. "agent": {
  456. "id": "8a4f500d"
  457. },
  458. "event": {
  459. "category": "process",
  460. "id": "edwCRnyD",
  461. "sequence": 1
  462. },
  463. "process": {
  464. "name": "cmd.exe",
  465. "path": "C:\\Windows\\System32\\cmd.exe"
  466. }
  467. },
  468. "sort": [
  469. 1607252645000, <1>
  470. "edwCRnyD" <2>
  471. ]
  472. },
  473. {
  474. "_index": "sec_logs",
  475. "_id": "3",
  476. "_score": null,
  477. "_source": {
  478. "@timestamp": "2020-12-07T11:06:07.000Z",
  479. "agent": {
  480. "id": "8a4f500d"
  481. },
  482. "event": {
  483. "category": "process",
  484. "id": "cMyt5SZ2",
  485. "sequence": 3
  486. },
  487. "process": {
  488. "name": "cmd.exe",
  489. "path": "C:\\Windows\\System32\\cmd.exe"
  490. }
  491. },
  492. "sort": [
  493. 1607339167000, <1>
  494. "cMyt5SZ2" <2>
  495. ]
  496. }
  497. ]
  498. }
  499. }
  500. ----
  501. // TESTRESPONSE[s/"took": 34/"took": $body.took/]
  502. <1> The event's <<eql-search-api-timestamp-field,timestamp>>, converted to
  503. milliseconds since the https://en.wikipedia.org/wiki/Unix_time[Unix
  504. epoch]
  505. <2> The event's `event.id` value.
  506. ====
  507. [discrete]
  508. [[eql-search-filter-query-dsl]]
  509. === Filter using query DSL
  510. You can use the EQL search API's `filter` parameter to specify an additional
  511. query using <<query-dsl,query DSL>>. This query filters the documents on which
  512. the EQL query runs.
  513. .*Example*
  514. [%collapsible]
  515. ====
  516. The following request uses a `range` query to filter the `sec_logs`
  517. index down to only documents with a `file.size` value greater than `1` but less
  518. than `1000000` bytes. The EQL query in `query` parameter then runs on these
  519. filtered documents.
  520. [source,console]
  521. ----
  522. GET /sec_logs/_eql/search
  523. {
  524. "filter": {
  525. "range" : {
  526. "file.size" : {
  527. "gte" : 1,
  528. "lte" : 1000000
  529. }
  530. }
  531. },
  532. "query": """
  533. file where (file.type == "file" and file.name == "cmd.exe")
  534. """
  535. }
  536. ----
  537. ====
  538. [discrete]
  539. [[eql-search-async]]
  540. === Run an async EQL search
  541. EQL searches in {es} are designed to run on large volumes of data quickly,
  542. often returning results in milliseconds. Because of this, the EQL search API
  543. runs _synchronous_ searches by default. This means the search request waits for
  544. complete results before returning a response.
  545. However, complete results can take longer for searches across:
  546. * <<frozen-indices,Frozen indices>>
  547. * <<modules-cross-cluster-search,Multiple clusters>>
  548. * Many shards
  549. To avoid long waits, you can use the EQL search API's
  550. `wait_for_completion_timeout` parameter to run an _asynchronous_, or _async_,
  551. search.
  552. Set the `wait_for_completion_timeout` parameter to a duration you'd like to wait
  553. for complete search results. If the search request does not finish within this
  554. period, the search becomes an async search. The EQL search
  555. API returns a response that includes:
  556. * A search ID, which can be used to monitor the progress of the async search and
  557. retrieve complete results when it finishes.
  558. * An `is_partial` value of `true`, indicating the response does not contain
  559. complete search results.
  560. * An `is_running` value of `true`, indicating the search is async and ongoing.
  561. The async search continues to run in the background without blocking
  562. other requests.
  563. [%collapsible]
  564. .*Example*
  565. ====
  566. The following request searches the `frozen_sec_logs` index, which has been
  567. <<frozen-indices,frozen>> for storage and is rarely searched.
  568. Because searches on frozen indices are expected to take longer to complete, the
  569. request contains a `wait_for_completion_timeout` parameter value of `2s`
  570. (two seconds).
  571. If the request does not return complete results in two seconds, the search
  572. becomes an async search and a search ID is returned.
  573. [source,console]
  574. ----
  575. GET /frozen_sec_logs/_eql/search
  576. {
  577. "wait_for_completion_timeout": "2s",
  578. "query": """
  579. process where process.name == "cmd.exe"
  580. """
  581. }
  582. ----
  583. // TEST[s/frozen_sec_logs/sec_logs/]
  584. After two seconds, the request returns the following response. Note the
  585. `is_partial` and `is_running` properties are `true`, indicating an ongoing async
  586. search.
  587. [source,console-result]
  588. ----
  589. {
  590. "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",
  591. "is_partial": true,
  592. "is_running": true,
  593. "took": 2000,
  594. "timed_out": false,
  595. "hits": ...
  596. }
  597. ----
  598. // TESTRESPONSE[s/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=/$body.id/]
  599. // TESTRESPONSE[s/"is_partial": true/"is_partial": $body.is_partial/]
  600. // TESTRESPONSE[s/"is_running": true/"is_running": $body.is_running/]
  601. // TESTRESPONSE[s/"took": 2000/"took": $body.took/]
  602. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  603. ====
  604. You can use the the returned search ID and the <<get-async-eql-search-api,get
  605. async EQL search API>> to check the progress of an ongoing async search.
  606. The get async EQL search API also accepts a `wait_for_completion_timeout` query
  607. parameter. Set the `wait_for_completion_timeout` parameter to a duration you'd
  608. like to wait for complete search results. If the request does not complete
  609. during this period, the response returns an `is_partial` value of `true` and no
  610. search results.
  611. [%collapsible]
  612. .*Example*
  613. ====
  614. The following get async EQL search API request checks the progress of the
  615. previous async EQL search. The request specifies a `wait_for_completion_timeout`
  616. query parameter value of `2s` (two seconds).
  617. [source,console]
  618. ----
  619. GET /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?wait_for_completion_timeout=2s
  620. ----
  621. // TEST[skip: no access to search ID]
  622. The request returns the following response. Note the `is_partial` and
  623. `is_running` properties are `false`, indicating the async EQL search has
  624. finished and the search results in the `hits` property are complete.
  625. [source,console-result]
  626. ----
  627. {
  628. "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",
  629. "is_partial": false,
  630. "is_running": false,
  631. "took": 2000,
  632. "timed_out": false,
  633. "hits": ...
  634. }
  635. ----
  636. // TESTRESPONSE[s/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=/$body.id/]
  637. // TESTRESPONSE[s/"took": 2000/"took": $body.took/]
  638. // TESTRESPONSE[s/"_index": "frozen_sec_logs"/"_index": "sec_logs"/]
  639. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  640. ====
  641. [discrete]
  642. [[eql-search-store-async-eql-search]]
  643. === Change the search retention period
  644. By default, the EQL search API only stores async searches and their results for
  645. five days. After this period, any ongoing searches or saved results are deleted.
  646. You can use the EQL search API's `keep_alive` parameter to change the duration
  647. of this period.
  648. .*Example*
  649. [%collapsible]
  650. ====
  651. In the following EQL search API request, the `keep_alive` parameter is `2d` (two
  652. days). This means that if the search becomes async, its results
  653. are stored on the cluster for two days. After two days, the async
  654. search and its results are deleted, even if it's still ongoing.
  655. [source,console]
  656. ----
  657. GET /sec_logs/_eql/search
  658. {
  659. "keep_alive": "2d",
  660. "wait_for_completion_timeout": "2s",
  661. "query": """
  662. process where process.name == "cmd.exe"
  663. """
  664. }
  665. ----
  666. ====
  667. You can use the <<get-async-eql-search-api,get async EQL search API>>'s
  668. `keep_alive` query parameter to later change the retention period. The new
  669. retention period starts after the get async EQL search API request executes.
  670. .*Example*
  671. [%collapsible]
  672. ====
  673. The following get async EQL search API request sets the `keep_alive` query
  674. parameter to `5d` (five days). The async search and its results are deleted five
  675. days after the get async EQL search API request executes.
  676. [source,console]
  677. ----
  678. GET /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?keep_alive=5d
  679. ----
  680. // TEST[skip: no access to search ID]
  681. ====
  682. You can use the <<delete-async-eql-search-api,delete async EQL search API>> to
  683. manually delete an async EQL search before the `keep_alive` period ends. If the
  684. search is still ongoing, this cancels the search request.
  685. .*Example*
  686. [%collapsible]
  687. ====
  688. The following delete async EQL search API request deletes an async EQL search
  689. and its results.
  690. [source,console]
  691. ----
  692. DELETE /_eql/search/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?keep_alive=5d
  693. ----
  694. // TEST[skip: no access to search ID]
  695. ====
  696. [discrete]
  697. [[eql-search-store-sync-eql-search]]
  698. === Store synchronous EQL searches
  699. By default, the EQL search API only stores async searches that cannot be
  700. completed within the period set by the `wait_for_completion_timeout` parameter.
  701. To save the results of searches that complete during this period, set the
  702. `keep_on_completion` parameter to `true`.
  703. [%collapsible]
  704. .*Example*
  705. ====
  706. In the following EQL search API request, the `keep_on_completion` parameter is
  707. `true`. This means the search results are stored on the cluster, even if
  708. the search completes within the `2s` (two-second) period set by the
  709. `wait_for_completion_timeout` parameter.
  710. [source,console]
  711. ----
  712. GET /sec_logs/_eql/search
  713. {
  714. "keep_on_completion": true,
  715. "wait_for_completion_timeout": "2s",
  716. "query": """
  717. process where process.name == "cmd.exe"
  718. """
  719. }
  720. ----
  721. The API returns the following response. Note that a search ID is provided in the
  722. `id` property. The `is_partial` and `is_running` properties are `false`,
  723. indicating the EQL search was synchronous and returned complete search results.
  724. [source,console-result]
  725. ----
  726. {
  727. "id": "FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=",
  728. "is_partial": false,
  729. "is_running": false,
  730. "took": 52,
  731. "timed_out": false,
  732. "hits": ...
  733. }
  734. ----
  735. // TESTRESPONSE[s/FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=/$body.id/]
  736. // TESTRESPONSE[s/"took": 52/"took": $body.took/]
  737. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]
  738. You can use the search ID and the <<get-async-eql-search-api,get async EQL
  739. search API>> to retrieve the same results later.
  740. [source,console]
  741. ----
  742. GET /_eql/search/FjlmbndxNmJjU0RPdExBTGg0elNOOEEaQk9xSjJBQzBRMldZa1VVQ2pPa01YUToxMDY=
  743. ----
  744. // TEST[skip: no access to search ID]
  745. ====
  746. Saved synchronous searches are still subject to the storage retention period set
  747. by the `keep_alive` parameter. After this period, the search and its saved
  748. results are deleted.
  749. You can also manually delete saved synchronous searches using the
  750. <<delete-async-eql-search-api,delete async EQL search API>>.
  751. [discrete]
  752. [[eql-search-case-sensitive]]
  753. === Run a case-sensitive EQL search
  754. By default, matching for EQL queries is case-insensitive. You can use the EQL
  755. search API's `case_sensitive` parameter to toggle case sensitivity on or off.
  756. .*Example*
  757. [%collapsible]
  758. ====
  759. The following search request contains a query that matches `process` events
  760. with a `process.path` containing `System32`.
  761. Because the `case_sensitive` parameter is `true`, this query only matches
  762. `process.path` values containing `System32` with the exact same capitalization.
  763. A `process.path` value containing `system32` or `SYSTEM32` would not match this
  764. query.
  765. [source,console]
  766. ----
  767. GET /sec_logs/_eql/search
  768. {
  769. "keep_on_completion": true,
  770. "case_sensitive": true,
  771. "query": """
  772. process where stringContains(process.path, "System32")
  773. """
  774. }
  775. ----
  776. ====