Tutorials

Install Elasticsearch on CentOS 7

Table of Contents

Introduction

Elasticsearch is an efficient "distributed restful search and analytics" service built on top of Apache Lucene. Individual indices store JSON documents that can be accessed and managed through a REST API and produce fast search results.

It helps to better understand Elasticsearch by comparing the data structure to a typical relational database. The Elasticsearch guide uses the following example.

Relational DB ⇒ Databases ⇒ Tables ⇒ Rows      ⇒ Columns
Elasticsearch ⇒ Indices   ⇒ Types  ⇒ Documents ⇒ Fields

Requirements

  • CentOS 7
  • Java Runtime Environment
  • Elasticsearch 1.3.2

Install Java Runtime Environment

Elasticsearch requires Java to run. While the OpenJDK Runtime Environment might be sufficient, official testing is performed using the Oracle Java Runtime Environment (JRE) and is advised for production usage.

You must accept the Oracle JRE license agreement before downloading the latest available RPM at the following URL.

http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

The RPM package can be installed once successfully downloaded.

sudo rpm -Uvh jre-8u20-linux-x64.rpm

The java executable should now be available.

java -version

Install Elasticsearch

The latest version of Elasticsearch is available as an RPM from the Elasticsearch download page:

http://www.elasticsearch.org/overview/elkdownloads/

The RPM can be installed directly using curl.

sudo rpm -Uvh https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.noarch.rpm

Start Elasticsearch

Enable the Elasticsearch service to start on server boot.

sudo systemctl enable elasticsearch

The service can started with the following.

sudo systemctl start elasticsearch

The following command can be used to confirm the service has successfully started.

curl http://localhost:9200/

Review the /var/log/elasticsearch/elasticsearch.log if there are any errors.

Example Usage

A new index called company with type name employee can be created by simply inserting a new document using an HTTP PUT request.

curl -XPUT http://localhost:9200/company/employees/1 -d '
    { "first_name" : "John", "last_name" : "Doe" }
'

The new document can be retrieved with a GET request.

curl -XGET http://localhost:9200/company/employees/1

The _search endpoint can be used to search for all employees under the company index.

curl -XGET http://localhost:9200/company/employees/_search/?pretty=true

If multiple documents existed in the index, the q query parameter can be used to narrow down the search results.

curl -XGET http://localhost:9200/company/employees/_search/?q=last_name:Doe

This is only a glimpse of what Elasticsearch has to offer. Please refer to the Elasticsearch guide for more details.

 
  • There are the amazing post here to all users if you wanna be getting the best enjoyments so need to get Online mahjongg connect this is the most famous free tiles game to like by the many players.

Log In, Add a Comment