Integration of Elastic Search and Django(A Python Framework) – Part One

Share On Facebook
Share On Google Plus
Share On Linkedin
Contact us

In this tutorial I am going to show you the Integration of Elastic Search and Django. I am using Django 1.10, ElasticSearch 5.2.0, and Ubuntu 16.04 OS for the application. Lets Have a look on the model we are going to build.

     A simple application that have five simple models : – Product Model, Category Model, SubCategory Model, UserProfile, and the User Model. This is the part One of the tutorial, in this part I am going to build an application at Django Part.

To install Django on your system refer here.

  • Open terminal and type command

    make a new django project

  • make virtual environment

    make virtual environment using python3 django

  • activate the virtual environment

    activate the virtual environment

  • install django 1.10 in the virtual environment using pip

    install django by pip

  • make a app named core that will contain our models

    make an app in django

  • Here is the directory structure for our application

    directory structure of the django project

    go to the elasticdjango/ file and add the core application to the Installed apps:-

    add app to the installed apps in django

  • add following code to the core/ file

Don’t worry if you are not able to understand this time the whole code. This in simple words contain the models definitions of our product, category,subcategory , userprofile models. The user model comes inbuilt with the Django and be imported from django.auth.core.models.

Run makemigration and migrate command to make the database ready for our application pretty simple. This thing likes to be the best of the Django that you just write the models, just what you want to build and leave the database part to be just handled by the django. Run the commands as follows:-
Make sure you are in the directory, contains the file.

make migrations django

If you face some wierd import patterns related error. just go the elasticdjango/ and update the code as:-

Next, run

migrate django

     Django comes with the admin part inbuilt. So that the models data at the backend can be easily be managed by the admin. Is’nt it awesome. To make it, just we have to register our models in the Go to core/ file and update the code as:-

We also need a superuser that will have the access of the django admin interface. Lets make the superuser by running the command

and follow the instructions.

create superuser django

run the django server by

Go to localhost:8000/admin and type in the admin username and password, the one you entered while making the superuser. If you face the template not exist error :-

template does not exist error

then add following template settings to the file and restart the django server.

Upto this level we have the basic django application set up and our database ready. We have four models Products, Category, Subcategory, UserProfile and User(Inbuilt model of the django). In next tutorial we will write our command to fill the database with the dummy data

 Thanks for reading this tutorial. For the full code go to my github repo. For more tutorials Keep visiting this site and also check my Git repositories from

One thought on “Integration of Elastic Search and Django(A Python Framework) – Part One

Leave a Reply

Your email address will not be published. Required fields are marked *