Writing a language plugin to run a script

I am migrating a few scripts from Groovy to Painless, and running into the following issue at runtime:
"Scripts may be no longer than 16384 characters.. . Consider using a plugin if a script longer than this length is a requirement."

So I've been trying to figure out how to write a plugin that would run the scripts I have and not having any luck. The only relevant example I've seen is this:

But It doesn't apply entirely. From my failed attempts it sounds like a need to figure out how instantiate a ExecutableScript factory and script, but not sure. It has been hard to find documentation or examples on the web.

The latest error I am getting is this (but could be because the plugin code is not correct):

Caused by: NotSerializableExceptionWrapper[class_cast_exception: Cannot cast com.mobius.ESPlugin$MyExpertScriptEngine$$Lambda$2912/1589848714 to org.elasticsearch.script.SearchScript$Factory]

I am wondering if someone can point me to other examples, specifically on just implementing scripts in a plugin. The scripts I am migrating are used in aggregations, so I have one initScript, one mapScript and one reduceScript.

Also if there is any other workaround for the max number of Painless characters issue, I'd appreciate any thoughts as well. I've already tried shrinking the code as much as I can. It's legacy code.

Thanks in advance.

Never mind. I figured out how to write the plugin. Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.