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.
- YAML
- JSON
- XML
handler:
class: ReplaceTransformer
operations:
- fieldMatcher:
pattern: fruit
valueMatcher:
replaceAll: true
pattern: apple
toValue: orange
{
"handler": {
"class": "ReplaceTransformer",
"operations": [
{
"fieldMatcher": {
"pattern": "fruit"
},
"valueMatcher": {
"replaceAll": true,
"pattern": "apple"
},
"toValue": "orange"
}
]
}
}
<handler>
<class>ReplaceTransformer</class>
<operations>
<op>
<fieldMatcher>
<pattern>fruit</pattern>
</fieldMatcher>
<valueMatcher>
<replaceAll>true</replaceAll>
<pattern>apple</pattern>
</valueMatcher>
<toValue>orange</toValue>
</op>
</operations>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
class: ReplaceTransformer
label: string
maxReadSize: 0
operations:
- discardUnchanged: false
fieldMatcher: {}
onSet: APPEND
toField: string
toValue: string
valueMatcher: {}
sourceCharset: string
{
"class": "ReplaceTransformer",
"label": "string",
"maxReadSize": 0,
"operations": [
{
"discardUnchanged": false,
"fieldMatcher": {},
"onSet": "APPEND",
"toField": "string",
"toValue": "string",
"valueMatcher": {}
}
],
"sourceCharset": "string"
}
<handler>
<class>ReplaceTransformer</class>
<label>string</label>
<maxReadSize>0</maxReadSize>
<operations>
<op>
<discardUnchanged>false</discardUnchanged>
<fieldMatcher/>
<onSet>APPEND</onSet>
<toField>string</toField>
<toValue>string</toValue>
<valueMatcher/>
</op>
</operations>
<sourceCharset>string</sourceCharset>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
label | string | No | - |
maxReadSize | integer | No | 10000000 |
operations | ReplaceOperation[] | No | - |
sourceCharset | string | No | - |
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.