A Lighter Elasticsearch Instance
Elasticsearch when downloaded can consume by default nearly half of the RAM on your local machine. 🥶🥶
If you prefer to run a local instance of elasticsearch (without Docker), here are the steps to lower its memory consumption
This tutorial was tested on a WSL Ubuntu 20.04.
Check if You have OpenJDK 11 Installed
First, make sure you have OpenJDK 11, which usually comes pre-installed with Ubuntu. To check, run in terminal:
java -version
if you don't have it installed you can follow this simple tutorial for debian-based distros:
Ok, so after confirming we have OpenJDK installed
Download and install Elasticsearch
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt update
sudo apt install elasticsearch
Configuration of Elasticsearch
To access the elasticsearch yml file:
sudo nano /etc/elasticsearch/elasticsearch.yml
Uncomment 'network.host' and change it to 'localhost' for local machine:
network.host: localhost
Check if Elasticsearch starts:
Recommended by LinkedIn
sudo systemctl start elasticsearch
or use 'service' if you don't have 'systemctl' which is common on WSL distros.
sudo service elasticsearch start
Great, if it starts without a problem we can now shut it down to configure memory requirements
sudo systemctl stop elasticsearch
or
sudo service elasticsearch stop
Let's create a new file called 'memory.options' in the 'jvm.options.d' directory so we can define memory requirements
BTW, I chose to name the file 'memory' but you can choose whatever name you want as long as the file extension is `.options` :
sudo nano /etc/elasticsearch/jvm.options.d/memory.options
In the file, add the minimum and maximum memory requirements (I decided on 1G 🙅♂️):
-Xms1g
-Xmx1g
Great, we are done! Now restart Elasticsearch and your RAM should be much lower!
Resources For Further Hacking
✊FYI, check out the NLP Cypher Newsletter for more helpful libraries and latest research in NLP!