Installing and Running Elasticsearch


Before installing the Elasticsearch, make sure you complete the following prerequisites:

  • A ubuntu 14.04 and above Droplet.
  • A non-root sudo user.
  • Latest version of Java already installed.

Since Elasticsearch is written in the Java programming language, it requires Java 7 or higher.

Downloading and Installing Elasticsearch

Installing from the RPM repository

Create a file called elasticsearch.repo under the directory /etc/yum.repos.d/ for RedHat based distributions, or under the directory /etc/zypp/repos.d/ for OpenSuSE based distribution, containing the following text in it.

name=Elasticsearch repository for 5.x packages

And your repository is ready for use. You can now install Elasticsearch with one of the following commands:

sudo yum install elasticsearch 
sudo dnf install elasticsearch 
sudo zypper install elasticsearch 
Use yum on CentOS and older Red Hat based distributions.
Use dnf on Fedora and other newer Red Hat distributions.
Use zypper on OpenSUSE based distributions

Download and install the Debian package manually

The Debian package for Elasticsearch v5.4.0 can be downloaded from the website and installed as follows:


Tip : If you want the latest released version of Elasticsearch, go to to find the link, and then use wget to download it to your Droplet. Be sure to download the deb package.

Installing Elasticsearch by either ways results in Elasticsearch being installed in /usr/share/elasticsearch/ with its configuration files placed in /etc/elasticsearch and its init script added in /etc/init.d/elasticsearch.

To make sure Elasticsearch starts and stops automatically with the Droplet, add its init script to the default runlevels with the command:

$ sudo update-rc.d elasticsearch defaults

Configuring Elasticsearch

Now as we have already installed the Elasticsearch, it is time to configure Elasticsearch.

The configuration files of Elasticsearch can be found under the directory /etc/elasticsearch  . There are two files which needs to be configured :

  • elasticsearch.yml — Configures the Elasticsearch server settings. This is where all options, except those for logging, are stored, which is why we are mostly interested in this file.
  • logging.yml — Provides configuration for logging. In the beginning, you don’t have to edit this file. You can leave all default logging options. You can find the resulting logs in /var/log/elasticsearch by default.


To start editing the elasticsearch.yml configuration file :

$ sudo nano /etc/elasticsearch/elasticsearch.yml

Below are some of the main properties whose default values has to be changed before running the Elasticsearch:

  •  : It determines whether a node will store the data or not. Possible values are true/false. By default it would be true.
  •  : It specifies the name of the node (Server).
  •  :  It specifies the cluster to which it is connected.
  •  : It determines the path where the data gets store. The default path is  /var/lib/elasticsearch.
  • index.number_of_shards  :  It determines into how many pieces (shards) the index will split in to.
  • index.number_of_replicas  : It determines the number of replicas which will be stored across the cluster.
  • node.master  : Using this property we can configure the node to act as a master or slave. Possible values are true to act as master and false to act as slave.

Before changing any values in the configuration file remove the # at the beginning of the lines to un-comment them.

Configuration file would look like below before doing any changes to it :

... node-1 my-application /path/to/data
#path.logs: /path/to/logs

After doing the changes it would look as follows :

... "MyNode" myCluster1 : false /opt/es/data
index.number_of_shards : 5
index.number_of_replicas : 1

Once you make all the changes, please save and exit the file. Now you can start Elasticsearch for the first time with the command:

$ sudo service elasticsearch start

Please wait for some seconds so that Elasticsearch start fully before you are able to use it. Otherwise, you may get errors about not being able to connect.

To test if the Elasticsearch server has started we can basically do a simple GET request like this :


We can see the below output :

  "name" : "MyNode",
  "cluster_name" : "myCluster1",
  "cluster_uuid" : "yF43bwdPSrWg8VtG1hwSnw",
  "version" : {
    "number" : "5.3.0",
    "build_hash" : "3adb13b",
    "build_date" : "2017-03-29T03:31:50.652Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  "tagline" : "You Know, for Search"



As we saw that’s how easy it is to install, configure and run the Elasticsearch. Next you can start creating index and play with some manual queries.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s