This repository is for the backend of ESRA using Django connect with Elasticsearch.
[backend]
├── settings.py : setting port, host, database, and etc from django
└── ...
[esra_backend]
├── documents.py : elasticsearch analyser and registry document
├── helps.py : elasticsearch query services
├── models.py : data model
├── serializer.py : data serializers
├── urls.py : api url lists
├── views.py : api logics
└── ...
[synonyms]
├── synonyms.py : create synonym.txt using embedding vector list of all entities
└── synonyms.txt : file for put in elasticsearch for synonyms feature
.env : enviroments same as in .env.example
new_seed.py : dumping items to database
requirements.txt : list of all libraries
DockerFile : for running with gunicorn
start.sh : for running with gunicorn
esra.sqlite3 : our database file (download: https://bit.ly/35eEFLt)
...
- Create directory
mkdir elasticsearch-library
- Download elasticsearch based-on your system to that directory [ https://www.elastic.co/downloads/elasticsearch ]
- Extract file
tar -xzf elasticsearch-{version}.tar.gz
- Get in to directory
cd elasticsearch-library
- To start elasticsearch server run this command:
./elasticsearch-{version}/bin/elasticsearch
To use the synonym, please follow the instruction below in Run the project with elascticsearch section.
In order to run the project, you need to create .env file (you can look the example at .env.example).
In order to create super user of Django, run this command:
python manage.py createsuperuser
Then put your username, email, and password respectively. You can access the admin at localhost:8000/admin
after run the project.
After you clone the project, please follow the two steps before run the application:
- Copy
./synonyms/synonyms.txt
(project directory) into./elasticsearch-{version}/config/analysis
(elasticsearch directory). - Download a database file (https://bit.ly/35eEFLt) and add it to the project directory as shown in the repository struture.
Run the following commands:
python manage.py makemigrations
python manage.py migrate
python manage.py search_index --rebuild
python manage.py runserver
python manage.py shell
We use gunicorn for serving our backend application. First install gunicorn(this is not fixed, pick anything that suit your liking) then run the following command:
gunicorn --bind 0.0.0.0:8000 --workers 8 backend.wsgi
This command will create 8 workers and binded them at port 8000
The docker image of this project is publicly available at backgroundboy/esra-backend dockerhub repository. The image requires an environment variable ELASTICSEARCH_HOST for the name of external elasticsearch host in order to connenect and run.