# 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-routing
* es修改数据:
# update_by_query:
def update_order_info_by_id(data_list):
update_body = {
"query": {
"term": {"_id": id_}
},
"script": {
"inline": "ctx._source.order_info=params.order_info",
"params": {
‘order_info‘ : {"test": "999qwwe", ‘aa‘:"sssqweee"}
}
}
}
resp = es.update_by_query(index=index, doc_type=doc_type, body=update_body)
# 批量修改
def update_order_info_by_id(data_list):
# res_set = set()
res_set = []
for id_ in data_list:
res_dict = dict()
res_dict["_index"] = index
res_dict["_op_type"] = "update"
res_dict["_type"] = doc_type
res_dict["_id"] = "AWZb5L8Kt4yMTep0SgOS" # 批量修改时id必须传递
update_body = {
"script": {
"inline": "ctx._source.order_info=order_info",
"params": {
‘order_info‘ : {"test": "999qwwe", ‘aa‘:"sssqweee"}
}
}
}
res_dict.update(update_body)
res_set.append(res_dict)
success, _ = helpers.bulk(es, actions=res_set)
原文:https://www.cnblogs.com/lajiao/p/9897943.html