Skip to main content

Extended haystack backend for Elasticsearch

Project description

Django Haystack backend for Elasticsearch 5.


Install Django Haystack ES:

pip install django-haystack-es

Add haystack_es.backends.ElasticsearchSearchEngine to your HAYSTACK_CONNECTIONS engine in


    'default': {
        'ENGINE': 'haystack_es.backends.Elasticsearch5SearchEngine',
        # ...

Define your indexes using haystack_es.indexes instead of haystack.indexes.


# myapp/

from haystack_es import indexes
from myapp.models import MyModel

class MyModelIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    # ...

If you have celery-haystack installed you can use haystack_es.indexes.CelerySearchIndex for defining your SearchIndex utilizing celery-haystack

If you want to utilize additional SearchQuerySet methods use haystack_es.query.SearchQuerySet instead of haystack.query.SearchQuerySet.


from haystack_es.query import SearchQuerySet

sqs = SearchQuerySet().filter(content='some query')
sqs.boost_fields({'field_name': 2, 'some_field': 1.5, 'another_field': 1})
# ...

Differences compared to the default django-haystack Elasticsearch backend

  • Intended for Elasticsearch >= 5

  • Allows query-time fields boosting.

  • Allows query-time negative boost

  • Provides additional SearchFields; DictField, NestedField and GeometryField

  • Tries to use Elasticsearch filter context instead of query string for filtering results.

  • Uses multi-fields for creating shadow fields which are useful for performing operations like faceting and exact matches which need non-analyzed values.

Query-time fields boosting

from haystack_es.query import SearchQuerySet

Example SearchQuerySet().boost_fields({'field_name': 2, 'another_field': 1})

Negative boosting

from haystack_es.query import SearchQuerySet
SearchQuerySet().boost_negative(query, negative_boost)

example SearchQuerySet().boost_negative({'match': {'category.raw': 'awful type'}}, negative_boost)

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox


Inspired by

Tools used in rendering this package:


0.1.0 (2017-07-27)

  • First release on PyPI.

0.2.8 (2019-07-18)

  • Simplify Django Version in Tox.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-haystack-es-0.2.8.tar.gz (14.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page