Map mobile application practice — Django haystack elasticsearch environment preparation

Time:2021-10-22

In an article, we introduceDjango elasticsearch ionic building GIS mobile application – Architecture Design。 Then, we started the actual combat, and the content is also very simple.

Django GIS preparation

1. Create a virtual environment

 virtualenv -p /usr/bin/python2.67 django-elasticsearch

2. Create project

For convenience, mezzanine CMS is used here. Compared with Django, the main advantage is that it is easy to expand in the future. But it is also possible for Django.

3. Installation dependency

All my dependencies here are

django-haystack
Mezzanine==3.1.10
djangorestframework
pygeocoder
elasticsearch

install

pip install requirements.txt

4. Install elasticsearch

CentOS

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.zip
sudo unzip elasticsearch-1.4.2 -d /usr/local/elasticsearch
rm elasticsearch-1.4.2.zip
cd /usr/local/elasticsearch/elasticsearch-1.4.2/
./bin/plugin install elasticsearch/elasticsearch-cloud-aws/2.4.1
curl -XGET http://localhost:9200

Mac OS

brew install elasticsearch

5. Django geo environment construction

CentOS and other GNU / Linux systems: you can refer toCentOS Django geo environment construction

MacOS: Mac OS Django geo environment construction

Configure Django

Configure haystack

HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'haystack',
    },
}   

HAYSTACK_SIGNAL_PROCESSORSo that it can be processed in real time.
HAYSTACK_CONNECTIONSIs used to configure the search engine.

Configure Django

staysettings.pyMediumINSTALLED_APPSadd to

"haystack",
"rest_framework",

next

 python manage.py createdb
 python manage.py migreate

function

 python manage.py runserver

other:

Server code:https://github.com/phodal/django-elasticsearch

Client code:https://github.com/phodal/ionic-elasticsearch