Skip to content

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

Move index parameter from query to URI

Jakub Draganek07c92cf7d68e
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.py
index 17dfeafafa..f269b3deb1 100644
--- a/saleor/search/backends/newelastic.py
+++ b/saleor/search/backends/newelastic.py
@@ -7,11 +7,11 @@ CLIENT = Elasticsearch()
def search_products(phrase):
- query = MultiMatch(
- index='storefront__product_product',
- fields=['name', 'description'],
- query=phrase)
- result = Search().query(query).source(['pk']).using(CLIENT).execute()
+ query = MultiMatch(fields=['name', 'description'], query=phrase)
+ result = (Search(index='storefront__product_product').query(query)
+ .source(['pk'])
+ .using(CLIENT)
+ .execute())
return [hit.pk for hit in result]
diff --git a/saleor/search/backends/test_newelastic.py b/saleor/search/backends/test_newelastic.py
index 1b5407c3bb..47fa0de112 100644
--- a/saleor/search/backends/test_newelastic.py
+++ b/saleor/search/backends/test_newelastic.py
@@ -13,7 +13,6 @@ def es_search_query(search_phrase):
'query': {
'multi_match': {
'query': 'How fortunate man with none',
- 'index': 'storefront__product_product',
'fields': ['name', 'description']
}
},
@@ -22,9 +21,15 @@ def es_search_query(search_phrase):
return query
-def test_no_result_search(mocker, es_search_query, search_phrase):
+def storefront_index():
+ return 'storefront__product_product'
+
+
+def test_no_result_search(mocker, es_search_query, search_phrase,
+ storefront_index):
mocker.patch.object(newelastic.CLIENT, 'search', returnvalue=[])
products = newelastic.search_products(search_phrase)
newelastic.CLIENT.search.assert_called_once_with(
- body=es_search_query, doc_type=[], index=None)
+ body=es_search_query, doc_type=[], index=[storefront_index])
assert not products
diff --git a/tests/cassettes/test_new_search_with_empty_results.yaml b/tests/cassettes/test_new_search_with_empty_results.yaml
index e92164ff2e..964edabb80 100644
--- a/tests/cassettes/test_new_search_with_empty_results.yaml
+++ b/tests/cassettes/test_new_search_with_empty_results.yaml
@@ -6,11 +6,11 @@ interactions:
connection: [keep-alive]
content-type: [application/json]
method: GET
- uri: http://search:9200/_search
+ uri: http://search:9200/storefront__product_product/_search
response:
- body: {string: '{"took":104,"timed_out":false,"_shards":{"total":15,"successful":15,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
+ body: {string: '{"took":93,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
headers:
- content-length: ['126']
+ content-length: ['123']
content-type: [application/json; charset=UTF-8]
status: {code: 200, message: OK}
version: 1
diff --git a/tests/cassettes/test_new_search_with_results.yaml b/tests/cassettes/test_new_search_with_results.yaml
index e1e1c4feca..6b9f42f12f 100644
--- a/tests/cassettes/test_new_search_with_results.yaml
+++ b/tests/cassettes/test_new_search_with_results.yaml
@@ -6,11 +6,11 @@ interactions:
connection: [keep-alive]
content-type: [application/json]
method: GET
- uri: http://search:9200/_search
+ uri: http://search:9200/storefront__product_product/_search
response:
- body: {string: '{"took":33,"timed_out":false,"_shards":{"total":15,"successful":15,"failed":0},"hits":{"total":3,"max_score":3.160794,"hits":[{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:39","_score":3.160794,"_source":{"pk":"39"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:35","_score":2.6753218,"_source":{"pk":"35"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:34","_score":2.6753218,"_source":{"pk":"34"}}]}}'}
+ 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"}}]}}'}
headers:
- content-length: ['532']
+ content-length: ['262']
content-type: [application/json; charset=UTF-8]
status: {code: 200, message: OK}
version: 1