How to Install Elasticsearch on CentOS, RHEL

Elasticsearch is flexible and powerful open source, distributed real-time search and analytics engine. Using a simple set of APIs, it provides the ability for full-text search. Elastic search is freely available under the Apache 2 license, which provides most flexibility.

This article will help you to install Elasticsearch on CentOS, RHEL, Ubuntu and Debian Systems.

Step 1. Install JAVA

Before installing elasticsearch make sure you have java installed on your system. If you do not have java installed use following article to install Java.

Install JAVA 7 or JAVA 8 on CentOS/RHEL
Install JAVA 8 on Ubuntu

Step 2. Setup Repositories

First we need to setup repositories in package manager as per our operating system.


Import the Public Signing Key for elasticsearch
# rpm –import

Now create a yum repository file /etc/yum.repos.d/elasticsearch.repo and add following content to this file.

name=Elasticsearch repository for 1.1.x packages

On Ubuntu/Debian:

Import the Public Signing Key first using following command
$ wget -O – | apt-key add –

Now edit /etc/apt/sources.list file and add below entry to enable the repository
deb stable main

Step 3. Install Elasticsearch

After adding required packages repository, lets install the elasticsearch package On CentOS/RHEL:
# yum install elasticsearch

On Ubuntu/Debian:
$ sudo apt-get update$ sudo apt-get install elasticsearch

Step 4. Start Elasticsearch

Make sure you have configured JAVA_HOME environment variable properly. Use following commands to start elasticsearch.
# service elasticsearch start# /sbin/chkconfig –add elasticsearch

Step 5. Elasticsearch is now installed. Let’s edit the configuration:

# vi /etc/elasticsearch/ thenationwdhttp.port: 9200
Optional – Move the Elasticsearch data directory.

Your linux install may be configured in such a way that your install partition is only a few Gb in size, and placing a large Elasticsearch index there is not ideal.

In which case you will want to move the index directory to a different, larger, location (in this example /var/elasticsearch).

# /path/to/data
to /var/elasticsearch (Create Dir. mkdir /var/elasticsearch)

You will also want to restrict outside access to your Elasticsearch instance, so outsiders can’t read your data or shut down your Elasticseach cluster through the HTTP API. Find the line that specifies and uncomment it so it looks like this: localhost

Add the following line somewhere in the file, to disable dynamic scripts:
script.disable_dynamic: true

Then disable multicast by finding the item and uncommenting so it looks like this: false

Save and exit elasticsearch.yml.

Step 6. Open up /elasticsearch/bin/service/elasticsearch.conf on line 2 edit

To a number suitable for the size of your forum.

I recommend approximately 1 GB for the HEAP_SIZE per 1 million posts on your forum.

1 Million Posts: 1024
2 Million Posts: 2048
3 Million Posts: 3072
4 Million Posts: 4096 etc.

This will not mean the service will use all that available memory, however it will have it at its disposal if required. So for example a 3 Million Post forum would edit

Step 7. Verify Setup

You have all done, just need to verify setup. elasticsearch works on port 9200, open your browser to point your server on port 9200, You will find some thing like below output


Examples of Data Indexing
Following examples will help to add, get and search data in Elasticsearch.

1. Adding Data to Elasticsearch
Use following commands to add some data in elasticsearch.

Command 1:
curl -XPUT ‘’ -d ‘{ “name” : “Johny Disuja” }’Output: {“ok”:true,”_index”:”demo”,”_type”:”user”,”_id”:”johny”,”_version”:1}

Command 2:
curl -XPUT ‘’ -d ‘{    “user”: “johny”,    “postDate”: “05-15-2013”,    “body”: “This is Demo Post 1 in ElasticSearch” ,    “title”: “Demo Post 1”}’Output: {“ok”:true,”_index”:”demo”,”_type”:”post”,”_id”:”1″,”_version”:1}

Command 3:
curl -XPUT ‘’ -d ‘{    “user”: “johny”,    “postDate”: “06-06-2013”,    “body”: “This is Demo Post 2 in ElasticSearch” ,    “title”: “Demo Post 2”}’Output: {“ok”:true,”_index”:”demo”,”_type”:”post”,”_id”:”2″,”_version”:1}

2. Get Data from Elasticsearch
Use following command to GET data from Elasticsearch and read the output.

curl -XGET ‘’curl -XGET ‘’curl -XGET ‘’

3. Search in Elasticsearch
Use following command to search data from elastic search. Below command will search all data assiciated with user johny.

curl ‘’

“took” : 27,
“timed_out” : false,
“_shards” : {
“total” : 5,
“successful” : 5,
“failed” : 0
“hits” : {
“total” : 2,
“max_score” : 0.30685282,
“hits” : [ {
“_index” : “demo”,
“_type” : “post”,
“_id” : “1”,
“_score” : 0.30685282, “_source” :
“user”: “johny”,
“postDate”: “05-15-2013”,
“body”: “This is Demo Post 1 in ElasticSearch” ,
“title”: “Demo Post 1”
}, {
“_index” : “demo”,
“_type” : “post”,
“_id” : “2”,
“_score” : 0.30685282, “_source” :
“user”: “johny”,
“postDate”: “06-06-2013”,
“body”: “This is Demo Post 2 in ElasticSearch” ,
“title”: “Demo Post 2”
} ]

Congratulations! You have successfully configured elasticsearch on your Linux system.


Leave a Reply

Please log in using one of these methods to post your comment: 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