Skip to content

Instantly share code, notes, and snippets.

@corentinbettiol
Last active January 7, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corentinbettiol/5bfd57673e970b89bbe324e00aadeee7 to your computer and use it in GitHub Desktop.
Save corentinbettiol/5bfd57673e970b89bbe324e00aadeee7 to your computer and use it in GitHub Desktop.

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.


  1. Make sure to have a fully functional django + djangocms + djangocms-blog project (see djangocms-blog installer).

  2. Install aldryn-search

    1. Run pipenv install git+https://github.com/django-haystack/django-haystack#egg=django-haystack

    2. Run pipenv install -e git+https://github.com/aldryn/aldryn-search.git#egg=aldryn-search

    3. Add this to INSTALLED_APPS (in mydumbproject/settings.py) (see doc):

    'haystack',
    'aldryn_common',
    'aldryn_search',
    'standard_form',
    'spurl',
    
    1. 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',
        },
    }
    
  3. Install elasticsearch

    1. Run pipenv install "elasticsearch" (will install version 7.1.0, and you will need to cheat to make it work. why ?)

    2. Remove < (3, 0, 0) (line 17 in haystack/backends/elasticsearch2_backend.py)

    3. Install elasticsearch 7.5.1 (direct link to the .deb file)

    4. Run sudo systemctl start elasticsearch.service && curl http://localhost:9200/

      This should display something like this.

  4. 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).

  5. Create a new, empty page on your website (screenshot)

  6. Go on page, then click on advanced settings (screenshot)

  7. Select aldryn search in Application list (screenshot)

  8. You now should have a basic search input on your page (screenshot)

  9. But you can't process any other search than " " :/

  10. Add , "doc_type" in the for-loop (line 81 in elasticsearch/client/utils.py)

  11. Remove , doc_type='modelresult' in the bulk function (line 190 in haystack/backends/elasticsearch_backend.py)

  12. ...

  13. LOTS OF TWEAKING

  14. ...

  15. another batch of very dirty tweaking and debugging

  16. ...

  17. dev

  18. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment