Categories
Elasticsearch Search engine

Install Elasticsearch in Ubuntu 20.04

Elasticsearch is a distributed, open-source search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is fast, distributed by nature. Here you can find steps to install elasticsearch.

Elasticsearch is a distributed, open-source search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is fast, distributed by nature.

Please see my other post, if you want to know Elasticsearch in-depth: What is elasticsearch

hOW YOU CAN USE ELASTICSEARCH?
  • You can add search functionality to your website or app.
  • Since its a no-SQL data store, you can store unstructured data like logs, metrics, and security event data.
  • Monitor application performance.
  • Log analytics.

Import the elasticsearch PGP key:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Installing from the APT repository

You may need to install the apt-transport-https package on Debian before proceeding:

sudo apt-get install apt-transport-https

Save the repository definition to /etc/apt/sources.list.d/elastic-7.x.list:

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

You can install the Elasticsearch Debian package with:

sudo apt-get update && sudo apt-get install elasticsearch

Running Elasticsearch with systemd

Elasticsearch can be started and stopped as follows:

sudo systemctl start elasticsearch.service
sudo systemctl enable elasticsearch.service

To stop elastic service.

sudo systemctl stop elasticsearch.service

If the elasticsearch service is stopped you will get below response,

curl: (7) Failed to connect to localhost port 9200: Connection refused

To configure Elasticsearch to start automatically when the system boots up, run the following commands:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

To check status of Elasticsearch service,

sudo /bin/systemctl status elasticsearch.service

Curl command to check if elasticsearch is running,

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

which shows below result,

{
  "name" : "injustice-Lenovo-Z50-70",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "OXLM0PNQT4GylxbI1uEggg",
  "version" : {
    "number" : "7.9.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",
    "build_date" : "2020-08-11T21:36:48.204330Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

To check logs of elasticsearch,

sudo journalctl --unit elasticsearch

which shows below result,

-- Logs begin at Tue 2020-06-30 13:05:32 IST, end at Thu 2020-09-03 08:07:55 IST. --
Sep 03 08:03:18 injustice-Lenovo-Z50-70 systemd[1]: Starting Elasticsearch...
Sep 03 08:03:39 injustice-Lenovo-Z50-70 systemd[1]: Started Elasticsearch.
Sep 03 08:04:23 injustice-Lenovo-Z50-70 systemd[1]: Stopping Elasticsearch...
Sep 03 08:04:23 injustice-Lenovo-Z50-70 systemd[1]: elasticsearch.service: Succeeded.
Sep 03 08:04:23 injustice-Lenovo-Z50-70 systemd[1]: Stopped Elasticsearch.
Sep 03 08:06:25 injustice-Lenovo-Z50-70 systemd[1]: Starting Elasticsearch...
Sep 03 08:06:43 injustice-Lenovo-Z50-70 systemd[1]: Started Elasticsearch.

Change “cluster.name” to “greylog” in elasticsearch.yml.

sudo nano /etc/elasticsearch/elasticsearch.yml
# Use a descriptive name for your cluster:
#
cluster.name: graylog
#

restart elasticsearch

sudo systemctl restart elasticsearch.service

Referencesâž–

  1. https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html

Please let me know in comment section if you are facing any issues.

Also, share this post with your colleagues and friends 🙂

By Satyanarayan Bhanja

Machine learning engineer

6 replies on “Install Elasticsearch in Ubuntu 20.04”

Leave a Reply

Your email address will not be published. Required fields are marked *

How to do semantic document similarity using BERT Zero-shot classification using Huggingface transformers