Update services/elasticsearch.py
Browse files
services/elasticsearch.py
CHANGED
@@ -29,21 +29,22 @@ def search_elasticsearch(index, query):
|
|
29 |
|
30 |
def search_products_by_keywords(encoded_query):
|
31 |
body_query = {
|
32 |
-
"_source": [
|
|
|
33 |
"knn": {
|
34 |
-
"field": "
|
35 |
"query_vector": encoded_query,
|
36 |
"k": 4,
|
37 |
"num_candidates": 500
|
38 |
}
|
39 |
}
|
40 |
|
41 |
-
response = es.search(index='
|
42 |
return response['hits']['hits']
|
43 |
|
44 |
|
45 |
def search_products_by_filters(filters):
|
46 |
-
response = es.search(index='
|
47 |
"query": {
|
48 |
"bool": {
|
49 |
"filter": filters
|
@@ -54,12 +55,12 @@ def search_products_by_filters(filters):
|
|
54 |
|
55 |
|
56 |
def get_product_details(product_id):
|
57 |
-
response = es.get(index='
|
58 |
return response['_source']
|
59 |
|
60 |
|
61 |
def index_product(product: Product):
|
62 |
-
es.index(index="
|
63 |
|
64 |
|
65 |
def index_customer(customer: Customer):
|
@@ -134,4 +135,4 @@ def checkout(customer_id: str):
|
|
134 |
}
|
135 |
es.index(index="orders", body=order)
|
136 |
es.delete(index="carts", id=customer_id)
|
137 |
-
return order
|
|
|
29 |
|
30 |
def search_products_by_keywords(encoded_query):
|
31 |
body_query = {
|
32 |
+
"_source": ['Gender', 'Category', 'SubCategory', 'ProductType',
|
33 |
+
'Colour', 'Usage', 'ProductTitle', 'ImageURL'],
|
34 |
"knn": {
|
35 |
+
"field": "ImageEmbedding",
|
36 |
"query_vector": encoded_query,
|
37 |
"k": 4,
|
38 |
"num_candidates": 500
|
39 |
}
|
40 |
}
|
41 |
|
42 |
+
response = es.search(index='fashion', body=body_query)
|
43 |
return response['hits']['hits']
|
44 |
|
45 |
|
46 |
def search_products_by_filters(filters):
|
47 |
+
response = es.search(index='fashion', body={
|
48 |
"query": {
|
49 |
"bool": {
|
50 |
"filter": filters
|
|
|
55 |
|
56 |
|
57 |
def get_product_details(product_id):
|
58 |
+
response = es.get(index='fashion', id=product_id)
|
59 |
return response['_source']
|
60 |
|
61 |
|
62 |
def index_product(product: Product):
|
63 |
+
es.index(index="fashion", id=product.product_id, body=product.dict())
|
64 |
|
65 |
|
66 |
def index_customer(customer: Customer):
|
|
|
135 |
}
|
136 |
es.index(index="orders", body=order)
|
137 |
es.delete(index="carts", id=customer_id)
|
138 |
+
return order
|