Skip to main content

ReplaceTransformer

Replaces an existing metadata value with another one.

Notesโ€‹

It is possible to only keep values that changed from a replacement and discard others by setting discardUnchanged to true.

The toField argument is optional.

Not specifying a toValue will delete the matches from sources values.

Storing values in an existing fieldโ€‹

If a target field with the same name already exists for a document, values will be added to the end of the existing value list. It is possible to change this default behavior by supplying a PropertySetter.

Can be used both as a pre-parse or post-parse handler.

You can specify whether matches should be made against the whole field value or not (default). You can also specify whether replacement should be attempted on first match only (default) or all occurrences. This last option is only applicable when whole value matching is false.

Examplesโ€‹

The following example replaces occurrences of "apple" to "orange" in the "fruit" field.

handler:
class: ReplaceTransformer
operations:
- fieldMatcher:
pattern: fruit
valueMatcher:
replaceAll: true
pattern: apple
toValue: orange

Usageโ€‹

Full configuration skeleton, with every option and its default
class: ReplaceTransformer
label: string
maxReadSize: 0
operations:
- discardUnchanged: false
fieldMatcher: {}
onSet: APPEND
toField: string
toValue: string
valueMatcher: {}
sourceCharset: string

Propertiesโ€‹

PropertyTypeRequiredDefault
labelstringNo-
maxReadSizeintegerNo10000000
operationsReplaceOperation[]No-
sourceCharsetstringNo-

Property Detailsโ€‹

labelโ€‹

An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing โ€” it exists purely to help identify this step, for example in large configurations or in the visual configurator.

maxReadSizeโ€‹

Max characters to read at once

operationsโ€‹

One or more replacements to perform, each pairing a fieldMatcher (which fields), a valueMatcher (what to replace) and a toValue (what to put there). They can also write to a different toField and drop values left unchanged. See ReplaceOperation.

sourceCharsetโ€‹

Sets the character encoding of the source document to ensure proper reading and processing.