Elasticsearch provides native scripting (a Java code compiled in JAR) and Painless, but a lot of interesting languages are available, such as JavaScript and Python.
As previously stated, the official language is now Painless, and this is provided by default in Elasticsearch for better sandboxing and performance.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To install JavaScript language support for Elasticsearch, we will perform the following steps:
bin/elasticsearch-plugin install lang-javascript
-> Downloading lang-javascript from elastic [=================================================] 100%?? @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: plugin requires additional permissions @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * java.lang.RuntimePermission createClassLoader * org.elasticsearch.script.ClassPermission <<STANDARD>> * org.elasticsearch.script.ClassPermission org.mozilla.javascript.ContextFactory * org.elasticsearch.script.ClassPermission org.mozilla.javascript.Callable * org.elasticsearch.script.ClassPermission org.mozilla.javascript.NativeFunction * org.elasticsearch.script.ClassPermission org.mozilla.javascript.Script * org.elasticsearch.script.ClassPermission org.mozilla.javascript.ScriptRuntime * org.elasticsearch.script.ClassPermission org.mozilla.javascript.Undefined * org.elasticsearch.script.ClassPermission org.mozilla.javascript.optimizer.OptRuntime See http://docs.oracle.com/javase/8/docs/technotes/ guides/security/permissions.html for descriptions of what these permissions allow and the associated risks. Continue with installation? [y/N]y -> Installed lang-javascript
bin/elasticsearch-plugin install lang-python
-> Downloading lang-python from elastic [=================================================] 100%?? @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: plugin requires additional permissions @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * java.lang.RuntimePermission createClassLoader * java.lang.RuntimePermission getClassLoader * org.elasticsearch.script.ClassPermission <<STANDARD>> Continue with installation? [y/N]y -> Installed lang-python
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html for descriptions of what these permissions allow and the associated risks.
[...][INFO ][o.e.n.Node ] [] initializing ... [...][INFO ][o.e.e.NodeEnvironment ] [R2Gp0ny] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [82.4gb], net total_space [930.7gb], spins? [unknown], types [hfs] [...][INFO ][o.e.e.NodeEnvironment ] [R2Gp0ny] heap size [1.9gb], compressed ordinary object pointers [true] [...][INFO ][o.e.n.Node ] [R2Gp0ny] node name [R2Gp0ny] derived from node ID; set [node.name] to override [...][INFO ][o.e.n.Node ] [R2Gp0ny] version[5.0.0-beta1], pid[58291], build[7eb6260/2016-09- 20T23:10:37.942Z], OS[Mac OS X/10.12/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101- b13] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [aggs-matrix-stats] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [ingest-common] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [lang-expression] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [lang-groovy] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [lang-mustache] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [lang-painless] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [percolator] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [reindex] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [transport-netty3] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded module [transport-netty4] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded plugin [lang-javascript] [...][INFO ][o.e.p.PluginsService ] [R2Gp0ny] loaded plugin [lang-python] [...][INFO ][o.e.n.Node ] [R2Gp0ny] initialized [...][INFO ][o.e.n.Node ] [R2Gp0ny] starting ...
Language plugins allow an extension of the number of supported languages to be used in scripting. During installation, they require special permissions to access classes and methods that are banned by the Elasticsearch security layer, such as access to ClassLoader or class permissions.
During the Elasticsearch start-up, an internal Elasticsearch service, PluginService, loads all the installed language plugins.
From version 5.x, all the plugins have the same version of Elasticsearch.
The Elasticsearch community provides common scripting languages (a list is available on the Elasticsearch site plugin page at http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-plugins.html), others are available in GitHub repositories (a simple search on GitHub will help you find them).
The most used languages for scripting are as follows:
The PluginManager that we've used to install plugins also provides the following commands:
list
: To list all installed plugins.For example, executing:
bin/elasticsearch-plugin list
The following is the result:
[email protected] [email protected]
remove
: to remove an installed plugin.For example, executing:
bin/elasticsearch-plugin remove lang-javascript
Will result in the following:
-> Removing lang-javascript...
3.149.25.4