rename_keys

The rename_keys processor renames keys in an event.

Configuration

You can configure the rename_keys processor with the following options.

OptionRequiredDescription
entriesYesA list of event entries to rename.
from_keyYesThe key of the entry to be renamed.
to_keyYesThe new key of the entry.
overwrite_if_to_key_existsNoWhen set to true, the existing value is overwritten if key already exists in the event. The default value is false.

Usage

To get started, create the following pipeline.yaml file:

  1. pipeline:
  2. source:
  3. file:
  4. path: "/full/path/to/logs_json.log"
  5. record_type: "event"
  6. format: "json"
  7. processor:
  8. - rename_keys:
  9. entries:
  10. - from_key: "message"
  11. to_key: "newMessage"
  12. overwrite_if_to_key_exists: true
  13. sink:
  14. - stdout:

copy

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 rename_keys processor, if the logs_json.log file contains the following event record:

  1. {"message": "hello"}

When you run the rename_keys processor, it parses the message into the following “newMessage” output:

  1. {"newMessage": "hello"}

If newMessage already exists, its existing value is overwritten with value.

Special considerations

Renaming operations occur in the order that the key-value pair entries are listed in the pipeline.yaml file. This means that chaining (where key-value pairs are renamed in sequence) is implicit in the rename_keys processor. See the following example pipline.yaml file:

  1. pipeline:
  2. source:
  3. file:
  4. path: "/full/path/to/logs_json.log"
  5. record_type: "event"
  6. format: "json"
  7. processor:
  8. - rename_keys:
  9. entries:
  10. - from_key: "message"
  11. to_key: "message2"
  12. - from_key: "message2"
  13. to_key: "message3"
  14. sink:
  15. - stdout:

Add the following contents to the logs_json.log file:

  1. {"message": "hello"}

copy

After the rename_keys processor runs, the following output appears:

  1. {"message3": "hello"}

rename_keys - 图1