Install and Configure Elasticsearch

Elasticsearch is a great tool for indexing huge amount of data and creating a search or analytics engine. It has a potential of solving large number of use cases. Its based on Apache Lucene and provides a RESTful interface which makes it easy to integrate with any technology.

This article describes the very basic Elasticsearch installation and configuration on a Unix environment. This tutorial has been written for Elasticsearch 5.4.1 on Ubuntu 16.04.1 LTS (64 Bit)

The configuration mentioned in this article should not be used in production environment. You can use this to test-drive Elasticsearch or on development environments

Step 1: Check Pre-requisites

The prerequisite for installing Elasticsearch is that you need JRE & JDK installed. You can use the following commands to install the same. Note you will need to use sudo permissions for this step

Update and upgrade apt-get

$ sudo apt-get update
$ sudo apt-get upgrade

If asked to modify the configuration file while upgrading then make sure that you select “keep the local version currently installed” so that it does not break any other packages

Use the following command to install default JRE

$ sudo apt-get install default-jre

Use the following command to install default JDK

$ sudo apt-get install default-jdk

Once apt-get installs default JDK and JRE, you can use the following command to check if the installation is successful.

$ java -version
$ javac -version

Both the above commands should throw output with the respective Java versions. If these command fails that means the packages are not installed properly and you may have to debug deeper.

Step 2: Get the Package

The first step is to get the package. You can download the latest Elasticsearch package from here. There are various flavors of package available but we will get the .zip package. You can download the package in any location

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.zip

Step 3: Unzip the package

Extract the package which was downloaded from Step 1

$ unzip elasticsearch-5.4.1.zip

Once the package is extracted a new folder will be created — elasticsearch-5.4.1 which will have a structure like below

elasticsearch-folder-struc-codincafe

Step 4:

The main executable is in the /bin directory. Go to the directory and use the following command to start Elasticsearch

$ ./elasticsearch -d

Now the ‘-d’ switch will daemonize elasticsearch. By default the daemon starts on port 9200. Since this is a RESTful application you can do a simple curl on your localhost port 9200 to check if the daemon has started

$ curl http://localhost:9200/

You should now see the curl output something like below

{
  "name" : "UEW0U2t",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "s5dGlxmPTCq4sYCd-2KpLw",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}

Your Elasticsearch is now ready to rumble!

To check the PID of the daemon you can use netstat as follows

$ netstat -nlpt | grep 9200

To cleanly shutdown the daemon us the following

$ kill -15 $(lsof -i:9200 -t)

That’s it! Your are now ready to go.

Drop in your comments in case you have any queries, feedback or any other ways that .

Level: Intermediate

Technologies: Linux / Unix, Elasticsearch

post via Codincafe