Support Questions
Find answers, ask questions, and share your expertise

Routing on the basis of text/attribute of flowfile

Solved Go to solution

Routing on the basis of text/attribute of flowfile

Explorer

Hi,

I have many flow file which has multiple field like mentioned below

customefields_12345 : null

customefields_12346: { "welcome to this issue"}

 

I have to route these flow files on the condition :

if customfield is null --> navigate to other processor

if customfield is notnull or having some value other than null should be navigate to other processor.

Please let me know how to achieve this. early response will be appreciated.

 

Note: customfield should be used rather than customfield_12345.

 

thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Routing on the basis of text/attribute of flowfile

Master Guru

@midee 

 

I am not clearly following your use case.

FlowFiles consist of two parts, FlowFile attributes/metadata and FlowFile content.

You give example with "customefields_12345" and "customefields_12346".
Does this mean one FlowFile may have multiple "customefields_<some string>" attributes assigned to it?

How do you want to route FlowFiles where only some of those customfield attributes are null while others are not?
There are multiple ways to handle this using NiFi Expression Language (NEL) [1] and the routeOnAttribute [2] processor.

 

 

${anyMatchingAttribute("customfield.*"):isEmpty()}

 

 

Above would return "true" if ANY of the NiFi FlowFile attributes starting with "customefield" is empty.
note: The isEmpty function returns true if the Subject is null, does not contain any characters or contains only white-space (new line, carriage return, space, tab), false otherwise.

There is another NEL subjectless function that would return "true" only if ALL FlowFileAttributes matching the Java regular expression were empty:

 

${allMatchingAttributes("customfield.*"):isEmpty()}

 

 

With the RouteOnAttribute processor you create/add dynamic properties and each of those becomes a new routable relationship on the processor. if the NEL statement configured for that dynamic property returns true that FlowFile routes to that relationship.  Any FlowFile that does not return true for dynamic properties will get routed to the pre-existing relationship named "unmatched".

 

[1] https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

[2] https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apach...

 

If you found this addressed your query, please take a moment to login and click "Accept" on this solution.
Thank you,

Matt

 

View solution in original post

1 REPLY 1

Re: Routing on the basis of text/attribute of flowfile

Master Guru

@midee 

 

I am not clearly following your use case.

FlowFiles consist of two parts, FlowFile attributes/metadata and FlowFile content.

You give example with "customefields_12345" and "customefields_12346".
Does this mean one FlowFile may have multiple "customefields_<some string>" attributes assigned to it?

How do you want to route FlowFiles where only some of those customfield attributes are null while others are not?
There are multiple ways to handle this using NiFi Expression Language (NEL) [1] and the routeOnAttribute [2] processor.

 

 

${anyMatchingAttribute("customfield.*"):isEmpty()}

 

 

Above would return "true" if ANY of the NiFi FlowFile attributes starting with "customefield" is empty.
note: The isEmpty function returns true if the Subject is null, does not contain any characters or contains only white-space (new line, carriage return, space, tab), false otherwise.

There is another NEL subjectless function that would return "true" only if ALL FlowFileAttributes matching the Java regular expression were empty:

 

${allMatchingAttributes("customfield.*"):isEmpty()}

 

 

With the RouteOnAttribute processor you create/add dynamic properties and each of those becomes a new routable relationship on the processor. if the NEL statement configured for that dynamic property returns true that FlowFile routes to that relationship.  Any FlowFile that does not return true for dynamic properties will get routed to the pre-existing relationship named "unmatched".

 

[1] https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

[2] https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apach...

 

If you found this addressed your query, please take a moment to login and click "Accept" on this solution.
Thank you,

Matt

 

View solution in original post