Skip to content

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

Match only product content type

Jakub Draganek29b5d1fbdee8
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.py
index 5bf0177b24..1d6c69d089 100644
--- a/saleor/search/backends/newelastic.py
+++ b/saleor/search/backends/newelastic.py
@@ -12,6 +12,7 @@ def search_products(phrase):
INDEX = 'storefront__product_product' # TODO: parametrize this
query = MultiMatch(fields=['name', 'description'], query=phrase)
search = Search(index=INDEX).query(query).source(['pk']).using(CLIENT)
+ search = search.filter('match', content_type='product.Product')
return [hit.pk for hit in search.execute()]
diff --git a/saleor/search/backends/test_newelastic.py b/saleor/search/backends/test_newelastic.py
index 428ecbc11c..80dc19d590 100644
--- a/saleor/search/backends/test_newelastic.py
+++ b/saleor/search/backends/test_newelastic.py
@@ -13,9 +13,18 @@ def search_phrase():
def es_search_query(search_phrase):
query = {
'query': {
- 'multi_match': {
- 'query': 'How fortunate man with none',
- 'fields': ['name', 'description']
+ 'bool': {
+ 'must': [{
+ 'multi_match': {
+ 'query': 'How fortunate man with none',
+ 'fields': ['name', 'description']
+ }
+ }],
+ 'filter': [{
+ 'match': {
+ 'content_type': 'product.Product'
+ }
+ }]
}
},
'_source': ['pk']
diff --git a/tests/cassettes/test_new_search_with_empty_results.yaml b/tests/cassettes/test_new_search_with_empty_results.yaml
index 964edabb80..a0bd86b05e 100644
--- a/tests/cassettes/test_new_search_with_empty_results.yaml
+++ b/tests/cassettes/test_new_search_with_empty_results.yaml
@@ -1,6 +1,7 @@
interactions:
- request:
- body: '{"query": {"multi_match": {"query": "foo", "fields": ["name", "description"]}},
+ body: '{"query": {"bool": {"must": [{"multi_match": {"query": "foo", "fields":
+ ["name", "description"]}}], "filter": [{"match": {"content_type": "product.Product"}}]}},
"_source": ["pk"]}'
headers:
connection: [keep-alive]
@@ -8,7 +9,7 @@ interactions:
method: GET
uri: http://search:9200/storefront__product_product/_search
response:
- body: {string: '{"took":93,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
+ body: {string: '{"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
headers:
content-length: ['123']
content-type: [application/json; charset=UTF-8]
diff --git a/tests/cassettes/test_new_search_with_results.yaml b/tests/cassettes/test_new_search_with_results.yaml
index 6b9f42f12f..322a98b332 100644
--- a/tests/cassettes/test_new_search_with_results.yaml
+++ b/tests/cassettes/test_new_search_with_results.yaml
@@ -1,6 +1,7 @@
interactions:
- request:
- body: '{"query": {"multi_match": {"query": "group", "fields": ["name", "description"]}},
+ body: '{"query": {"bool": {"must": [{"multi_match": {"query": "group", "fields":
+ ["name", "description"]}}], "filter": [{"match": {"content_type": "product.Product"}}]}},
"_source": ["pk"]}'
headers:
connection: [keep-alive]
@@ -8,7 +9,7 @@ interactions:
method: GET
uri: http://search:9200/storefront__product_product/_search
response:
- body: {string: '{"took":25,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":3.7124774,"hits":[{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:32","_score":3.7124774,"_source":{"pk":"32"}}]}}'}
+ body: {string: '{"took":10,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":3.7124774,"hits":[{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:32","_score":3.7124774,"_source":{"pk":"32"}}]}}'}
headers:
content-length: ['262']
content-type: [application/json; charset=UTF-8]