As of 03/01/20, here's how I install & configure a search box on a djangocms (& djangocms-blog) project using elasticsearch:
TL;DR: It didn't work. Switch to solr.
-
Make sure to have a fully functional django + djangocms + djangocms-blog project (see djangocms-blog installer).
-
Install aldryn-search
-
Run
pipenv install git+https://github.com/django-haystack/django-haystack#egg=django-haystack
-
Run
pipenv install -e git+https://github.com/aldryn/aldryn-search.git#egg=aldryn-search
-
Add this to INSTALLED_APPS (in
mydumbproject/settings.py
) (see doc):
'haystack', 'aldryn_common', 'aldryn_search', 'standard_form', 'spurl',
- Add this in
mydumbproject/settings.py
:
HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine', 'URL': 'http://127.0.0.1:9200/', 'INDEX_NAME': 'haystack', }, }
-
-
Install elasticsearch
-
Run
pipenv install "elasticsearch"
(will install version 7.1.0, and you will need to cheat to make it work. why ?) -
Remove
< (3, 0, 0)
(line 17 inhaystack/backends/elasticsearch2_backend.py
) -
Install elasticsearch 7.5.1 (direct link to the .deb file)
-
Run
sudo systemctl start elasticsearch.service && curl http://localhost:9200/
This should display something like this.
-
-
Run
python manage.py rebuild_index
This will require having at least one entry in the
ALLOWED_HOSTS
parameter (set it to"*"
if you want). -
Create a new, empty page on your website (screenshot)
-
Go on page, then click on advanced settings (screenshot)
-
Select aldryn search in Application list (screenshot)
-
You now should have a basic search input on your page (screenshot)
-
But you can't process any other search than "
-
Add
, "doc_type"
in the for-loop (line 81 inelasticsearch/client/utils.py
) -
Remove
, doc_type='modelresult'
in thebulk
function (line 190 inhaystack/backends/elasticsearch_backend.py
) -
...
-
LOTS OF TWEAKING
-
...
-
another batch of very dirty tweaking and debugging
-
...
-
I'm stuck with the same two results for every request (I don't have all the other pages). Pretty infuriating at this point. I think I'm switching to solr.