Two months back, at my Tech Talk session with BRAC IT, I showed a demo of Elasticsearch from an online tutorial, but it was cumbersome to some of you because of installation issues and others. Instead, participants preferred my way of doing all things on Docker. So I am uploading all my demo code here with everything in dockerized containers. I kept the models same as it is and uploaded the exact data generation script.
-
Fork/Clone
-
Install Docker & Docker-Compose
-
Build:
$ docker-compose build
-
Run:
$ docker-compose up -d
-
Open web container's bash:
$ docker-compose exec web bash
-
Apply the migrations:
root@container-id $ python manage.py migrate
-
Populate the database with some test data by running the following command:
root@container-id $ python manage.py populate_db
-
Create and populate the Elasticsearch index and mapping:
root@container-id $ python manage.py search_index --rebuild
-
Test Elasticsearch with the following queries:
- http://127.0.0.1:8000/search/user/mike/ - should find the user 'mike13'
- http://127.0.0.1:8000/search/user/jess_/ - should find the user 'jess_'
- http://127.0.0.1:8000/search/category/seo/ - should find the category 'SEO optimization'
- http://127.0.0.1:8000/search/category/progreming/ - should find the category 'Programming' (:warning: notice the typo)
- http://127.0.0.1:8000/search/article/linux/ - should find the article 'Installing the latest version of Ubuntu'
- http://127.0.0.1:8000/search/article/java/ - should find the article 'Which programming language is the best?'
-
Or if you familiar with swagger you can play with the following URL -