convert_entry_type
The convert_entry_type
processor converts a value type associated with the specified key in a event to the specified type. It is a casting processor that changes the types of some fields in events. Some data must be converted to a different type, such as an integer to a double, or a string to an integer, so that it will pass the events through condition-based processors or perform conditional routing.
Configuration
You can configure the convert_entry_type
processor with the following options.
Option | Required | Description |
---|---|---|
key | Yes | Key whose value needs to be converted to a different type. |
keys | Yes | Keys whose value needs to be converted to a different type. |
type | No | Target type for the key-value pair. Possible values are integer , long , double , big_decimal , string , and boolean . Default value is integer . |
null_values | No | String representation of what constitutes a null value. If the field value equals one of these strings, then the value is considered null and is converted to null . |
scale | No | Modifies the scale of the big_decimal when converting to a big_decimal . The default value is 0 . |
tags_on_failure | No | A list of tags to be added to the event metadata when the event fails to convert. |
convert_when | No | Specifies a condition using a Data Prepper expression for performing the convert_entry_type operation. If specified, the convert_entry_type operation runs only when the expression evaluates to true . |
Usage
To get started, create the following pipeline.yaml
file:
type-conv-pipeline:
source:
...
....
processor:
- convert_entry_type:
key: "response_status"
type: "integer"
Next, create a log file named logs_json.log
and replace the path
in the file source of your pipeline.yaml
file with that filepath. For more information, see Configuring Data Prepper.
For example, before you run the convert_entry_type
processor, if the logs_json.log
file contains the following event record:
{"message": "value", "response_status":"200"}
The convert_entry_type
processor converts the output received to the following output, where the type of response_status
value changes from a string to an integer:
{"message":"value","response_status":200}