Elasticsearch is a powerful, open-source search and analytics engine widely popular for its ability to support scalable applications. Whether you're building real-time search functionalities, monitoring logs, or analyzing big data, Elasticsearch offers speed and flexibility. In this guide, we’ll walk you through the steps to install Elasticsearch 8 on Ubuntu.

1. Download Elasticsearch GPG key:

First, we need to download Elasticsearch GPG key and convert it into a binary format, saving it to /usr/share/keyrings/elastic.gpg for secure package verification.

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg

Then, we need to add the Elasticsearch APT repository to our system:

echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-8.x.list

2. Update packages:

sudo apt update

3. Install Elasticsearch:

Now, we can install Elasticsearch, which we added to our repository earlier.

sudo apt install elasticsearch

Elasticsearch has generated a password for authenticating your requests and managing your configuration. Both the installation path and the generated password should be visible in the output.

You should see an output similar to this:

Please note this information, as you will need it in the next steps.

4. Update configuration:

We need to set a hostname and a port number for Elasticsearch to function properly. Since we want to restrict access from outside our web server, we will set localhost as the hostname.

Open the elasticsearch.yml file in a text editor and update it as shown below.

sudo vi /etc/elasticsearch/elasticsearch.yml
. . .
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: localhost
. . .
http.port: 9200
. . .

5. Start the Elasticsearch service:

systemctl start elasticsearch

Depending on your system configuration, it may take a few minutes for it to start.

You can always verify if Elasticsearch is running by using the following command:

systemctl status elasticsearch

6. Reset your password:

Whenever you need to reset your Elasticsearch user password, you can use the elasticsearch-reset-password tool.

/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

When you run the command above, your password will be reset, and the new password will be displayed in the output.

7. Testing Elasticsearch:

You can test your Elasticsearch configuration by sending a request to port 9200:

curl -u elastic:{your_password} -X GET 'https://localhost:9200?pretty' -k

You should receive a response similar to this:

{
  "name" : "elasticsearch",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ICccfD3pR9KLhakGp2CXvg",
  "version" : {
    "number" : "8.17.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "2b6a7fed44faa321997703718f07ee0420804b41",
    "build_date" : "2024-12-11T12:08:05.663969764Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

You can add a sample entry like this:

curl -u elastic:{your_password} -XPOST -H "Content-Type: application/json" 'https://localhost:9200/mytest/_doc/1?pretty' -d '{ "message": "Hello World!!!" }' -k

You can retrieve the entry with an HTTP GET request:

curl -u elastic:{your_password} -X GET -H "Content-Type: application/json" 'https://localhost:9200/mytest/_doc/1?pretty' -k

You should receive a response similar to this:

{
  "_index": "mytest",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "message": "Hello World!!!"
  }
}

Conclusion

Elasticsearch provides a powerful platform for analyzing and searching large volumes of data. In this guide, we covered the installation and basic configuration of Elasticsearch on an Ubuntu server.

Once installed, you can begin indexing your data and leveraging Elasticsearch’s capabilities for search and analytics. For further customization and advanced features, consider exploring the official Elasticsearch documentation.

AUTHOR
PUBLISHED 14 February 2025