elasticsearch에서 여러 인덱스의 대량 업데이트 (이 방법은doc의 id에 따라)

gol_index_name = "index_*"
es_search_optionsss = {
  "query":{"match_all": {}}
}
es_result = es_client.search(index=gol_index_name, doc_type="index_type", 
                      body=es_search_optionsss)
ids_list = []
#  ( )
index_set = set()
for i in es_result["hits"]["hits"]:
    id = i["_id"]
    index_name = i["_index"]
    index_set.add(index_name)
    ids_list.append({"id": id, "index_name": index_name})
index_all_list = list(index_set)
#   [[],[],[]]
index_id_list = [[] for i in range(len(index_all_list))]
#  for id 
#  index_id_list 0 index_all_list 0   index_id_list 0 
for i in ids_list:
    index_count = index_all_list.index(i["index_name"])
    index_id_list[index_count].append(i["id"])
#  
for i, j in zip(index_all_list, index_id_list):
    updateBody = {
         "query": {
                "bool": {
                    "filter": {"terms": {"_id": j}}
                }

            },
            "script": {
                "inline": "ctx._source.is_linked = params.is_linked",
                "params": {
                    "is_linked": 1
                },
                "lang": "painless"

            }
        }
     update_result = es_client.update_by_query(index=i, doc_type='index_type',
                                                  body=updateBody)
es_client.indices.flush()

좋은 웹페이지 즐겨찾기