Created 08-29-2017 05:45 PM
I have a sample text file, it contains text "Such as this is a check text", I need to write a NiFi expression in RouteText file processor to check if the sample text file contains string 'check' ingest other wise reject.
What I could find was everything is with filename, not what is inside the file.
${filename:toUpper():contains('check')}
Created on 08-29-2017 07:12 PM - edited 08-17-2019 05:08 PM
The NiFi expression Language is used to evaluate and operate against the attributes of a FlowFile, Variable Registry key/value pair, a NiFi JVM pre-defined property, or a pre-defined system environment variable. What you are trying to operate against is the content of a FlowFile. Processor like RouteText and RouteOnContent as mentioned by @kdoran are the correct processor to use in this scenario. These processors expect you to create custom new properties that use Java Regular expressions instead of the NiFi Expression Language to parse against the content of a FlowFile.
Using your example and a RouteOnContent processor, you might want to add a new property as follows:
.*?([Cc][Hh][Ee][Cc][Kk]).*?
The Java regular expression looks at the content for 0 or more characters, followed by "check" (case incentive), followed by 0 or more characters.
The RouteOnContent will then have 2 relationships: "containsCheck" (user added above) and "unmatched" (default: always exists)
Any FlowFiles with content not containing check (case incentive) will be routed to unmatched. You can choose to auto-terminate this relationship if you just want to throw these unmatched FlowFiles away.
Thanks,
Matt
Created 08-29-2017 06:41 PM
From the RouteText processor documentation:
Each line in an incoming FlowFile is compared against the values specified by user-defined Properties. The mechanism by which the text is compared to these user-defined properties is defined by the 'Matching Strategy'. The data is then routed according to these rules, routing each line of the text individually.
Is this what you want to accomplish, i.e., routing each line of text? If so, then you don't have to use the NiFi Expression language. Use a Java Regex Pattern string and it will be evaluated for each line in your text file.
If instead you wish to route the entire FlowFile if any line matches, there are probably many ways you could do that. One method would be to use RouteOnContent:
Applies Regular Expressions to the content of a FlowFile and routes a copy of the FlowFile to each destination whose Regular Expression matches. Regular Expressions are added as User-Defined Properties where the name of the property is the name of the relationship and the value is a Regular Expression to match against the FlowFile content.
Again, this uses a Java Regex Pattern String.
Does this answer your question?
Created 08-29-2017 07:20 PM
@kdoran Thanks a lot that makes sense it worked
Created on 08-29-2017 07:12 PM - edited 08-17-2019 05:08 PM
The NiFi expression Language is used to evaluate and operate against the attributes of a FlowFile, Variable Registry key/value pair, a NiFi JVM pre-defined property, or a pre-defined system environment variable. What you are trying to operate against is the content of a FlowFile. Processor like RouteText and RouteOnContent as mentioned by @kdoran are the correct processor to use in this scenario. These processors expect you to create custom new properties that use Java Regular expressions instead of the NiFi Expression Language to parse against the content of a FlowFile.
Using your example and a RouteOnContent processor, you might want to add a new property as follows:
.*?([Cc][Hh][Ee][Cc][Kk]).*?
The Java regular expression looks at the content for 0 or more characters, followed by "check" (case incentive), followed by 0 or more characters.
The RouteOnContent will then have 2 relationships: "containsCheck" (user added above) and "unmatched" (default: always exists)
Any FlowFiles with content not containing check (case incentive) will be routed to unmatched. You can choose to auto-terminate this relationship if you just want to throw these unmatched FlowFiles away.
Thanks,
Matt