Elasticsearch¶
Installation¶
Elasticsearch search backend requires an Elasticsearch server. For the installation guide, please refer to the official documentation <https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html>.
Integration can be configured with set of environment variables. When you’re deploying on Heroku - you can use add-on that provides Elasticsearch as a service. By default Saleor uses Elasticsearch 6.3.
If you’re deploying somewhere else, you can use one of following services:
Environment variables¶
ELASTICSEARCH_URLorBONSAI_URLorSEARCHBOX_URLURL to elasticsearch engine. If it’s empty - search will be not available.
Example:
https://user:password@my-3rdparty-es.com:9200
Data indexing¶
Saleor uses Django Elasticsearch DSL as a wrapper for Elasticsearch DSL to enable automatic indexing and sync. Indexes are defined in documents file. Please refer to documentation of above projects for further help.
Initial search index can be created with following command:
$ python manage.py search_index --rebuild
By default all indexed objects (products, users, orders) are reindexed 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 and dashboard. Storefront search uses only storefront index for product only search, dashboard backend does additional searches in users and orders indexes as well.
Testing¶
There are two levels of testing for search functionality. Syntax of Elasticsearch queries is ensured by unit tests for backend, integration testing is done using VCR.py to mock external communication. If search logic is modified, 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.