Installing additional script plugins

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.

Note

Other scripting languages can be installed as plugins, thus they are now deprecated. We will present them in this recipe as they have a large user base.

Getting ready

You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.

How to do it...

To install JavaScript language support for Elasticsearch, we will perform the following steps:

  1. From the command line, simply call the following command:
            bin/elasticsearch-plugin install lang-javascript
    
  2. It will print the following output:
                -> 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
    

    Note

    If the installation is successful, the output will end with Installed; otherwise, an error is returned.

  3. To install Python language support for Elasticsearch, just call the following command:
            bin/elasticsearch-plugin install lang-python
    
  4. It will print the following output:
             -> 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
    

    Note

    See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html for descriptions of what these permissions allow and the associated risks.

  5. Restart your Elasticsearch server to check that the scripting plugins are loaded:
            [...][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 ...
    

How it works...

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.

Tip

Installing or upgrading a plugin requires a node restart.

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:

  • Groovy (http://www.groovy-lang.org/): This language, embedded in Elasticsearch by default, is a simple language providing scripting functionalities. It's of the fastest available language extensions (except for Painless). Groovy is a dynamic object-oriented programming language with features similar to those of Python, Ruby, Perl, and Smalltalk. It also supports the writing of functional code.
  • JavaScript: This is available as an external plugin. The JavaScript implementation is based on Java Rhino (https://developer.mozilla.org/en-US/docs/Rhino) and it's very fast.
  • Python: This is available as an external plugin, based on Jython (http://jython.org). It allows Python to be used as a script engine. From several benchmarks, it's slower than other scripting languages.

Tip

The performance of every language is different; the fastest one is the native Java. In the case of dynamic scripting languages, Painless and Groovy are faster, as compared to JavaScript and Python.

There's more...

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... 
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.25.4