0
私はユーザーのお気に入りの製品を更新したいと思います。私はPythonでそれを行うことはできません。この例では、これはあなたが私がお気に入り配列は、製品のIDを格納したい見ての通り、私は顧客のINDEXElasticsearchとPythonのタグ配列リストを更新する方法
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "customers",
"_type": "customer",
"_id": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"_score": 1,
"_source": {
"uid": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"email": "[email protected]",
"favorites": [], < ---- this is the problem
"history": [],
"settings": {},
"purchases ": [],
"created": 1507892081201,
"updated": 1507892081201
}
}
]
}
に持っているスキーマです
追加および削除タグのユーザと同じですユーザーがお気に入りの商品として選んだ私はこのコードを試してみましたが、動作しませんされて
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "customers",
"_type": "customer",
"_id": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"_score": 1,
"_source": {
"uid": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"email": "[email protected]",
"favorites": ['product_id_1', 'product_id_2', 'product_id_3'], < ---- this is the problem
"history": ['id_1', 'id_2', 'id_3'],
"settings": {},
"purchases ": [],
"created": 1507892081201,
"updated": 1507892081201
}
}
]
}
:
fav_product = {
"user_id": "user_1",
"product_id": "favorite_product_1",
}
def add_favevorite_product(fav_product):
''' Add new favorite product '''
user_id = fav_product['user_id']
product_id = fav_product['product_id']
print('Start new favorite product')
timestamp = int(round(time.time() * 1000))
doc = {
'favorites' : "ctx._source.tags.add(product_id)",
'created': timestamp,
'updated': timestamp
}
es.update(index="customers", doc_type='customer', id=user_id, body={"doc": doc})
es.indices.refresh(index="customers")
return jsonify({'message': 'customer_updated'}), 200
# return jsonify(fav_product), 200
#end
は、サーバから、この応答の有無:
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "customers",
"_type": "customer",
"_id": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"_score": 1,
"_source": {
"uid": "QOTzXMUcrnbsYyFKeouHnjlkjQB3",
"email": "[email protected]",
"favorites": "ctx._source.favorites.add(AV8PsBG_oWUfB334-p5b)",
"history": [],
"settings": {},
"purchases ": [],
"created": 1507893703655,
"updated": 1507893703655
}
}
]
}
OMG BROOOOOOOOOOOO THANX、私はseその日のためにアーチング。私はあなたが私を助けてうれしい –