Haystack provides an interface similar to Django's QuerySet
, which instead enables easy querying in one or more popular search backends. Because the Haystack SearchQuerySet
API is meant to hook up to several search backends, however, not all the functionality of the backends has been implemented in the API. In this article we show how Haystack's Elasticsearch backend can be extended with advanced querying functionality.
As an exemplary use case, we'll focus on implementing Elasticsearch's Nested Query in the SearchQuerySet
API, to enable e.g. weighted tags on documents. The usage of this extended API will be shown first, after which we'll go through the necessary implementation steps.
import search.custom_elasticsearch as ces
from files import FileObject