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 settings.py
Example
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack_es.backends.Elasticsearch5SearchEngine',
# ...
}
}
Define your indexes using haystack_es.indexes
instead of haystack.indexes
.
Example
# myapp/search_indexes.py
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
.
Example
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})
sqs.facet('some_field')
# ...
- Intended for Elasticsearch >= 5
- Allows query-time fields boosting.
- Allows query-time negative boost
- Provides additional SearchFields;
DictField
,NestedField
andGeometryField
- 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.
from haystack_es.query import SearchQuerySet SearchQuerySet().boost_fields(boost_fields)
Example SearchQuerySet().boost_fields({'field_name': 2, 'another_field': 1})
from haystack_es.query import SearchQuerySet SearchQuerySet().boost_negative(query, negative_boost)
example
SearchQuerySet().boost_negative({'match': {'category.raw': 'awful type'}}, negative_boost)
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Inspired by
- haystack-elasticsearch5: https://github.com/Alkalit/haystack-elasticsearch5
Tools used in rendering this package: