Django blog - ElasticSearch + MySQL + Redis π
- Most of us use wordpress π₯± for blogs (so do I: https://pyblog.xyz). The search operation in wordpress takes forever, because it's a simple
column like '%<complete input string>%π€ - To perform faster search operations on tags, categories and other key-words. While it can be achieved with Relational and other NoSQL data stores, Elastic Search is the best when it comes to
SEARCHπ
- Tap the Elastic Homebrew repository:
brew tap elastic/tap brew install elastic/tap/elasticsearch-fullpip install elasticsearch-dsl
cd /usr/local/var/homebrew/linked/elasticsearch-full/bin./elasticsearchTo start ES from GUI, follow: https://opensource.com/article/19/7/installing-elasticsearch-macos
curl -XGET http://localhost:9200Expected Response (Similar):
{ "name": "PP-C02Z66CALVCG.local", "cluster_name": "elasticsearch_adesh.nalpet", "cluster_uuid": "E_543bFmSUqO7dXwzjE1WQ", "version": { "number": "7.8.1", "build_flavor": "default", "build_type": "tar", "build_hash": "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89", "build_date": "2020-07-21T16:40:44.668009Z", "build_snapshot": false, "lucene_version": "8.5.1", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" } brew install redisbrew services start redisorredis-server /usr/local/etc/redis.confpip install django-redis
redis-cli ping
For details on how to set-up a django project with best practices: https://pyblog.xyz/django-initial-setup/
- Update ES and Redis - host and port in
settings.py
ELASTICSEARCH_DSL = { 'default': { 'hosts': 'localhost:9200' }, } CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient" }, "KEY_PREFIX": "pyblog" } } - bulk indexing:
search.bulk_indexing - On every
post_save:signals.pyMore details on Django Signals: https://pyblog.xyz/events-using-django-signals/
Blog Home is a basic blog homepage HTML starter template for Bootstrap created by Start Bootstrap.