In this article we will see how to implement fast text search using elastic search instead of using MySQL or PostgreSQL.
Elasticsearch is a search engine based on Lucene. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.
ElasticSearch indexes documents for your data instead of using data tables like a regular relational database does.
There are two client libraries to interact with ElasticSearch with Python.
1. elasticsearch-py
2. elasticsearch-dsl
1 - Make a directory.
mkdir elasticsearch
2 - Download the tar file.
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz
3 - Untar the compressed file.
tar -xzf elasticsearch-6.0.0.tar.gz
4 - Start the elastic search.
./elasticsearch-6.0.0/bin/elasticsearch.
Elastic search will print lots of output on terminal.
To confirm if its working, go to your browser and hit http://localhost:9200/
. You will get the response something like below.
Elastic search is up and running. Lets setup the Kibana.
We will be installing using the .deb file.
1 - Download the kibana v6.0.0 deb file.
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.0.0-amd64.deb
2 - Compare the SHA produced by sha1sum or shasum with the published SHA.
sha1sum kibana-6.0.0-amd64.deb
3 - Install kibana.
sudo dpkg -i kibana-6.0.0-amd64.deb
Use below commands to start or stop kibana.
sudo systemctl start kibana.service sudo systemctl stop kibana.service
Use below commands to start kibana automatically when system boots up
sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable kibana.service
Now open the Kibana in browser. Go to http://localhost:5601
. If your elastic search was running and everything is fine then you will see all green on the kibana status page otherwise you may see some red flags.
So now kibana and elastic search are up, connected and running.
In next part of this article, we will setup a Django project and will link it to elastic search.
References:
- https://www.automationlaboratories.com/linux/installation-elk-stack-linux-server/