Reader small image

You're reading from  Elasticsearch 5.x Cookbook - Third Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786465580
Edition3rd Edition
Right arrow
Author (1)
Alberto Paro
Alberto Paro
author image
Alberto Paro

Alberto Paro is an engineer, manager, and software developer. He currently works as technology architecture delivery associate director of the Accenture Cloud First data and AI team in Italy. He loves to study emerging solutions and applications, mainly related to cloud and big data processing, NoSQL, Natural language processing (NLP), software development, and machine learning. In 2000, he graduated in computer science engineering from Politecnico di Milano. Then, he worked with many companies, mainly using Scala/Java and Python on knowledge management solutions and advanced data mining products, using state-of-the-art big data software. A lot of his time is spent teaching how to effectively use big data solutions, NoSQL data stores, and related technologies.
Read more about Alberto Paro

Right arrow

Chapter 17. Plugin Development

In this chapter we will cover the following recipes:

  • Creating a plugin

  • Creating an analyzer plugin

  • Creating a REST plugin

  • Creating a cluster action

  • Creating an ingest plugin

Introduction


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.

Creating a plugin


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.

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.

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.

How to do it...

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:

  1. 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...

Creating an analyzer 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.

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.

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.

How to do it...

An analyzer plugin is generally composed of two classes:

  • A Plugin class, which implements the org.elasticsearch.plugins.AnalysisPlugin class...

Creating a REST plugin


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.

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.

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.

How to do it...

To create a REST entry-point, we need to create the action and then register it in the plugin. We will perform the following...

Creating a cluster action


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.

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.

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.

How to do it...

In this recipe we will see that a REST call is converted to an internal cluster action. To execute an internal cluster action, some classes are required:

  • A Request...

Creating an ingest plugin


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.

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.

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.

How to do it...

To create an ingest processor plugin, we need to create the processor and then register it in the plugin class. We will perform the following steps:

  1. We create the processor and its factory:

            ... 
            public final class InitialProcessor extends...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Elasticsearch 5.x Cookbook - Third Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786465580
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alberto Paro

Alberto Paro is an engineer, manager, and software developer. He currently works as technology architecture delivery associate director of the Accenture Cloud First data and AI team in Italy. He loves to study emerging solutions and applications, mainly related to cloud and big data processing, NoSQL, Natural language processing (NLP), software development, and machine learning. In 2000, he graduated in computer science engineering from Politecnico di Milano. Then, he worked with many companies, mainly using Scala/Java and Python on knowledge management solutions and advanced data mining products, using state-of-the-art big data software. A lot of his time is spent teaching how to effectively use big data solutions, NoSQL data stores, and related technologies.
Read more about Alberto Paro