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