prev
Adds the values of specified fields from the previous record in the input data stream to the current record as fields with the prev_ prefix.
Command properties
| Item | Description |
|---|---|
| Command type | Processing query |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Supported |
| Distributed execution | Not supported |
Syntax
Target
FIELD, ...- Names of the fields whose values from the previous record you want to reference. Separate multiple fields with commas (
,). An output field with theprev_prefix is created for each field.
Output fields
| Field | Type | Description |
|---|---|---|
| prev_FIELD | Original type | The value of that field in the immediately preceding record. Null in the first record. |
Error codes
Parse errors
N/A
Runtime errors
N/A
Description
The prev command processes input records in order and, for each specified field, adds the value from the immediately preceding record as a new field with the prev_ prefix. For example, specifying prev count adds a prev_count field to the current record containing the count value from the preceding record. For the first record, there is no preceding record, so the prev_ field value is null.
Values are deep-copied, so mutable types such as Map, List, and Date can be safely referenced.
Examples
-
Referencing the previous value of a single field
json "[{'seq': 1, 'value': 10}, {'seq': 2, 'value': 20}, {'seq': 3, 'value': 30}]" | prev valueA
prev_valuefield is added to each record. Theprev_valueof the first record is null, the second is 10, and the third is 20. -
Calculating the difference from the previous value
json "[{'seq': 1, 'value': 100}, {'seq': 2, 'value': 250}, {'seq': 3, 'value': 400}]" | prev value | eval diff = if(isnull(prev_value), 0, value - prev_value)Uses
prevto get the previousvalue, then usesevalto calculate the difference between the current and previous values. -
Referencing the previous values of multiple fields
json "[{'ts': '2025-01-01', 'src': '192.0.2.1', 'bytes': 1024}, {'ts': '2025-01-02', 'src': '192.0.2.2', 'bytes': 2048}]" | prev src, bytesAdds
prev_srcandprev_bytesfields to each record.