Elasticsearch search backend requires an Elasticsearch server. For the installation guide, see the official documentation.
You can configure an integration with the set of environment variables.
When deploying on Heroku - you can use an add-on which provides Elasticsearch as a service. By default, Saleor uses Elasticsearch 6.3.
When deploying somewhere else, you can use one of the following services:
URL to the Elasticsearch engine. If it is empty, search is not available.
Saleor uses Django Elasticsearch DSL as a wrapper for Elasticsearch DSL to enable automatic indexing and sync. Indexes are defined in the documents file. Refer to documentation of above projects for help and tips.
The initial search index can be created with the following command:
python manage.py search_index --rebuild
By default, all indexed objects (products, users, orders) are re-indexed every time they are changed.
Search integration architecture
Search backends use Elasticsearch DSL for query definition in saleor/search/backends.
There are two backends defined for Elasticsearch integration:
- storefront - Storefront search uses only the storefront index for a product-only search.
- dashboard - The dashboard backend performs additional searches in user and order indexes.
There are two levels of testing for search functionality. Syntax of Elasticsearch queries is ensured by unit tests for the backend; integration testing is done using VCR.py to mock external communication.
If you modify the search logic, make sure to record new communication and align test fixtures accordingly.
Pytest will run VCR in never-recording mode on CI to make sure no attempts of communication are made, so make sure most recent cassettes are always included in your repository.