| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128 | [role="xpack"][testenv="basic"][[eql-syntax]]== EQL syntax reference++++<titleabbrev>Syntax reference</titleabbrev>++++[discrete][[eql-basic-syntax]]=== Basic syntaxEQL queries require an event category and a matching condition. The `where`keyword connects them.[source,eql]----event_category where condition----An event category is an indexed value of the <<eql-required-fields,eventcategory field>>. By default, the <<eql-search-api,EQL search API>> uses the`event.category` field from the {ecs-ref}[Elastic Common Schema (ECS)]. You canspecify another event category field using the API's<<specify-a-timestamp-or-event-category-field,`event_category_field`>>parameter.For example, the following EQL query matches events with an event category of`process` and a `process.name` of `svchost.exe`:[source,eql]----process where process.name == "svchost.exe"----[discrete][[eql-syntax-match-any-event-category]]=== Match any event categoryTo match events of any category, use the `any` keyword. You can also use the`any` keyword to search for documents without a event category field.For example, the following EQL query matches any documents with a`network.protocol` field value of `http`:[source,eql]----any where network.protocol == "http"----[discrete][[eql-syntax-escape-an-event-category]]=== Escape an event categoryUse enclosing double quotes (`"`) or three enclosing double quotes (`"""`) toescape event categories that:* Contain a special character, such as a hyphen (`-`) or dot (`.`)* Contain a space* Start with a numeral[source,eql]----".my.event.category""my-event-category""my event category""6eventcategory"""".my.event.category""""""my-event-category""""""my event category""""""6eventcategory"""----[discrete][[eql-syntax-escape-a-field-name]]=== Escape a field nameUse enclosing backticks (+++`+++) to escape field names that:* Contain a hyphen (`-`)* Contain a space* Start with a numeral[source,eql]----`my-field``my field``6myfield`----Use double backticks (+++``+++) to escape any backticks (+++`+++) in the fieldname.[source,eql]----my`field -> `my``field`----[discrete][[eql-syntax-conditions]]=== ConditionsA condition consists of one or more criteria an event must match.You can specify and combine these criteria using the following operators. MostEQL operators are case-sensitive by default.[discrete][[eql-syntax-comparison-operators]]=== Comparison operators[source,eql]----<   <=   ==   :   !=   >=   >----`<` (less than)::Returns `true` if the value to the left of the operator is less than the valueto the right. Otherwise returns `false`.`<=` (less than or equal) ::Returns `true` if the value to the left of the operator is less than or equal tothe value to the right. Otherwise returns `false`.`==` (equal, case-sensitive)::Returns `true` if the values to the left and right of the operator are equal.Otherwise returns `false`. Wildcards are not supported.`:` (equal, case-insensitive)::Returns `true` if strings to the left and right of the operator are equal.Otherwise returns `false`. Can only be used to compare strings. Supports<<eql-syntax-wildcards,wildcards>> and <<eql-syntax-lookup-operators,listlookups>>.`!=` (not equal, case-sensitive)::Returns `true` if the values to the left and right of the operator are notequal. Otherwise returns `false`. Wildcards are not supported.`>=` (greater than or equal) ::Returns `true` if the value to the left of the operator is greater than or equalto the value to the right. Otherwise returns `false`. When comparing strings,the operator uses a case-sensitive lexicographic order.`>` (greater than)::Returns `true` if the value to the left of the operator is greater than thevalue to the right. Otherwise returns `false`. When comparing strings,the operator uses a case-sensitive lexicographic order.NOTE: `=` is not supported as an equal operator. Use `==` or `:` instead.[discrete][[eql-syntax-pattern-comparison-keywords]]=== Pattern comparison keywords[source,eql]----my_field like  "VALUE*"         // case-sensitive wildcard matchingmy_field like~ "value*"         // case-insensitive wildcard matchingmy_field regex  "VALUE[^Z].?"   // case-sensitive regex matchingmy_field regex~ "value[^z].?"   // case-insensitive regex matching----`like` (case-sensitive)::Returns `true` if the string to the left of the keyword matches a<<eql-syntax-wildcards,wildcard pattern>> to the right. Supports<<eql-syntax-lookup-operators,list lookups>>. Can only be used to comparestrings. For case-insensitive matching, use `like~`.`regex` (case-sensitive)::Returns `true` if the string to the left of the keyword matches a regularexpression to the right. For supported regular expression syntax, see<<regexp-syntax>>. Supports <<eql-syntax-lookup-operators,list lookups>>. Canonly be used to compare strings. For case-insensitive matching, use `regex~`.[discrete][[limitations-for-comparisons]]=== Limitations for comparisonsYou cannot chain comparisons. Instead, use a<<eql-syntax-logical-operators,logical operator>> between comparisons. Forexample, `foo < bar <= baz` is not supported. However, you can rewrite theexpression as `foo < bar and bar <= baz`, which is supported.You also cannot compare a field to another field, even if the fields are changedusing a <<eql-functions,function>>.*Example* +The following EQL query compares the `process.parent_name` fieldvalue to a static value, `foo`. This comparison is supported.However, the query also compares the `process.parent.name` field value to the`process.name` field. This comparison is not supported and will return anerror for the entire query.[source,eql]----process where process.parent.name == "foo" and process.parent.name == process.name----Instead, you can rewrite the query to compare both the `process.parent.name`and `process.name` fields to static values.[source,eql]----process where process.parent.name == "foo" and process.name == "foo"----[discrete][[eql-syntax-logical-operators]]=== Logical operators[source,eql]----and  or  not----`and`::Returns `true` only if the condition to the left and right _both_ return `true`.Otherwise returns `false`.`or`::Returns `true` if one of the conditions to the left or right `true`.Otherwise returns `false`.`not`::Returns `true` if the condition to the right is `false`.[discrete][[eql-syntax-lookup-operators]]=== Lookup operators[source,eql]----my_field in ("Value-1", "VALUE2", "VAL3")                 // case-sensitivemy_field in~ ("value-1", "value2", "val3")                // case-insensitivemy_field not in ("Value-1", "VALUE2", "VAL3")             // case-sensitivemy_field not in~ ("value-1", "value2", "val3")            // case-insensitivemy_field : ("value-1", "value2", "val3")                  // case-insensitivemy_field like  ("Value-*", "VALUE2", "VAL?")              // case-sensitivemy_field like~ ("value-*", "value2", "val?")              // case-insensitivemy_field regex  ("[vV]alue-[0-9]", "VALUE[^2].?", "VAL3") // case-sensitivemy_field regex~  ("value-[0-9]", "value[^2].?", "val3")   // case-sensitive----`in` (case-sensitive)::Returns `true` if the value is contained in the provided list. Forcase-insensitive matching, use `in~`.`not in` (case-sensitive)::Returns `true` if the value is not contained in the provided list. Forcase-insensitive matching, use `not in~`.`:` (case-insensitive)::Returns `true` if the string is contained in the provided list. Can only be usedto compare strings.`like` (case-sensitive)::Returns `true` if the string matches a <<eql-syntax-wildcards,wildcard pattern>>in the provided list. Can only be used to compare strings. For case-insensitivematching, use `like~`.`regex` (case-sensitive)::Returns `true` if the string matches a regular expression pattern in theprovided list. For supported regular expression syntax, see <<regexp-syntax>>.Can only be used to compare strings. For case-insensitive matching, use`regex~`.[discrete][[eql-syntax-math-operators]]=== Math operators[source,eql]----+  -  *  /  %----`+` (add)::Adds the values to the left and right of the operator.`-` (subtract)::Subtracts the value to the right of the operator from the value to the left.`*` (multiply)::Multiplies the values to the left and right of the operator.`/` (divide)::Divides the value to the left of the operator by the value to the right.+[[eql-divide-operator-float-rounding]][WARNING]====If both the dividend and divisor are integers, the divide (`\`) operation_rounds down_ any returned floating point numbers to the nearest integer. Toavoid rounding, convert either the dividend or divisor to a float.*Example* +The `process.args_count` field is a <<number,`long`>> integer field containing acount of process arguments.A user might expect the following EQL query to only match events with a`process.args_count` value of `4`.[source,eql]----process where ( 4 / process.args_count ) == 1----However, the EQL query matches events with a `process.args_count` value of `3`or `4`.For events with a `process.args_count` value of `3`, the divide operationreturns a float of `1.333...`, which is rounded down to `1`.To match only events with a `process.args_count` value of `4`, converteither the dividend or divisor to a float.The following EQL query changes the integer `4` to the equivalent float `4.0`.[source,eql]----process where ( 4.0 / process.args_count ) == 1----====`%` (modulo)::Divides the value to the left of the operator by the value to the right. Returns only the remainder.[discrete][[eql-syntax-match-any-condition]]=== Match any conditionTo match events solely on event category, use the `where true` condition.For example, the following EQL query matches any `file` events:[source,eql]----file where true----To match any event, you can combine the `any` keyword with the `where true`condition:[source,eql]----any where true----[discrete][[eql-syntax-check-field-exists]]=== Check if a field existsTo match events containing any value for a field, compare the field to `null`using the `!=` operator:[source,eql]----my_field != null----To match events that do not contain a field value, compare the field to `null`using the `==` operator:[source,eql]----my_field == null----IMPORTANT: To avoid errors, the field must contain a non-`null` value in atleast one document or be <<explicit-mapping,explicitly mapped>>.[discrete][[eql-syntax-strings]]=== StringsStrings are enclosed in double quotes (`"`).[source,eql]----"hello world"----Strings enclosed in single quotes (`'`) are not supported.[discrete][[eql-syntax-escape-characters]]=== Escape characters in a stringWhen used within a string, special characters, such as a carriage return ordouble quote (`"`), must be escaped with a preceding backslash (`\`).[source,eql]----"example \r of \" escaped \n characters"----[options="header"]|====| Escape sequence | Literal character|`\n`             | Newline (linefeed)|`\r`             | Carriage return|`\t`             | Tab|`\\`             | Backslash (`\`)|`\"`             | Double quote (`"`)|====You can escape Unicode characters using a hexadecimal `\u{XXXXXXXX}` escapesequence. The hexadecimal value can be 2-8 characters and is case-insensitive.Values shorter than 8 characters are zero-padded. You can use these escapesequences to include non-printable or right-to-left (RTL) characters in yourstrings. For example, you can escape a{wikipedia}/Right-to-left_mark[right-to-left mark (RLM)] as `\u{200f}`,`\u{200F}`, or `\u{0000200f}`.IMPORTANT: The single quote (`'`) character is reserved for future use. Youcannot use an escaped single quote (`\'`) for literal strings. Use an escapeddouble quote (`\"`) instead.[discrete][[eql-syntax-raw-strings]]=== Raw stringsRaw strings treat special characters, such as backslashes (`\`), as literalcharacters. Raw strings are enclosed in three double quotes (`"""`).[source,eql]----"""Raw string with a literal double quote " and blackslash \ included"""----A raw string cannot contain three consecutive double quotes (`"""`). Instead,use a regular string with the `\"` escape sequence.[source,eql]----"String containing \"\"\" three double quotes"----[discrete][[eql-syntax-wildcards]]=== WildcardsFor string comparisons using the `:` operator or `like` keyword, you can use the`*` and `?` wildcards to match specific patterns. The `*` wildcard matches zeroor more characters:[source,eql]----my_field : "doc*"     // Matches "doc", "docs", or "document" but not "DOS"my_field : "*doc"     // Matches "adoc" or "asciidoc"my_field : "d*c"      // Matches "doc" or "disc"my_field like "DOC*"  // Matches "DOC", "DOCS", "DOCs", or "DOCUMENT" but not "DOS"my_field like "D*C"   // Matches "DOC", "DISC", or "DisC"----The `?` wildcard matches exactly one character:[source,eql]----my_field : "doc?"     // Matches "docs" but not "doc", "document", or "DOS"my_field : "?doc"     // Matches "adoc" but not "asciidoc"my_field : "d?c"      // Matches "doc" but not "disc"my_field like "DOC?"  // Matches "DOCS" or "DOCs" but not "DOC", "DOCUMENT", or "DOS"my_field like "D?c"   // Matches "DOC" but not "DISC"----The `:` operator and `like` keyword also support wildcards in<<eql-syntax-lookup-operators,list lookups>>:[source,eql]----my_field : ("doc*", "f*o", "ba?", "qux")my_field like ("Doc*", "F*O", "BA?", "QUX")----[discrete][[eql-sequences]]=== SequencesYou can use EQL sequences to describe and match an ordered series of events.Each item in a sequence is an event category and event condition,surrounded by square brackets (`[ ]`). Events are listed in ascendingchronological order, with the most recent event listed last.[source,eql]----sequence  [ event_category_1 where condition_1 ]  [ event_category_2 where condition_2 ]  ...----*Example* +The following EQL sequence query matches this series of ordered events:. Start with an event with:+--* An event category of `file`* A `file.extension` of `exe`--. Followed by an event with an event category of `process`[source,eql]----sequence  [ file where file.extension == "exe" ]  [ process where true ]----[discrete][[eql-with-maxspan-keywords]]=== `with maxspan` keywordsYou can use the `with maxspan` keywords to constrain a sequence to a specifiedtimespan. All events in a matching sequence must occur within this duration,starting at the first event's timestamp.The `maxspan` keyword accepts <<time-units,time value>> arguments.[source,eql]----sequence with maxspan=30s  [ event_category_1 where condition_1 ] by field_baz  [ event_category_2 where condition_2 ] by field_bar  ...----*Example* +The following sequence query uses a `maxspan` value of `15m` (15 minutes).Events in a matching sequence must occur within 15 minutes of the first event'stimestamp.[source,eql]----sequence with maxspan=15m  [ file where file.extension == "exe" ]  [ process where true ]----[discrete][[eql-by-keyword]]=== `by` keywordYou can use the `by` keyword with sequences to only match events that share thesame field values. If a field value should be shared across all events, youcan use `sequence by`.[source,eql]----sequence by field_foo  [ event_category_1 where condition_1 ] by field_baz  [ event_category_2 where condition_2 ] by field_bar  ...----*Example* +The following sequence query uses the `by` keyword to constrain matching eventsto:* Events with the same `user.name` value* `file` events with a `file.path` value equal to the following `process`   event's `process.executable` value.[source,eql]----sequence  [ file where file.extension == "exe" ] by user.name, file.path  [ process where true ] by user.name, process.executable----Because the `user.name` field is shared across all events in the sequence, itcan be included using `sequence by`. The following sequence is equivalent to theprior one.[source,eql]----sequence by user.name  [ file where file.extension == "exe" ] by file.path  [ process where true ] by process.executable----You can combine the `sequence by` and `with maxspan` keywords to constrain asequence by both field values and a timespan.[source,eql]----sequence by field_foo with maxspan=30s  [ event_category_1 where condition_1 ] by field_baz  [ event_category_2 where condition_2 ] by field_bar  ...----*Example* +The following sequence query uses the `sequence by` keyword and `with maxspan`keywords to match only a sequence of events that:* Share the same `user.name` field values* Occur within `15m` (15 minutes) of the first matching event[source,eql]----sequence by user.name with maxspan=15m  [ file where file.extension == "exe" ] by file.path  [ process where true ] by process.executable----[discrete][[eql-until-keyword]]=== `until` keywordYou can use the `until` keyword to specify an expiration event for a sequence.If this expiration event occurs _between_ matching events in a sequence, thesequence expires and is not considered a match. If the expiration event occurs_after_ matching events in a sequence, the sequence is still considered amatch. The expiration event is not included in the results.[source,eql]----sequence  [ event_category_1 where condition_1 ]  [ event_category_2 where condition_2 ]  ...until [ event_category_3 where condition_3 ]----*Example* +A dataset contains the following event sequences, grouped by shared IDs:[source,txt]----A, BA, B, CA, C, B----The following EQL query searches the dataset for sequences containingevent `A` followed by event `B`. Event `C` is used as an expiration event.[source,eql]----sequence by ID  A  Buntil C----The query matches sequences `A, B` and `A, B, C` but not `A, C, B`.[TIP]====The `until` keyword can be useful when searching for process sequences inWindows event logs.In Windows, a process ID (PID) is unique only while a process is running. Aftera process terminates, its PID can be reused.You can search for a sequence of events with the same PID value using the `by`and `sequence by` keywords.*Example* +The following EQL query uses the `sequence by` keyword to match asequence of events that share the same `process.pid` value.[source,eql]----sequence by process.pid  [ process where event.type == "start" and process.name == "cmd.exe" ]  [ process where file.extension == "exe" ]----However, due to PID reuse, this can result in a matching sequence thatcontains events across unrelated processes. To prevent false positives, you canuse the `until` keyword to end matching sequences before a process terminationevent.The following EQL query uses the `until` keyword to end sequences before`process` events with an `event.type` of `stop`. These events indicate a processhas been terminated.[source,eql]----sequence by process.pid  [ process where event.type == "start" and process.name == "cmd.exe" ]  [ process where file.extension == "exe" ]until [ process where event.type == "stop" ]----====[discrete][[eql-functions]]=== FunctionsYou can use EQL functions to convert data types, perform math, manipulatestrings, and more. For a list of supported functions, see <<eql-function-ref>>.[discrete][[eql-case-insensitive-functions]]=== Case-insensitive functionsMost EQL functions are case-sensitive by default. To make a functioncase-insensitive, use the `~` operator after the function name:[source,eql]----stringContains(process.name,".exe")  // Matches ".exe" but not ".EXE" or ".Exe"stringContains~(process.name,".exe") // Matches ".exe", ".EXE", or ".Exe"----[discrete][[eql-how-functions-impact-search-performance]]=== How functions impact search performanceUsing functions in EQL queries can result in slower search speeds. If youoften use functions to transform indexed data, you can speed up search by makingthese changes during indexing instead. However, that often means slower indexspeeds.*Example* +An index contains the `file.path` field. `file.path` contains the full path to afile, including the file extension.When running EQL searches, users often use the `endsWith` function with the`file.path` field to match file extensions:[source,eql]----file where endsWith(file.path,".exe") or endsWith(file.path,".dll")----While this works, it can be repetitive to write and can slow search speeds. Tospeed up search, you can do the following instead:. <<indices-put-mapping,Add a new field>>, `file.extension`, to the index. The  `file.extension` field will contain only the file extension from the  `file.path` field.. Use an <<ingest,ingest pipeline>> containing the <<grok-processor,`grok`>>  processor or another preprocessor tool to extract the file extension from the  `file.path` field before indexing.. Index the extracted file extension to the `file.extension` field.These changes may slow indexing but allow for faster searches. Userscan use the `file.extension` field instead of multiple `endsWith` functioncalls:[source,eql]----file where file.extension in ("exe", "dll")----We recommend testing and benchmarking any indexing changes before deploying themin production. See <<tune-for-indexing-speed>> and <<tune-for-search-speed>>.[discrete][[eql-pipes]]=== PipesEQL pipes filter, aggregate, and post-process events returned byan EQL query. You can use pipes to narrow down EQL query results or make themmore specific.Pipes are delimited using the pipe (`|`) character.[source,eql]----event_category where condition | pipe----*Example* +The following EQL query uses the `tail` pipe to return only the 10 most recentevents matching the query.[source,eql]----authentication where agent.id == 4624| tail 10----You can pass the output of a pipe to another pipe. This lets you use multiplepipes with a single query.For a list of supported pipes, see <<eql-pipe-ref>>.[discrete][[eql-syntax-limitations]]=== LimitationsEQL has the following limitations.[discrete][[eql-uses-fields-parameter]]==== EQL uses the `fields` parameterEQL retrieves field values using the search API's <<search-fields-param,`fields`parameter>>. Any limitations on the `fields` parameter also apply to EQLqueries. For example, if `_source` is disabled for any returned fields or atindex level, the values cannot be retrieved.[discrete][[eql-compare-fields]]==== Comparing fieldsYou cannot use EQL comparison operators to compare a field toanother field. This applies even if the fields are changed using a<<eql-functions,function>>.[discrete][[eql-text-fields]]==== Text fields are not supportedEQL searches do not support <<text,`text`>> fields. To a search a `text` field,use the EQL search API's <<eql-search-filter-query-dsl,Query DSL `filter`>>parameter.[discrete][[eql-array-fields]]==== Array field values are not supportedEQL does not support <<array,array>> field values, also known asmulti-value fields. EQL searches on array field values may return inconsistentresults.[discrete][[eql-nested-fields]]==== EQL search on nested fieldsYou cannot use EQL to search the values of a <<nested,`nested`>> field or thesub-fields of a `nested` field. However, data streams and indices containing`nested` field mappings are otherwise supported.[discrete][[eql-ccs-support]]==== {ccs-cap} is not supportedEQL search APIs do not support <<modules-cross-cluster-search,{ccs}({ccs-init})>>.[discrete][[eql-unsupported-syntax]]==== Differences from Endgame EQL syntax{es} EQL differs from the {eql-ref}/index.html[Elastic Endgame EQL syntax] asfollows:* In {es} EQL, most operators are case-sensitive. For example,`process_name == "cmd.exe"` is not equivalent to`process_name == "Cmd.exe"`.* In {es} EQL, functions are case-sensitive. To make a functioncase-insensitive, use `~`, such as `endsWith~(process_name, ".exe")`.* For case-insensitive equality comparisons, use the `:` operator. Both `*` and`?` are recognized wildcard characters.* The `==` and `!=` operators do not expand wildcard characters. For example,`process_name == "cmd*.exe"` interprets `*` as a literal asterisk, not awildcard.* For wildcard matching, use the `like` keyword when case-sensitive and`like~` when case-insensitive. The `:` operator is equivalent to `like~`.* For regular expression matching, use `regex` or `regex~`.* `=` cannot be substituted for the `==` operator.* Strings enclosed in single quotes (`'`) are not supported. Enclose strings indouble quotes (`"`) instead.* `?"` and `?'` do not indicate raw strings. Enclose raw strings inthree double quotes (`"""`) instead.* {es} EQL does not support:** Array functions:*** {eql-ref}/functions.html#arrayContains[`arrayContains`]*** {eql-ref}/functions.html#arrayCount[`arrayCount`]*** {eql-ref}/functions.html#arraySearch[`arraySearch`]** The {eql-ref}//functions.html#match[`match`] function** {eql-ref}/joins.html[Joins]** {eql-ref}/basic-syntax.html#event-relationships[Lineage-related keywords]:*** `child of`*** `descendant of`*** `event of`** The following {eql-ref}/pipes.html[pipes]:*** {eql-ref}/pipes.html#count[`count`]*** {eql-ref}/pipes.html#filter[`filter`]*** {eql-ref}/pipes.html#sort[`sort`]*** {eql-ref}/pipes.html#unique[`unique`]*** {eql-ref}/pipes.html#unique-count[`unique_count`][discrete][[eql-how-sequence-queries-handle-matches]]==== How sequence queries handle matches<<eql-sequences,Sequence queries>> don't find all potential matches for asequence. This approach would be too slow and costly for large event data sets.Instead, a sequence query handles pending sequence matches as a{wikipedia}/Finite-state_machine[state machine]:* Each event item in the sequence query is a state in the machine.* Only one pending sequence can be in each state at a time.* If two pending sequences are in the same state at the same time, the mostrecent sequence overwrites the older one.* If the query includes <<eql-by-keyword,`by` fields>>, the query uses aseparate state machine for each unique `by` field value..*Example*[%collapsible]====A data set contains the following `process` events in ascending chronologicalorder:[source,js]----{ "index" : { "_id": "1" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}{ "index" : { "_id": "2" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}{ "index" : { "_id": "3" } }{ "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}{ "index" : { "_id": "4" } }{ "user": { "name": "root" }, "process": { "name": "bash" }, ...}{ "index" : { "_id": "5" } }{ "user": { "name": "root" }, "process": { "name": "bash" }, ...}{ "index" : { "_id": "6" } }{ "user": { "name": "elkbee" }, "process": { "name": "attrib" }, ...}{ "index" : { "_id": "7" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}{ "index" : { "_id": "8" } }{ "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}{ "index" : { "_id": "9" } }{ "user": { "name": "root" }, "process": { "name": "cat" }, ...}{ "index" : { "_id": "10" } }{ "user": { "name": "elkbee" }, "process": { "name": "cat" }, ...}{ "index" : { "_id": "11" } }{ "user": { "name": "root" }, "process": { "name": "cat" }, ...}----// NOTCONSOLEAn EQL sequence query searches the data set:[source,eql]----sequence by user.name  [process where process.name == "attrib"]  [process where process.name == "bash"]  [process where process.name == "cat"]----The query's event items correspond to the following states:* State A:  `[process where process.name == "attrib"]`* State B:  `[process where process.name == "bash"]`* Complete: `[process where process.name == "cat"]`image::images/eql/sequence-state-machine.svg[align="center"]To find matching sequences, the query uses separate state machines for eachunique `user.name` value. Based on the data set, you can expect two statemachines: one for the `root` user and one for `elkbee`.image::images/eql/separate-state-machines.svg[align="center"]Pending sequence matches move through each machine's states as follows:[source,txt]----{ "index" : { "_id": "1" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}// Creates sequence [1] in state A for the "root" user.//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |    [1]    |     |           |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "2" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}// Creates sequence [2] in state A for "root", overwriting sequence [1].//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |    [2]    |     |           |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "3" } }{ "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}// Nothing happens. The "elkbee" user has no pending sequence to move// from state A to state B.//// +-----------------------"elkbee"-----------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |           |     |           |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "4" } }{ "user": { "name": "root" }, "process": { "name": "bash" }, ...}// Sequence [2] moves out of state A for "root".// State B for "root" now contains [2, 4].// State A for "root" is empty.//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+ --> +-----------+     +------------+  |// |  |           |     |   [2, 4]  |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "5" } }{ "user": { "name": "root" }, "process": { "name": "bash" }, ...}// Nothing happens. State A is empty for "root".//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |           |     |   [2, 4]  |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "6" } }{ "user": { "name": "elkbee" }, "process": { "name": "attrib" }, ...}// Creates sequence [6] in state A for "elkbee".//// +-----------------------"elkbee"-----------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |    [6]    |     |           |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "7" } }{ "user": { "name": "root" }, "process": { "name": "attrib" }, ...}// Creates sequence [7] in state A for "root".// Sequence [2, 4] remains in state B for "root".//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |    [7]    |     |   [2, 4]  |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "8" } }{ "user": { "name": "elkbee" }, "process": { "name": "bash" }, ...}// Sequence [6, 8] moves to state B for "elkbee".// State A for "elkbee" is now empty.//// +-----------------------"elkbee"-----------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+ --> +-----------+     +------------+  |// |  |           |     |   [6, 8]  |     |            |  |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "9" } }{ "user": { "name": "root" }, "process": { "name": "cat" }, ...}// Sequence [2, 4, 9] is complete for "root".// State B for "root" is now empty.// Sequence [7] remains in state A.//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+ --> +------------+  |// |  |    [7]    |     |           |     |  [2, 4, 9] |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "10" } }{ "user": { "name": "elkbee" }, "process": { "name": "cat" }, ...}// Sequence [6, 8, 10] is complete for "elkbee".// State A and B for "elkbee" are now empty.//// +-----------------------"elkbee"-----------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+ --> +------------+  |// |  |           |     |           |     | [6, 8, 10] |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+{ "index" : { "_id": "11" } }{ "user": { "name": "root" }, "process": { "name": "cat" }, ...}// Nothing happens.// The machines for "root" and "elkbee" remain the same.//// +------------------------"root"------------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |    [7]    |     |           |     |  [2, 4, 9] |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+//// +-----------------------"elkbee"-----------------------+// |  +-----------+     +-----------+     +------------+  |// |  |  State A  |     |  State B  |     |  Complete  |  |// |  +-----------+     +-----------+     +------------+  |// |  |           |     |           |     | [6, 8, 10] |// |  +-----------+     +-----------+     +------------+  |// +------------------------------------------------------+----====
 |