Locally Install ElasticSearch to interact with Magento.
Prerequisites:
- Install Apt Transport HTTPS
1sudo apt-get install apt-transport-https
Step 1 – Download and install ElasticSearch
- Save repository definition
1echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
Note: Bear in mind that last version of elasticsearch (7.x) is not compatible with Magento 2.3.*, so you will need to install elasticsearch 6.x. In case you need to remove elasticsearch for a mistake, this is noted at the end of this post, so you will be able then, to proceed again.
- Update indexes
1sudo apt-get update - Install ElasticSearch
1sudo apt-get install elasticsearch
1 |
sudo nano /etc/elasticsearch/elasticsearch.yml |
Remove the # character at the beginning of the lines for cluster.name and node.name to uncomment them, and then update their values.
After this, your first configuration changes in the /etc/elasticsearch/elasticsearch.yml file should look like this:
1 2 3 4 5 |
.... cluster.name: my-application ... node.name: node-1 ... |
Step 3 – Launch ElasticSearch
1 |
sudo /bin/systemctl enable elasticsearch.service |
Eitherway, Elasticsearch can be started and stopped as follows:
1 2 |
sudo systemctl start elasticsearch.service sudo systemctl stop elasticsearch.service |
Step 4 – Test Launch
Request on CLI:
1 |
curl -X GET "http://localhost:9200/?pretty" |
Expected Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
{ "name" : "node-1", "cluster_name" : "my-application", "cluster_uuid" : "YLBEZHdqQ2W_gMiDUJXJyw", "version" : { "number" : "7.3.0", "build_flavor" : "default", "build_type" : "deb", "build_hash" : "de777fa", "build_date" : "2019-07-24T18:30:11.767338Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } |
Go to elasticsearch home directory:
1 |
cd /usr/share/elasticsearch |
Install plugins (this should be done per each node):
1 2 |
bin/elasticsearch-plugin install analysis-phonetic bin/elasticsearch-plugin install analysis-icu |
Restart service:
1 |
sudo service elasticsearch restart |
How to uninstall Elasticsearch:
Uninstall elasticsearch
1 |
sudo apt-get remove elasticsearch |
Uninstall elasticsearch and it’s dependent packages
1 |
sudo apt-get autoremove elasticsearch |
Purging elasticsearch
1 |
sudo apt-get purge elasticsearch |
1 |
sudo apt-get autoremove --purge elasticsearch |
Error logs:
If you need to review or monitor any particular error, those can be found on here:
1 |
sudo service elasticsearch status |
or
1 |
sudo cat /var/log/elasticsearch/<your_elasticsearch_app_name>.log |
Side note:
If you like to install a particular elasticsearch version for a project, you can commit the following steps (In this example, i will install 6.8.12 version):
12345678 sudo service elasticsearch stopcd /var/www/html // Your project path - or wherever you like to store your temporal EScurl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.12.tar.gztar -xvf elasticsearch-6.8.12.tar.gzchown -R user:group elasticsearch-6.8.12 (set your system user and group)cd elasticsearch-6.8.12bin/elasticsearch-plugin install analysis-icubin/elasticsearch-plugin install analysis-phonetic
Then, for every single run:
123 sudo service elasticsearch stopcd /var/www/html/elasticsearch-6.8.12/bin./elasticsearch (do not close this window)