nano SIEM
Search Commands

eval

Supported in:Self-hosted

Compute new fields, or overwrite existing ones, from expressions: arithmetic, string building, conditions and functions.

Use eval to compute a field from an expression for each result row. You can add a field or replace an existing value.

Syntax

... | eval <field>=<expression>[, <field>=<expression> ...]
ArgumentDescription
fieldName of the new field. If it already exists, it is overwritten. Quote names with spaces: eval "risk label"=....
expressionFields, literals, operators and functions.

Assignments run left to right, so a later assignment can use an earlier one: eval a=1, b=a*2.

Expressions

Operators

Listed from lowest to highest precedence:

OperatorMeaning
OR, ||Logical or
AND, &&Logical and
NOTLogical not
IN (…), NOT IN (…)Membership: http_request.http_method IN ("PUT", "DELETE")
==, =, !=, >, <, >=, <=, CONTAINS, LIKEComparison. Returns 1 or 0.
+, -Add, subtract (numbers only)
*, /, %Multiply, divide, modulo
.String concatenation

Use parentheses whenever you mix operators.

Literals

  • Numbers: 42, 3.5
  • Strings: "text" or 'text'. A quoted string in eval is always a literal, never a field name.
  • Booleans: true, false
  • Intervals: INTERVAL 15 MINUTE, INTERVAL 1 DAY
  • Regex: /pattern/. field=/re/ inside eval is a case-insensitive regex match, as it is in where.

Fields

Reference fields by their exact OCSF 1.9 path, unquoted: http_request.url.hostname, traffic.bytes_out. A field that no event populates evaluates to null. See OCSF field reference.

Functions

eval accepts every scalar function on the Functions page: string, encoding, hashing, IP, URL and domain, threat hunting (entropy, defang, edit distance), time, conversion, conditional, math, regex and array functions.

Examples

Turn bytes into kilobytes:

class_uid=4002 | eval kb=round(http_response.length / 1024, 1) | table time, http_request.url.url_string, kb

Outbound-to-inbound byte ratio per connection, guarded against division by zero:

class_uid=4001 | eval ratio=round(traffic.bytes_out / (traffic.bytes_in + 1), 2) | where ratio > 10 | table src_endpoint.ip, dst_endpoint.ip, traffic.bytes_out, traffic.bytes_in, ratio

Bucket HTTP responses into classes:

class_uid=4002 | eval outcome=case(http_response.code >= 500, "server_error", http_response.code >= 400, "client_error", "ok") | stats count by outcome

Label rows with if:

class_uid=4001 | eval direction=if(is_private_ip(dst_endpoint.ip), "internal", "external") | stats count by direction

Score encoded and high-entropy PowerShell:

class_uid=1007 process.name="powershell.exe" | eval encoded=match(process.cmd_line, "(?i)-e(nc|ncodedcommand)?\s"), score=round(entropy(process.cmd_line), 2) | where encoded=1 OR score > 5 | table time, device.hostname, actor.user.name, score

Pull the Base64 payload out of an encoded command line:

class_uid=1007 process.cmd_line="*-EncodedCommand*" | eval blob=regex_extract(process.cmd_line, "(?i)-EncodedCommand\s+(\S+)") | stats count by blob | sort -count

Defang URLs before you paste them into a ticket:

class_uid=4002 http_response.code=200 | eval safe_url=defang(http_request.url.url_string) | table time, src_endpoint.ip, safe_url

Fall back across class-dependent user fields:

metadata.log_source=windows_event | eval who=coalesce(user.name, actor.user.name, "unknown") | stats count by who

Hour of day and age of each event:

class_uid=3002 | eval hr=hour(time), day=strftime(time, "%Y-%m-%d"), age_s=age(time) | table time, user.name, hr, day, age_s

Percentage of server errors per source, after stats:

class_uid=4002 | stats count(eval(http_response.code >= 500)) as errors, count as total by metadata.log_source | eval error_pct=round(errors * 100 / total, 1)

Notes

  • eval keeps every row; it only adds or replaces a column. Filter with where.
  • substr() and mvindex() use 0-based positions.
  • String comparisons with =, ==, != and CONTAINS are case-insensitive, as in where. match() is case-sensitive unless the pattern starts with (?i).
  • base64_decode() returns null for an invalid or empty decoded value. Narrow the rows first, and test on a few events.

More references

  • stats: aggregate computed fields

What's next

  • where: filter on an expression
  • Functions: every function with aliases and arguments
  • rex: extract fields with a regex
  • fillnull: replace nulls

On this page