ConstantTransformer
Define and add constant values to documents.
Notes
To add multiple constant values under the same constant name, repeat the constant entry with a different value.
onSet property determines how constant values are applied to fields that may already exist in a document. It can be configured globally (at the root of the handler) or individually for each constant
Storing values in an existing field
If a document already has a target field with the same name,
new values are appended to the existing list by default. Use onSet to manage this default behavior.
Parser Handler Compatibility
This functionality can be applied as either a pre-parse or post-parse handler.
Examples
The following example adds a constant to incoming documents to identify they were web and mobile documents plus a constant number
- YAML
- JSON
- XML
handler:
class: ConstantTransformer
constants:
- name: source
values:
- web
- mobile
- name: limit
values:
- "3"
{
"handler": {
"class": "ConstantTransformer",
"constants": [
{
"name": "source",
"values": [
"web",
"mobile"
]
},
{
"name": "limit",
"values": [
"3"
]
}
]
}
}
<handler>
<class>ConstantTransformer</class>
<constants>
<constant>
<name>source</name>
<values>
<value>web</value>
<value>mobile</value>
</values>
</constant>
<constant>
<name>limit</name>
<values>
<value>3</value>
</values>
</constant>
</constants>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
class: ConstantTransformer
constants:
- name: string
onSet: APPEND
values: []
label: string
onSet: APPEND
{
"class": "ConstantTransformer",
"constants": [
{
"name": "string",
"onSet": "APPEND",
"values": []
}
],
"label": "string",
"onSet": "APPEND"
}
<handler>
<class>ConstantTransformer</class>
<constants>
<constant>
<name>string</name>
<onSet>APPEND</onSet>
<values>
<value/>
</values>
</constant>
</constants>
<label>string</label>
<onSet>APPEND</onSet>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
constants | Constant[] | No | - |
label | string | No | - |
onSet | enum | No | - |
Property Details
constants
Manage the constants list
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.
onSet
What to do if a target field of the same name already exist.
Allowed Values
APPENDPREPENDREPLACEOPTIONAL