Install plugin on Elasticsearch container

Posted by ChenRiang on May 20, 2020

Elasticsearch version : 7.7

In this article, we will be using docker-compose to create a container with plugin pre-installed.

Core Plugin

Plugins that maintained by Elasticsearch team. List of plugin: doc.

  1. Create a docker-compose.yml file :

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
     version: '2'
     services:
       es_v7:
         image: elasticsearch:7.7.0
         environment:
           - node.name=es01
           - cluster.name=es-docker-cluster
           - discovery.type=single-node
         ports:
           - "9200:9200"
         volumes:
           - .:/mnt
         entrypoint: /mnt/docker-entrypoint-es.sh
        
    
    • Set discovery.type=single-node if you intented to run single node mode.
    • Port is exposed to 9200.
    • The location of the script is mount to /mnt directory in the container.

  2. Create a script file docker-entrypoint-es.sh :

    1
    2
    3
    4
    5
    
     #!/bin/bash
        
     bin/elasticsearch-plugin install analysis-phonetic
     exec /usr/local/bin/docker-entrypoint.sh elasticsearch
        
    



  3. Run docker-compose up.

Custom Plugin

Custom plugins that developed by community.

  1. Create docker-compose.yml file
    (Refer Core Plugin - Step 1)

  2. Create a directory (e.g: analysis-plugin) same location as docker-compose.yml.
    E.g. Create plugin directory

  3. Move the plugin jars and properties into the created directory.
    E.g.
    In my case, I’m trying to import analysis-pinyin which has artifacts of 2 jars + 1 properties file.

    Custom Plugin's artifact

  4. Create a script file docker-entrypoint-es.sh :

    1
    2
    3
    4
    5
    
     #!/bin/bash
    
     cp -R /apps/<custom-plugin> /usr/share/elasticsearch/plugins
     exec /usr/local/bin/docker-entrypoint.sh elasticsearch
    
    



  5. Run docker-compose up.

Validate

Validate is the plugin successfully installed by using Elasticsearch cat plugin api.

Postman: Validate using POSTMAN