EQL search API

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Returns search results for an Event Query Language (EQL) query.

In Elasticsearch, EQL assumes each document in a data stream or index corresponds to an event.

  1. GET /my-index-000001/_eql/search
  2. {
  3. "query": """
  4. process where process.name = "regsvr32.exe"
  5. """
  6. }

Request

GET /<target>/_eql/search

POST /<target>/_eql/search

Prerequisites

See Required fields.

Limitations

See EQL limitations.

Path parameters

<target>

(Required, string) Comma-separated list of data streams, indices, or index aliases used to limit the request. Accepts wildcard (*) expressions.

To search all data streams and indices in a cluster, use _all or *.

Query parameters

allow_no_indices

(Optional, boolean) If true, the request does not return an error if a wildcard expression or _all value retrieves only missing or closed indices.

This parameter also applies to index aliases that point to a missing or closed index.

Defaults to false.

expand_wildcards

(Optional, string) Controls what kind of indices that wildcard expressions can expand to. Multiple values are accepted when separated by a comma, as in open,hidden. Valid values are:

  • all

    Expand to open and closed indices, including hidden indices.

    open

    Expand only to open indices.

    closed

    Expand only to closed indices.

    hidden

    Expansion of wildcards will include hidden indices. Must be combined with open, closed, or both.

    none

    Wildcard expressions are not accepted.

Defaults to open.

ignore_unavailable

(Optional, boolean) If true, missing or closed indices are not included in the response. Defaults to false.

keep_alive

(Optional, time value) Period for which the search and its results are stored on the cluster. Defaults to 5d (five days).

When this period expires, the search and its results are deleted, even if the search is still ongoing.

If the keep_on_completion parameter is false, Elasticsearch only stores async searches that do not complete within the period set by the wait_for_completion_timeout parameter, regardless of this value.

You can also specify this value using the keep_alive request body parameter. If both parameters are specified, only the query parameter is used.

keep_on_completion

(Optional, boolean) If true, the search and its results are stored on the cluster.

If false, the search and its results are stored on the cluster only if the request does not complete during the period set by the wait_for_completion_timeout parameter. Defaults to false.

You can also specify this value using the keep_on_completion request body parameter. If both parameters are specified, only the query parameter is used.

wait_for_completion_timeout

(Optional, time value) Timeout duration to wait for the request to finish. Defaults to no timeout, meaning the request waits for complete search results.

If this parameter is specified and the request completes during this period, complete search results are returned.

If the request does not complete during this period, the search becomes an async search.

You can also specify this value using the wait_for_completion_timeout request body parameter. If both parameters are specified, only the query parameter is used.

Request body

case_sensitive

(Optional, boolean) If true, matching for the EQL query is case sensitive. Defaults to false.

event_category_field

(Required*, string) Field containing the event classification, such as process, file, or network.

Defaults to event.category, as defined in the Elastic Common Schema (ECS). If a data stream or index does not contain the event.category field, this value is required.

The event category field is typically mapped as a field type in the keyword family.

fetch_size

(Optional, integer) Maximum number of events to search at a time for sequence queries. Defaults to 1000.

This value must be greater than 2 but cannot exceed the value of the index.max_result_window setting, which defaults to 10000.

Internally, a sequence query fetches and paginates sets of events to search for matches. This parameter controls the size of those sets. This parameter does not limit the total number of events searched or the number of matching events returned.

A greater fetch_size value often increases search speed but uses more memory.

filter

(Optional, query DSL object) Query, written in query DSL, used to filter the events on which the EQL query runs.

keep_alive

(Optional, time value) Period for which the search and its results are stored on the cluster. Defaults to 5d (five days).

When this period expires, the search and its results are deleted, even if the search is still ongoing.

If the keep_on_completion parameter is false, Elasticsearch only stores async searches that do not complete within the period set by the wait_for_completion_timeout parameter, regardless of this value.

You can also specify this value using the keep_alive query parameter. If both parameters are specified, only the query parameter is used.

keep_on_completion

(Optional, boolean) If true, the search and its results are stored on the cluster.

If false, the search and its results are stored on the cluster only if the request does not complete during the period set by the wait_for_completion_timeout parameter. Defaults to false.

You can also specify this value using the keep_on_completion query parameter. If both parameters are specified, only the query parameter is used.

query

(Required, string) EQL query you wish to run.

This parameter supports a subset of EQL syntax. See Unsupported syntax.

size

(Optional, integer or float) For basic queries, the maximum number of matching events to return.

For sequence queries, the maximum number of matching sequences to return.

Defaults to 10. This value must be greater than 0.

You cannot use pipes, such as head or tail, to exceed this value.

tiebreaker_field

(Optional, string) Field used to sort events with the same timestamp field value. Defaults to event.sequence, as defined in the Elastic Common Schema (ECS).

By default, matching events in the search response are sorted by timestamp, converted to milliseconds since the Unix epoch, in ascending order. If two or more events share the same timestamp, this field is used to sort the events in ascending, lexicographic order.

timestamp_field

(Required*, string) Field containing event timestamp.

Defaults to @timestamp, as defined in the Elastic Common Schema (ECS). If a data stream or index does not contain the @timestamp field, this value is required.

Events in the API response are sorted by this field’s value, converted to milliseconds since the Unix epoch, in ascending order.

The timestamp field is typically mapped as a date or date_nanos field.

wait_for_completion_timeout

(Optional, time value) Timeout duration to wait for the request to finish. Defaults to no timeout, meaning the request waits for complete search results.

If this parameter is specified and the request completes during this period, complete search results are returned.

If the request does not complete during this period, the search becomes an async search.

You can also specify this value using the wait_for_completion_timeout query parameter. If both parameters are specified, only the query parameter is used.

Response body

id

(string) Identifier for the search.

This search ID is only provided if one of the following conditions is met:

You can use this ID with the get async EQL search API to get the current status and available results for the search.

is_partial

(boolean) If true, the response does not contain complete search results.

is_running

(boolean) If true, the search request is still executing.

If this parameter and the is_partial parameter are true, the search is an ongoing async search. If the keep_alive period does not pass, the complete search results will be available when the search completes.

If is_partial is true but is_running is false, the search returned partial results due to a failure. Only some shards returned results or the node coordinating the search failed.

took

(integer) Milliseconds it took Elasticsearch to execute the request.

This value is calculated by measuring the time elapsed between receipt of a request on the coordinating node and the time at which the coordinating node is ready to send the response.

Took time includes:

  • Communication time between the coordinating node and data nodes
  • Time the request spends in the search thread pool, queued for execution
  • Actual execution time

Took time does not include:

  • Time needed to send the request to Elasticsearch
  • Time needed to serialize the JSON response
  • Time needed to send the response to a client

timed_out

(boolean) If true, the request timed out before completion.

hits

(object) Contains matching events and sequences. Also contains related metadata.

Properties of hits

  • total

    (object) Metadata about the number of matching events or sequences.

    Properties of total

    • value

      (integer) For basic queries, the total number of matching events.

      For sequence queries, the total number of matching sequences.

      relation

      (string) Indicates whether the number of events or sequences returned is accurate or a lower bound.

      Returned values are:

      eq

      Accurate

      gte

      Lower bound, including returned events or sequences

  1. `sequences`
  2. (array of objects) Contains event sequences matching the query. Each object represents a matching sequence. This parameter is only returned for EQL queries containing a [sequence]($38d25857bc9a9de1.md#eql-sequences "Sequences").
  3. Properties of `sequences` objects
  4. - `join_keys`
  5. (array of values) Shared field values used to constrain matches in the sequence. These are defined using the [`by` keyword]($38d25857bc9a9de1.md#eql-sequences "Sequences") in the EQL query syntax.
  6. `events`
  7. (array of objects) Contains events matching the query. Each object represents a matching event.
  8. Properties of `events` objects
  9. `_index`
  10. (string) Name of the index containing the event.
  11. `_id`
  12. (string) Unique identifier for the event. This ID is only unique within the index.
  13. `_version`
  14. (integer) Version of the document (event). This version is incremented each time the document is updated.
  15. `_seq_no`
  16. (integer) Sequence number assigned to the document (event).
  17. Sequence numbers are used to ensure an older version of a document doesnt overwrite a newer version. See [Optimistic concurrency control]($1b476ca439dbec53.md "Optimistic concurrency control").
  18. `_primary_term`
  19. (integer) Primary term assigned to the document. See [Optimistic concurrency control]($1b476ca439dbec53.md "Optimistic concurrency control").
  20. `_score`
  21. (float) Positive 32-bit floating point number used to determine the relevance of the event. See [Relevance scores]($e8aa4b0e7ff9e612.md#relevance-scores "Relevance scores").
  22. `_source`
  23. (object) Original JSON body passed for the event at index time.
  • events

    (array of objects) Contains events matching the query. Each object represents a matching event.

    Properties of events objects

    • _index

      (string) Name of the index containing the event.

      _id

      (string) (string) Unique identifier for the event. This ID is only unique within the index.

      _score

      (float) Positive 32-bit floating point number used to determine the relevance of the event. See Relevance scores.

      _source

      (object) Original JSON body passed for the event at index time.

Examples

Basic query example

The following EQL search request searches for events with an event.category of process that meet the following conditions:

  • A process.name of cmd.exe
  • An process.pid other than 2013
  1. GET /my-index-000001/_eql/search
  2. {
  3. "query": """
  4. process where (process.name == "cmd.exe" and process.pid != 2013)
  5. """
  6. }

The API returns the following response. Matching events in the hits.events property are sorted by timestamp, converted to milliseconds since the Unix epoch, in ascending order.

If two or more events share the same timestamp, the tiebreaker_field field is used to sort the events in ascending, lexicographic order.

  1. {
  2. "is_partial": false,
  3. "is_running": false,
  4. "took": 6,
  5. "timed_out": false,
  6. "hits": {
  7. "total": {
  8. "value": 2,
  9. "relation": "eq"
  10. },
  11. "events": [
  12. {
  13. "_index": "my-index-000001",
  14. "_type": "_doc",
  15. "_id": "babI3XMBI9IjHuIqU0S_",
  16. "_score": null,
  17. "_source": {
  18. "@timestamp": "2099-12-06T11:04:05.000Z",
  19. "event": {
  20. "category": "process",
  21. "id": "edwCRnyD",
  22. "sequence": 1
  23. },
  24. "process": {
  25. "pid": 2012,
  26. "name": "cmd.exe",
  27. "executable": "C:\\Windows\\System32\\cmd.exe"
  28. }
  29. }
  30. },
  31. {
  32. "_index": "my-index-000001",
  33. "_type": "_doc",
  34. "_id": "b6bI3XMBI9IjHuIqU0S_",
  35. "_score": null,
  36. "_source": {
  37. "@timestamp": "2099-12-07T11:06:07.000Z",
  38. "event": {
  39. "category": "process",
  40. "id": "cMyt5SZ2",
  41. "sequence": 3
  42. },
  43. "process": {
  44. "pid": 2012,
  45. "name": "cmd.exe",
  46. "executable": "C:\\Windows\\System32\\cmd.exe"
  47. }
  48. }
  49. }
  50. ]
  51. }
  52. }

Sequence query example

The following EQL search request matches a sequence of events that:

  1. Start with an event with:

    • An event.category of file
    • A file.name of cmd.exe
    • An process.pid other than 2013
  2. Followed by an event with:

    • An event.category of process
    • A process.executable that contains the substring regsvr32

These events must also share the same process.pid value.

  1. GET /my-index-000001/_eql/search
  2. {
  3. "query": """
  4. sequence by process.pid
  5. [ file where file.name == "cmd.exe" and process.pid != 2013 ]
  6. [ process where stringContains(process.executable, "regsvr32") ]
  7. """
  8. }

The API returns the following response. Matching sequences are included in the hits.sequences property. The hits.sequences.join_keys property contains the shared process.pid value for each matching event.

  1. {
  2. "is_partial": false,
  3. "is_running": false,
  4. "took": 6,
  5. "timed_out": false,
  6. "hits": {
  7. "total": {
  8. "value": 1,
  9. "relation": "eq"
  10. },
  11. "sequences": [
  12. {
  13. "join_keys": [
  14. 2012
  15. ],
  16. "events": [
  17. {
  18. "_index": "my-index-000001",
  19. "_type": "_doc",
  20. "_id": "AtOJ4UjUBAAx3XR5kcCM",
  21. "_version": 1,
  22. "_seq_no": 1,
  23. "_primary_term": 1,
  24. "_score": null,
  25. "_source": {
  26. "@timestamp": "2099-12-06T11:04:07.000Z",
  27. "event": {
  28. "category": "file",
  29. "id": "dGCHwoeS",
  30. "sequence": 2
  31. },
  32. "file": {
  33. "accessed": "2099-12-07T11:07:08.000Z",
  34. "name": "cmd.exe",
  35. "path": "C:\\Windows\\System32\\cmd.exe",
  36. "type": "file",
  37. "size": 16384
  38. },
  39. "process": {
  40. "pid": 2012,
  41. "name": "cmd.exe",
  42. "executable": "C:\\Windows\\System32\\cmd.exe"
  43. }
  44. }
  45. },
  46. {
  47. "_index": "my-index-000001",
  48. "_type": "_doc",
  49. "_id": "OQmfCaduce8zoHT93o4H",
  50. "_version": 1,
  51. "_seq_no": 3,
  52. "_primary_term": 1,
  53. "_score": null,
  54. "_source": {
  55. "@timestamp": "2099-12-07T11:07:09.000Z",
  56. "event": {
  57. "category": "process",
  58. "id": "aR3NWVOs",
  59. "sequence": 4
  60. },
  61. "process": {
  62. "pid": 2012,
  63. "name": "regsvr32.exe",
  64. "command_line": "regsvr32.exe /s /u /i:https://...RegSvr32.sct scrobj.dll",
  65. "executable": "C:\\Windows\\System32\\regsvr32.exe"
  66. }
  67. }
  68. }
  69. ]
  70. }
  71. ]
  72. }
  73. }