You're reading from Elasticsearch 5.x Cookbook - Third Edition
Elasticsearch is designed to be extended with plugins to improve its capabilities. In the previous chapters we installed and used many of them (new queries, REST endpoints, and scripting plugins).
Plugins are application extensions that can add many features to Elasticsearch. They can have several usages, such as:
Adding new scripting language (that is, Python and JavaScript plugins) Adding new aggregation types
Extending Lucene-supported analyzers and tokenizers
Using native scripting to speed up computation of scores, filters and field manipulation
Extending node capabilities, for example creating a node plugin that can execute your logic
Monitoring and administering clusters
In this chapter, the Java language will be used to develop a the native plugin, but it is possible to use any JVM language that generates JAR files.
Native plugins allow several aspects of the Elasticsearch server to be extended, but they require a good knowledge of Java.
In this recipe we will see how to set up a working environment to develop native plugins.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that supports Java programming, such as Eclipse or IntelliJ IDEA, is required.
The code to this recipe is available in the chapter17/simple_plugin
directory.
Generally, Elasticsearch plugins are developed in Java using the Maven build tool and deployed as a ZIP file.
To create a simple JAR plugin, we will perform the following steps:
To correctly build and serve a plugin, some files must be defined:
pom.xml
is used to define the build configuration for Maven.es-plugin.properties
defines the namespace of the plugin class that must be loaded.<name>plugin...
Elasticsearch provides, out-of-the-box, a large set of analyzers and tokenizers to cover general needs. Sometimes we need to extend the capabilities of Elasticsearch by adding new analyzers.
Typically you can create an analyzer plugin when you need:
To add standard Lucene analyzers/tokenizers not provided by Elasticsearch
To integrate third-part analyzers
To add custom analyzers
In this recipe we will add a new custom English analyzer similar to the one provided by Elasticsearch.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that supports Java programming, such as Eclipse or IntelliJ IDEA. The code for this recipe is available in the chapter17/analysis_plugin
directory.
In the previous recipe we read how to build an analyzer plugin that extends the query capabilities of Elasticsearch. In this recipe, we will see how to create one of the most common Elasticsearch plugins.
This kind of plugin allows the standard REST calls to be extended with custom ones to easily improve the capabilities of Elasticsearch.
In this recipe, we will see how to define a REST entry-point and create its action; in the next one, we'll see how to execute this action distributed in shards.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that supports Java programming, such as Eclipse or IntelliJ IDEA. The code for this recipe is available in the chapter17/rest_plugin
directory.
In the previous recipe, we saw how to create a REST entry-point, but to execute the action at cluster level, we will need to create a cluster action.
An Elasticsearch action is generally executed and distributed in the cluster and in this recipe we will see how to implement this kind of action. The cluster action will be very bare; we send a string with a value to every shard and the shards echo a result string concatenating the string with the shard number.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that support Java programming, such as Eclipse or IntelliJ IDEA. The code for this recipe is available in the chapter17/rest_plugin
directory.
Elasticsearch 5.x introduces the ingest node that allows the modification, via a pipeline, to the records before ingesting in Elasticsearch. We have already seen in Chapter 13, Ingest that a pipeline is composed by one or more processor action. In this recipe, we will see how to create a custom processor that store in a field the initial character of another one.
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that support Java programming, such as Eclipse or IntelliJ IDEA. The code for this recipe is available in the chapter17/ingest_plugin
directory.