-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.py
28 lines (25 loc) · 888 Bytes
/
route.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
######################################################################################
######## this step is for searching with Elasticsearch
######## don't change anything without permission please.
######################################################################################
es = Elasticsearch("http://elasticsearch:9200")
# this is your route to get a result on json array
@pro.route('/searchingProduct', methods=['POST'])
@require_appkey
def index():
#this is your key sended
nameProduct = request.json['nameProduct']
body = {
"size": 10,
"query": {
"prefix": {
"name_product.keyword": nameProduct,
}
},
"_source": ["name_product"]
}
results = es.search(index = 'product_db.product', body = body)
numberOfResults = results['_shards']['successful'] - 1
return jsonify({
'msg': results['hits']['hits']
})