Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Index products for storefront search

Jakub Draganek91fadbd5b716
diff --git a/saleor/search/documents.py b/saleor/search/documents.py
new file mode 100644
index 0000000000..ee2e199083
--- /dev/null
+++ b/saleor/search/documents.py
@@ -0,0 +1,18 @@
+from django_elasticsearch_dsl import DocType, Index
+from ..product.models import Product
+
+storefront = Index('storefront')
+storefront.settings(number_of_shards=1, number_of_replicas=0)
+
+
+class ProductDocument(DocType):
+ class Meta:
+ model = Product # The model associated with this DocType
+
+ # The fields of the model you want to be indexed in Elasticsearch
+ fields = [
+ 'name',
+ 'description',
+ 'is_published'
+ ]
diff --git a/saleor/settings.py b/saleor/settings.py
index 3b8897689d..84f5afc40c 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -357,7 +357,7 @@ if ELASTICSEARCH_URL:
INSTALLED_APPS.append('django_elasticsearch_dsl')
ELASTICSEARCH_DSL = {
'default': {
- 'hosts': 'localhost:9200'
+ 'hosts': ELASTICSEARCH_URL
},
}
SEARCH_BACKENDS = {