Skip to main content

Convert

Mutate Elastic Compatible

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

FieldRequiredDefaultDescription
fieldY-Field containing the value to convert
typeY-Target conversion type (integer, long, float, double, string, boolean, ip, auto)
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if conversion fails
ignore_missingNfalseSkip processing if field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
precisionN3Number of decimal places for floating-point numbers
tagN-Identifier
target_fieldNfieldField 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.

note

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.

warning

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...

{
"stringToInt": "123"
}
convert:
- field: stringToInt
- type: integer

result:

{
"stringToInt": 123
}

Floating Point with Precision

Convert to float with precision...

{
"value": "3.14159"
}
convert:
- field: value
- type: float
- precision: 3

result:

{
"value": 3.142
}

Array Conversion

Converting all elements of an array...

{
"numbers": ["1", "2", "3", "4", "5"]
}
convert:
- field: numbers
- type: integer

result:

{
"numbers": [1, 2, 3, 4, 5]
}

Using Target Field

Converting to a different field...

{
"source": "42"
}
convert:
- field: source
- type: integer
- target_field: target

result:

{
"source": "42",
"target": 42
}

Auto Type Detection

Automatically determining the type...

{
"value1": "42",
"value2": "3.14",
"value3": "true",
"value4": "hello"
}
convert:
- field: value1
- type: auto

results in the appropriate types:

{
"value1": 42,
"value2": 3.14,
"value3": true,
"value4": "hello"
}