Subtract
Synopsis
Subtracts one numeric value from another.
- subtract:
field: <ident>
left_operand: <string>
right_operand: <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:
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Target field to store the subtraction result |
left_operand | Y | - | Minuend (value to subtract from) - can be a literal value or field reference |
right_operand | Y | - | Subtrahend (value to be subtracted) - can be a literal value or field reference |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if subtraction fails |
ignore_missing | N | false | Replace missing operands with 0 instead of failing |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
tag | N | - | Identifier |
Details
Subtracts the right operand from the left operand and stores the result in the target field. The processor can use literal values or extract values from existing fields in the log entry.
Numeric values are automatically converted to appropriate types for subtraction. The processor accepts both literal values and field references for operands.
The processor is useful for calculating differences, performing adjustments, implementing mathematical operations, and deriving new metrics from existing values.
When ignore_missing
is set to true
, the processor will replace any missing fields with 0 instead of failing. This can lead to unexpected results if you're not careful, as missing fields will be treated as having a value of 0 in the calculation.
Examples
Basic
Subtracting two literal values... |
|
calculates and stores the result: |
|
Field-Based
Calculating difference between field values... |
|
computes time duration: |
|
Delta
Calculating change in metric values... |
|
determines the rate of change: |
|
Mixed Types
Working with different data types... |
|
handles automatic type conversion: |
|
Missing Fields
Processing with missing fields... |
|
treats them as zero: |
|
Chains
Performing sequential calculations... |
|
builds a sequence of results: |
|