Convert
Synopsis
Converts field values from one data type to another. Supports single values and arrays, with the ability to specify precision for floating-point numbers.
Schema
convert:
- field: <ident>
- type: <enum>
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- ignore_missing: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- precision: <numeric>
- tag: <string>
- target_field: <ident>
Configuration
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Field containing the value to convert |
type | Y | - | Target conversion type (integer, long, float, double, string, boolean, ip, auto) |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if conversion fails |
ignore_missing | N | false | Skip processing if field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
precision | N | 3 | Number of decimal places for floating-point numbers |
tag | N | - | Identifier |
target_field | N | field | Field to store the converted value. If not specified, overwrites the source field |
Details
Supported conversion types:
integer | Converts to a whole number |
long | Converts to a 64-bit integer |
float | Converts to a single precision floating-point number |
double | Converts to a double-precision floating-point |
string | Converts to text representation |
boolean | Converts to true/false value |
ip | Validates and standardizes IP address format |
auto | Automatically determines the most appropriate type |
When converting arrays, all elements in the array will be converted to the specified type. For floating-point conversions, the precision parameter controls decimal places.
With the auto type specified, the processor attempts conversion in the order: integer, float, boolean. If none of these matches, it falls back to string.
IP conversion will fail if the value is not a valid IPv4 or IPv6 address. Set ignore_failure: true to skip invalid IPs.
Examples
Basic Type Conversion
Convert string to integer... | |
result: | |
Floating Point with Precision
Convert to float with precision... | |
result: | |
Array Conversion
Converting all elements of an array... | |
result: | |
Using Target Field
Converting to a different field... | |
result: | |
Auto Type Detection
Automatically determining the type... | |
results in the appropriate types: | |