es修改数据


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM