Skip to main content
Version: 1.4.0

Abs

Arithmetic Data Analysis

Synopsis

Returns the absolute value of a numeric field.

Schema

- abs:
field: <ident>
value: <string>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Target field to store the absolute value result
valueY-Source value or field reference to calculate absolute value from
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if calculation fails
ignore_missingNfalseSkip processing if referenced field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier

Details

Calculates the absolute value of a numeric value and assigns the result to the specified field. This processor converts negative numbers to their positive equivalents while keeping positive numbers unchanged.

note

The processor will automatically convert string representations of numbers to their numeric values before calculating the absolute value. This makes it flexible when working with different data types.

The processor can evaluate numeric values from a field reference or a numeric literal. It handles various numeric types and ensures that the result is always a positive number.

warning

If the specified value or referenced field cannot be converted to a number, the processor will fail unless ignore_failure is set to true. Always ensure that the input value is numeric or can be parsed as a number.

Examples

Basic

Calculating absolute value from a negative number...

{
"temperature": -15.5
}
- abs:
field: temperature_abs
value: "{{temperature}}"

creates a new field with absolute value:

{
"temperature": -15.5,
"temperature_abs": 15.5
}

In-Place

Replacing field value with its absolute value...

{
"distance": -42
}
- abs:
field: distance
value: "{{distance}}"

overwrites the original value:

{
"distance": 42
}

Using Literals

Calculating absolute value from a literal...

{
"data": {}
}
- abs:
field: absolute_value
value: "-123.45"

sets field to the absolute value:

{
"data": {},
"absolute_value": 123.45
}

Conditionals

Calculating absolute value only when needed...

{
"value": -50,
"needs_abs": true
}
- abs:
field: positive_value
value: "{{value}}"
if: "logEntry.needs_abs == true"

processes conditionally:

{
"value": -50,
"needs_abs": true,
"positive_value": 50
}