Apache Nifi Record Path Cheat Sheet
Apache Nifi Record path allows dynmic values in functional fields, and manipulation of a record as it is passing through Nifi and heavily used in the UpdateRecord and ConvertRecord processors. This is a short reference to find useful functions and examples. For a full reference see the offical documentation.
Examples will reference the below sample.
{ "A":" A-value", "B": { "B-1": { "B-1-a": "B-1-a Value", "B-1-b": "B-1-b Value" "B-1-c": "B-1-c Value" }, "B-2": "", "B-3": " ", "B-4": "#" }, "C": "C-value" }
Node Access
The basic rules for xpath or jsonp is generally followed.
/ | direct child |
// | descendant |
.. | parent |
. | self |
* | wildcard |
[3, 0..3, 2..-1] | array filter |
['child','child2'] | map filter |
[filterFunction('attr1')] | filter using functions |
Filter Predicates
= (equals)
!= (not equals)
> (greater than)
>= (greater than or equal to)
< (less than)
<= (less than or equal to)
Examples:
/A[. = 'A-value'] | All "A" nodes with "A-value" |
/A[../C != 'C-value'] | All "A" nodes with a sibling "C" that does not equal "C-Value" |
Filter Functions
The general format for using filters is /node-selector[filterFunction()].
/path[contains(path, 'str'|path)] | /A[contains(., '-')] |
/path[matchesRegex(path, 'regex')] | /*[matchesRegex(., '.*value')] A & C |
/path[startsWith(path, 'str')] | /A[startsWith(., 'A')] |
/path[endsWith(path, 'str')] | /A[endsWith(., 'value')] |
/path[not(filter)] | /A[not(contains(., '-'))] |
/path[isEmpty(path)] | //B-2[isEmpty(.)] true //B-3[isEmpty(.)] false |
/path[isBlank(path)] | //B-2[isBlank(.)] true //B-3[isBlank(.)] true |
Type Conversion
Coerces from one format to another
toString(path, format) | toString(/byteValue, "UTF-8") |
toDate(path, format) | toDate(/dateValue, "yyyy-MM-dd") |
toBytes(path, format) | toBytes(/stringValue, "UTF-8") |
String Manipulation
substring(path, start, end) | substring(/A, 0, 1) 'A' |
substringAfter(path, str) | substringAfter(/A, '-') 'value' |
substringAfterLast(path, str) | substringAfterLast(//B-1-a, 'a') 'lue' |
substringBefore(path, str) | substringBefore(/A, '-') 'A' |
substringBeforeLast(path, str) | substringBeforeLast(//B-1-a, 'a') 'B-1-a V' |
replace(path, str, str|path) | replace(/A, '-', //B-4) 'A#value' |
replaceRegex(path, search, replace) | replaceRegex(/A, '(-)', '$1#') 'A-#value' |
replaceRegex(/A, '\s+<named>(.*)', 'xx${named}xx') 'xx-valuexx' | |
concat(path, str|path...) | concat(/A, ' and ', /B) 'A-value and B-value' |
fieldName(path) | //*[fieldName(.) = 'B-4'] '#' |
Format Date
If a node is of type date it can be used directly, if not utilize the toDate function.
format(/path, format) | format(toDate(/dateValue, "yyyy-MM-dd"), "MM-dd") '01-01' |
Encode/Decode Functions
base64Encode(/path) | base64Encode(//stringField) |
base64Decode(/path) | base64Decode(//stringField) |