calc
Use calc functions to create a new field and populate values for the new field with content returned by the function.
Syntax
|calc <new_field> = <function>
Usage and Examples
Note: AQL boolean arguments are case-insensitive, that is, all the following boolean arguments are valid:
Positive case: True, true, t
Negative case: False, false, f
| Type | Supported functions and syntax | Description |
|---|---|---|
| Comparison and Conditional functions |
Example:
|
Takes alternating conditions and values. Returns the first value for which the condition is true. |
|
Example:
|
Takes one or more values. Returns the first non-null value. |
|
|
Example:
|
If the |
|
|
Examples: Example 1:
Example 2:
|
Returns TRUE if the specified CIDR address includes the value of the specified IP address field; otherwise, returns FALSE. Use the asterisk (*) symbol as an equivalent for '0.0.0.0/0' for matching any IP address. |
|
|
Example:
|
Evaluate whether the specified field matches the specified pattern. The pattern can specify an exact match or a wildcard match:
|
|
|
Example:
|
Evaluate whether any substring of a specified field matches the specified regex. |
|
|
Example:
|
Use this function to set the value of fields with no value to The When used with |
|
|
Example:
|
Use this function to embed a search within the primary search, using square brackets ( See Subsearch documentation for more information. |
|
| Text functions |
Example:
In the following example, assume the value for
|
Concatenates the specified fields or strings into a new field. You must specify at least two arguments, and there is no upper limit. Order is important. The first argument is the start of the new field and subsequent arguments are appended in order. The |
|
Example:
returns a field name |
Concatenates the specified fields or strings into a new field. Enclose string values in single or double quotes. You must specify at least two arguments, and there is no upper limit. The |
|
|
Example:
|
Returns the number of characters in the specified field value. The |
|
|
Example:
|
Converts values for the specified field to lowercase. |
|
|
Example:
|
Removes characters from the left side of the specified field value. The The |
|
|
Example:
|
Substitutes |
|
|
Example:
|
Replaces all occurrences of the <regex> string, using regular expression matches, with the replacement string. In this example, all occurrences of ^qa- matches are replaced with localTest-. |
|
|
Example:
|
Removes characters from the right side of the specified field value. The The |
|
|
Example:
|
Returns a substring of the specified field value, beginning at the position specified by the |
|
|
Example:
|
Removes characters from both sides of the specified field value. The The |
|
|
Example:
|
Converts values for the specified field to uppercase. |
|
|
Example:
|
Applies URL-decoding to convert specified URL fields or URL values to human-readable string values. For field values that are unencoded, the function returns the field name. |
|
| Conversion functions |
Example:
|
Converts values for the specified string field to number values. The |
|
Example:
|
Converts values for the specified number or date field to a string value. |
|
| Date and Time functions |
Example:
|
Converts a Unix timestamp into a human-readable date and time format. A Unix timestamp is a numeric representation of the number of milliseconds since January 1, 1970, 00:00:00 UTC. |
|
Example:
|
Converts a date and time value into a Unix timestamp. A Unix timestamp is a numeric representation of the number of milliseconds since January 1, 1970, 00:00:00 UTC. |
|
|
Note:
|
Converts a Unix timestamp (in milliseconds) to a human-readable time in the specified format. See Date Time Format Code for more information. |
|
|
Examples:
|
Converts a string that is a human-readable time to a Unix timestamp (in milliseconds). The string is parsed according to the format pattern you specify. See Date Time Format Code for more information. | |
|
Example:
|
Adjusts a Unix A Unix timestamp is a numeric representation of the number of milliseconds since January 1, 1970, 00:00:00 UTC. |
|
|
Example:
|
Formats a date expression according to a specified format. See Date Time Format Code for more information.
This function allows you to customize the format to be consistent with your organization's conventions. For example, you can use this function to change the order of day, month, and year components, including time, specifying the separator character, and more. |
|
|
Example:
|
Returns the time that the search was started (in Unix time). A Unix timestamp is a numeric representation of the number of milliseconds since January 1, 1970, 00:00:00 UTC. |
|
|
Example:
|
Takes a bigint field as an argument and returns an epoch timestamp. | |
|
Example:
|
Takes a timestamp field as an argument and returns the epoch time. |
|
| Array functions |
Example:
|
Returns true if <value> is present in the specified multivalue field or array. |
|
Example:
|
Splits a field into an array. | |
|
Example:
|
Splits all occurrences of the regular expression matches in the field. In this example, all occurrences of the |
|
|
Example:
|
Returns the length of an array. | |
array_concat(array1, array2)
Example:
|
Concatenates two arrays into one array, two strings into one string, or an array and a string (that appends the string to the array.) | |
array_distinct(array)
Example:
|
Removes duplicate values. | |
array_join(array, delimiter)
Example:
|
Concatenates the individual values of the array using delimiter. | |
array_slice(array, start, length)
Example:
|
Returns a subset from <field array> starting from index <start> with <length>. | |
|
JSON Extraction functions |
Note: You must place
|
Creates a new field and populates values for the new field with content extracted from an existing field having JSON values. In the example:
|
|
|
Extract nested keys using dot notation to specify the path to the desired key. |
|
ocsf | calc api_name=json_extract(actor.process.cmd_line, 'api_name')
Note: For OCSF schema fields, array indexes start at |
Using the OCSF schema, extract JSON fields from process command lines. See OCSF Schema Overview for more information. | |
|
Examples:
|
If the JSON contains keys with special characters, the operator automatically skips the following characters:
If there are other special characters, avoid them by using double quotes ( |
|
|
Examples:
|
If the key does not exist in the JSON, |
|
|
Examples:
|
By default, the value extracted from the JSON is a string, even if the JSON value is an array. To retrieve results in a specific datatype, specify the datatype in the For example:
|
|
|
Examples:
|
To extract nested keys from a specific element of an array, use the To extract all nested keys in the array of elements, the index can be omitted. This will extract the key for each element in the array. By default, this will return an array of IP addresses but as a string. In the example, the |
|
|
Examples:
|
This allows complex scenarios where keys of nested arrays need to be extracted. In the examples, the group IDs for all the groups for all the interfaces in the instance are extracted. |
|
|
Example of a JSON field with a nested JSON:
Full AQL:
|
If the JSON field contains a nested JSON in string format, you must first extract the string key to be able to extract any key from the nested JSON. For example: if the
|
|
|
Note: Here are some important aspects of JSON filters to note:
Example of a JSON field with a nested JSON:
Full AQL Example 1:
Here,
Result:
Full AQL Example 2:
Here,
Result:
|
You can use a JSON filter if:
Here is the syntax for the JSON filter:
Syntax:
|
|
| Hash functions |
Example:
|
Convert string fields or string values into a hash using the MD5 cryptographic hashing algorithm. |
|
Example:
|
Convert string fields or string values into a hash using the SHA1 cryptographic hashing algorithm. |
|
|
Example:
|
Convert string fields or string values into a hash using the SHA256 cryptographic hashing algorithm. |
|
|
Example:
|
Convert string fields or string values into a hash using the SHA512 cryptographic hashing algorithm. |
|
| Informational functions |
Example:
|
Use these functions to determine whether values for a specified field are NULL or not NULL. |
|
Example:
|
Use this function to determine whether the values for a specified field are numbers. | |
|
Example:
|
Use this function to determine whether value for a specified field is an outlier. Optional:
|
|
| Mathematical functions |
Example:
|
Takes a number and returns its absolute value. |
|
Example:
|
Converts numeric fields or numeric values to an upper bound numerical value that is the lowest integer above the given value. In other words, 2.1 is converted to 3. |
|
|
Example:
|
Converts numeric fields or numeric values to a lower bound numerical value that is the greatest integer below the given value. In other words, 2.1 is converted to 2. |
|
|
Example:
|
Raises numeric fields or numeric values to the given power based on the second parameter of the function. In other words, power(2, 2) will produce 4, or power(2, 3) will produce 8. | |
|
Example:
|
Converts numeric fields or numeric values to a number having the decimal places specified by the given precision. If precision is not specified, it will round to the nearest integer. |
|
|
Example:
|
Returns the square root of numeric fields or numeric values. | |
|
Example:
|
Returns the product of a numeric field or number multiplied by a numeric field or number. | |
|
Example:
|
Returns the product of a numeric field or number divided by a numeric field or number. | |
|
Example:
|
Returns the sum of a numeric field or number added to a numeric field or number. | |
|
Example:
|
Returns the difference of a numeric field or number subtracted from a numeric field or number. | |
| Trigonometric functions |
Example:
|
Calculates the distance between sequential login events for a user, based on distances between latitude-longitude pairs within queries. Helps you determine impossible travel, that is, you can automatically identify geographically improbable logins compared to plausible travel speeds, indicating compromised logins. Supports string-based geolocation fields and integration with other AQL operators such as Supported units of distance measurement: |
| Multivalue functions |
Examples:
|
Remove duplicate values in multivalue fields.
|
|
Examples:
|
Returns a single multivalue result from a specified list of values. Specify any combination of string or number fields or values, including multivalue fields. Put multivalue arrays in brackets You can also use nested |
|
|
Examples:
|
Returns a count of the number of elements in a list for the specified multivalue field. | |
|
Examples:
|
Returns the index for the first value in a multivalue field that matches a regular expression. The index begins with zero. If no values match, returns NULL.
|
|
|
Examples:
|
|
|
|
Examples:
|
Concatenates values within the multivalue field.
|
|
|
Example:
|
Sort the multivalue field lexicographically:
|
|
|
Example:
|
Creates a new multivalue field with concatenated values from two multivalue fields.
The values in the first field are zipped with the values from the second field. If the number of values ββin the two fields does not match, the resulting multivalue has the length of the smaller list of values. |
|
| Information Theory functions |
Caution: Do not use
Examples:
Note: Each input row is capped at 50,000 characters per Note: If the input column contains an empty or NULL value for a row, |
Calculates an entropy score for a string field. The score measures the randomness or unpredictability of the characters in the field value. Parameters
Entropy Score
Strings with many different characters appearing in roughly equal proportions produce a high score. Strings that repeat the same characters frequently produce a low score. The score is a decimal value from zero to eight:
Use cases
|
| UUID function |
Example:
|
Generates a new column with UUIDs. |