The Divio Cloud offers you search (Elastic search version 2.3) as a service, which allows you to integrate advanced search features directly into your project without having to manage complex search clusters.

We recommend using Haystack with Elastic search; it's a Django application that provides a clean and usable interface to Elastic search.

How to enable Elastic search

In your project's Subscription, add as many Elastic search instances as you think you will need. One you have applied the new subscription, we will provision it on your Cloud project.

This will include applying a DEFAULT_HAYSTACK_URL  environment variable, that takes the form:

DEFAULT_HAYSTACK_URL=es+http://hostname:9200/my-index-name

There is also native support for AWS ElasticSearch style connections:

DEFAULT_HAYSTACK_URL=es+https+aws://AWS_ACCESS_KEY:AWS_SECRET_KEY@cluster-name.us-east-1.amazonaws.com/my-index-name

Other options are also available, so if you have special requirements please contact our support.

Scheduled indexing

Set up a cron job, for example:

python manage.py rebuild_index --noinput

Debugging

Set the ALDRYN_HAYSTACK_DEBUG environment variable to True  to get detailed logs from Haystack.

Local environment set-up

For local development add an ElasticSearch service to docker-compose.yml:

es:
    image: elasticsearch:2.3

and add a link to it from the web service:

web:
    links:
      - "es:es"

Then add the environment variable to configure the connection (on the default aldryn setup: add to .env-local):

DEFAULT_HAYSTACK_URL=es+http://es:9200/local-*

Test the connection:

docker-compose run --rm web python manage.py shell
>>> from haystack.query import SearchQuerySet
>>> list(SearchQuerySet())
[]

There won't be any results yet, since nothing has so far been indexed. However you will get an error if the connection does not work.

For further information

To learn more about how to setup your project, please see the Aldryn Haystack GitHub Repository.

Did this answer your question?