Jar invoke Elasticsearch plugin
To execute custom code in Elasticsearch, you can write an Elasticsearch plugin. However, a plugin introduces an operational complication. To deploy a new version of an Elasticsearch plugin, you need to restart every node in the Elasticsearch cluster where the plugin is installed. This plugin loads Java code at runtime, so you can deploy new code without needing to restart the Elasticsearch nodes.
SECURITY WARNING
This plugin allows scripts to download and execute arbitrary code from the Internet. Installing it will make your information security officer cry.
Install
Install the plugin using the command:
elasticsearch-plugin install com.github.pukkaone:jar-invoke:VERSION
Usage
This plugin adds a script language named jar-invoke
which implements statements to load and invoke Java code.
Require JAR file
Load JAR artifact from a Maven repository if not already loaded.
module = require('
repositoryUri ', '
jarCoordinates ')
Parameter | Description |
---|---|
module |
name to assign to module |
repositoryUri |
Maven repository URI |
jarCoordinates |
Maven artifact coordinates, in format groupId:artifactId:version |
Invoke Java static method
Invoke static method of a Java class in a loaded JAR file.
module .invoke('
className ', '
methodName ')
Parameter | Description |
---|---|
module |
name of loaded module |
className |
Java class name |
methodName |
Java method name |
hello = require('http://repository.example.com/', 'com.example:hello:1.0') hello.invoke('com.example.Hello', 'greet')
The Java method must have accept two Map parameters:
public static Object greet(Map<String, Object> variables, Map<String, ScriptDocValues> docLookup) {
Load JAR file
Load JAR artifact from a Maven repository even if it was already loaded.
module = load('
repositoryUri ', '
jarCoordinates ')
Parameter | Description |
---|---|
module |
name to assign to module |
repositoryUri |
Maven repository URI |
jarCoordinates |
Maven artifact coordinates, in format groupId:artifactId:version |
hello = load('http://repository.example.com/', 'com.example:hello:1.0')