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()