Skip to main content

Copy

The copy function mapping defines a simple conversion of the field. It has a “from” field and a “to” field that define a field name translation, leaving the value unchanged. The mapping types are defined with “function type” and "function" attributes in the mapping. The default string function is "Copy".

Regular Expressions in Mapping

Mappings can incorporate regular expressions in the "from" field to enhance flexibility. These expressions must include a capture group that is subsequently referenced in the "to" field. This feature is particularly useful in handling arrays within messages.

Example of Array Handling

To apply a mapping to each element in an array, the following regular expression is used in the "from" field (note the capture group):

channels/(.*)/name

The captured value is then referenced in the "to" field using the format $n$, where n is the index of the capture group:

event/metrics/$1/description

Contextual Changes When Using Regular Expressions

The use of regular expressions affects the scope of any filters applied in the mapping. Typically, a filter affects the entire message. However, when a regular expression is used, the filter's scope is limited to the segment of the message after the last slash (/) within the "from" field.

For example, consider the following message structure:

mydata/0/interesting = true
mydata/0/name = One flew over the cuckoo's nest
mydata/1/interesting = true
mydata/1/name = The Chosen
mydata/2/interesting = false
mydata/2/name = The art of the deal

If a filter is defined to select only entries where interesting == true, and the mapping is defined as:

mydata/(.*) to /mybooks/$1

The resulting copied fields would be:

mybooks/0/name = One flew over the cuckoo's nest
mybooks/1/interesting = true
mybooks/1/name = The Chosen``