Runs a Lua script on a document.
For each incoming FlowFile in document format, the processor calls a Lua function. The function is passed a LuaDocument object containing the document reference, metadata, and content. The script can modify the LuaDocument and can also return new LuaDocument instances.
The document that is passed in to the function is routed to the success relationship (but only when it is not explicitly returned by the function), or the returned relationship (if it is explicitly returned). New LuaDocuments that you return are routed to the returned relationship.
Name | Default Value | Description |
---|---|---|
Document Registry Service | A DocumentRegistryService controller service that manages and updates a document registry database. This ensures that documents are indexed in the correct order. | |
Lua script file | The path of the script to run (or the actual Lua script). | |
Lua script function | handler | The name of the function to call. The function is expected to take a single argument which is a LuaDocument type. |
require_module_name | The path or body of a script that can be required by the script by calling require("require_module_name") . Replace require_module_name with the name of the property you create. |
Name | Description |
---|---|
success | FlowFiles that have been processed by your script but not explicitly returned. FlowFiles that are processed can be routed to this relationship even if your script throws an exception. |
returned |
All documents that you return from the Lua function named by the property Lua script function are routed to this relationship. You might return new documents if you want to split one document into several. TIP:
To use a Lua script to filter out irrelevant documents, you could return documents that you want to continue processing, and return |
failure | FlowFiles that had an invalid or unknown format. |
The following is an example Lua script. Your script must contain a function that matches the name defined by the Lua script function property. This function must accept a single argument (a LuaDocument). The default function name is handler
.
Any changes that you make to the LuaDocument are reflected in the FlowFile that is routed to the success relationship (when the document is not explicitly returned) or returned relationship (when it is).
The function does not need to return anything, but you can return new documents. Any new documents that you return are routed to the returned relationship. Unlike Lua scripts for use with CFS, you do not return true or false.
-- require a module defined by the value of the property 'some_property_name' require("some_property_name") function handler(document) -- Perform any modifications to the document here -- Documents not explicitly returned are routed to 'success' document:addField("some_field", "some_field_value") -- Create and return a new document, routed to 'returned' local newDocument = LuaDocument:new("new_document_reference") return newDocument end
|