Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»BIG-DATA»How to Install Elasticsearch on CentOS 7/6

    How to Install Elasticsearch on CentOS 7/6

    RahulBy RahulJanuary 7, 20153 Mins ReadUpdated:October 18, 2019

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

    This tutorial will help you to setup Elasticsearch single node cluster on CentOS, Red Hat, and Fedora systems.

    Step 1 – Prerequsities

    Java is the primary requirement for installing Elasticsearch on any system. You can check the installed version of Java by executing the following command. If it returns an error, install Java on your system using this tutorial.

    java -version
    

    Step 2 – Setup Yum Repository

    First of all, install GPG key for the elasticsearch rpm packages.

    sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
    

    Then create yum repository file for the elasticsearch. Edit /etc/yum.repos.d/elasticsearch.repo file:

    sudo vi /etc/yum.repos.d/elasticsearch.repo
    

    Add below content:

    [Elasticsearch-7]
    name=Elasticsearch repository for 7.x packages
    baseurl=https://artifacts.elastic.co/packages/7.x/yum
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=1
    autorefresh=1
    type=rpm-md
    

    Step 3 – Install Elasticsearch

    After adding yum repository, just install Elasticsearch on CentOS and RHEL system using the following command:

    sudo yum install elasticsearch
    

    After successful installation edit Elasticsearch configuration file “/etc/elasticsearch/elasticsearch.yml” and set the network.host to localhost. You can also change it to the system LAP IP address to make it accessible over the network.

    vim /etc/elasticsearch/elasticsearch.yml
    
      network.host: localhost
    

    Then enable the elasticsearch service and start it.

    sudo systemctl enable elasticsearch
    sudo systemctl start elasticsearch
    

    The ElasticSearch has been successfully installed and running on your CentOS or RHEL system.

    Run the following command to verify service:

    curl -X GET "localhost:9200/?pretty"
    

    You will see the results like below:

    {
      "name" : "tecadmin",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "HY8HoLHnRCeb3QzXnTcmrQ",
      "version" : {
        "number" : "7.4.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
        "build_date" : "2019-09-27T08:36:48.569419Z",
        "build_snapshot" : false,
        "lucene_version" : "8.2.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    

    Step 4 – Elasticsearch Examples (Optional)

    The following examples will help you to add, fetch and search data in the Elasticsearch cluster.

    Create New Bucket

    curl -XPUT http://localhost:9200/mybucket
    

    Output:

    {"acknowledged":true}
    

    Adding Data to Elasticsearch

    Use following commands to add some data in Elasticsearch.
    Command 1:

    curl -XPUT 'http://localhost:9200/mybucket/user/johny' -d '{ "name" : "Rahul Kumar" }'
    

    Output:

    {"_index":"mybucket","_type":"user","_id":"johny","_version":1,"created":true}
    

    Command 2:

    curl -XPUT 'http://localhost:9200/mybucket/post/1' -d '
    {
        "user": "Rahul",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 1 in Elasticsearch" ,
        "title": "Demo Post 1"
    }'
    

    Output:

    {"_index":"mybucket","_type":"post","_id":"1","_version":1,"created":true}
    

    Command 3:

    curl -XPUT 'http://localhost:9200/mybucket/post/2' -d '
    {
        "user": "TecAdmin",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 2 in Elasticsearch" ,
        "title": "Demo Post 2"
    }'
    

    Output:

    {"_index":"mybucket","_type":"post","_id":"2","_version":1,"created":true}
    

    Fetching Data from Elasticsearch

    Use the following command to GET data from ElasticSearch and read the output.

    curl -XGET 'http://localhost:9200/mybucket/user/johny?pretty=true'
    curl -XGET 'http://localhost:9200/mybucket/post/1?pretty=true'
    curl -XGET 'http://localhost:9200/mybucket/post/2?pretty=true'
    

    Searching in Elasticsearch

    Use the following command to search data from elastic search. Below command will search all data associated with user johny.

    curl 'http://localhost:9200/mybucket/post/_search?q=user:TecAdmin&pretty=true'
    

    Output:

    {
      "took" : 145,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 0.30685282,
        "hits" : [ {
          "_index" : "mybucket",
          "_type" : "post",
          "_id" : "2",
          "_score" : 0.30685282,
          "_source":
    {
        "user": "TecAdmin",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 2 in Elasticsearch" ,
        "title": "Demo Post 2"
    }
        } ]
      }
    }
    
    

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

    BIG-DATA cluster data database elasticsearch Elasticsearch Cluster
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Noise Music Player on Ubuntu
    Next Article Working with FOR Loop in Bash Shell with Examples

    Related Posts

    How To Install MySQL Server on Ubuntu 22.04

    Updated:April 6, 20224 Mins Read

    How To Install MariaDB on Debian 11

    4 Mins Read

    How to Install Redis on Debian 11 Linux

    Updated:September 16, 20213 Mins Read

    How to Check the PostgreSQL Version

    Updated:August 6, 20212 Mins Read

    How to Rename MySQL Database

    Updated:July 26, 20213 Mins Read

    How to Backup SQL Server Database

    Updated:June 28, 20212 Mins Read

    7 Comments

    1. sarma on November 9, 2019 2:50 pm

      At step 3, after
      sudo yum install elasticsearch
      I got message, “No Package elasticsearch available.
      Error: Nothing to do

      My Java Version was 1.7.0_67

      How to proceed now?

      Reply
      • Rahul on November 12, 2019 7:29 am

        Hi,

        I have checked and elasticsearch package are available to install in repository. Please check repository once again.

        Reply
    2. AgBOX on March 21, 2016 6:49 am

      For new version elasticsearch version 2x, install plugin should : bin/plugin install

      Reply
    3. Breno on August 13, 2015 8:11 pm

      Great article. Congratulation!

      Reply
    4. Sam on July 28, 2015 6:54 am

      Perfect article… written nicely

      Thanks man…

      Reply
    5. JULIAN on July 7, 2015 4:12 am

      Thanks!
      really, you saved me so much time.

      Reply
    6. patrick on June 6, 2015 3:08 am

      Hi this needs updating to java 1.7
      please follow
      http://www.cyberciti.biz/faq/centos-linux-6-install-java-sdk/
      before installing elastic search
      great article i thought this was going to be really hard.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.