Elasticsearch plugins

At various places in this book, we have used different plugins that have been able to extend the core functionality of Elasticsearch. You probably remember the additional programming languages used in scripts described in the Scripting capabilities of Elasticsearch section of Chapter 6, Make Your Search Better. In this section, we will look at how the plugins work and how to install them.

The basics

By default, Elasticsearch plugins are located in their own subdirectory in the plugins subdirectory of the search engine home directory. If you have downloaded a new plugin manually, you can just create a new directory with the plugin name and unpack that plugin archive to this directory. There is also a more convenient way to install plugins: by using the plugin script. We have used it several times in this book without talking about it, so this time let's take the time and describe this tool.

Elasticsearch has two main types of plugins. These two types can be categorized based on the content of the plugin-descriptor.properties file: Java plugins and site plugins. Let's start with the site plugins. They usually contain sets of HTML, CSS, and JavaScript files and add additional UI components to Elasticsearch. Elasticsearch treats the site plugins as a file set that should be served by the built-in HTTP server under the /_plugin/plugin_name/ URL (for example, /_plugin/bigdesk/). This type of plugin doesn't change anything in core Elasticsearch functionality.

The Java plugins are the ones that add or modify the core Elasticsearch features. They usually contain the JAR files. The plugin-descriptor.properties file contains information about the main class that should be used by Elasticsearch as an entry point to configure plugins and allow them to extend the Elasticsearch functionality. The nice thing about the Java plugins is that they can contain the site part as well. The site part of the plugin needs to be placed in the _site directory if we are unpacking the plugin manually.

Installing plugins

Plugins can be downloaded from three source types. The first is the official repository located at https://download.elastic.co. All plugins from this source can be installed by referring to the plugin name. For example:

bin/plugin install lang-javascript

The preceding command results in installation of a plugin that allows us to use an additional scripting language, JavaScript. Elasticsearch automatically tries to find a plugin version that is the same as the version of Elasticsearch we are using. Sometimes, like in the following example, a plugin may ask for additional permissions during installation.

Just so we know what to expect, this is an example result of running the preceding command:

-> Installing lang-javascript...
Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/lang-javascript/2.2.0/lang-javascript-2.2.0.zip ...
Downloading ...........................................................................DONE
Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/lang-javascript/2.2.0/lang-javascript-2.2.0.zip checksums if available ...
Downloading .DONE
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     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 into /Users/someplace/elasticsearch-2.2.0/plugins/lang-javascript
Installed lang-javascript into /Users/negativ/Developer/Elastic/elasticsearch-2.2.0/plugins/lang-javascript

If the plugin is not available at the first location, it can be placed in one of the Apache Maven repositories: Maven Central (https://search.maven.org/) or Maven Sonatype (https://oss.sonatype.org/). In this case, the plugin name for installation should be equal to groupId/artifactId/version, just as every library for Maven (http://maven.apache.org/). For example:

bin/plugin install org.elasticsearch/elasticsearch-mapper-attachments/3.0.1

The third source are the GitHub (https://github.com/) repositories. The plugin tool assumes that the given plugin address contains the organization name followed by the plugin name and, optionally, the version number. Let's look at the following command example:

bin/plugin install mobz/elasticsearch-head

If you write your own plugin and you have no access to the earlier-mentioned sites, there is no problem. The plugin tool accepts the url property from where the plugin should be downloaded (instead of specifying the name of the plugin). This option allows us to set any location for the plugins, including the local file system (using the file:// prefix) or remote file (using the http:// prefix). For example, the following command will result in the installation of a plugin archived on the local file system in the /tmp/elasticsearch-lang-javascript-3.0.0.RC1.zip directory:

bin/plugin install file:///tmp/elasticsearch-lang-javascript-3.0.0.RC1.zip

Removing plugins

Removing a plugin is as simple as removing its directory. You can also do this by using the plugin tool. For example, to remove the previously installed JavaScript plugin, we run a command as follows:

bin/plugin remove lang-javascript

The output from the command just confirms that the plugin was removed:

-> Removing lang-javascript...
Removed lang-javascript

Note

You need to restart the Elasticsearch node for the plugin installation or removal to take effect.

..................Content has been hidden....................

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