码迷,mamicode.com
首页 > 其他好文 > 详细

es修改数据

时间:2018-11-02 20:24:48      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:param   order   app   ram   uid   routing   for   script   data   

# 官方文档: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)

es修改数据

标签:param   order   app   ram   uid   routing   for   script   data   

原文地址:https://www.cnblogs.com/lajiao/p/9897943.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!