作者:小杰01234 | 来源:互联网 | 2023-05-26 15:31
新增字段
PUT http://host/index名字/_mapping
{"properties":{"last_time_used":{"type" : "date"}}
}
全部更新
参考:http://t.zoukankan.com/itBlogToYpl-p-13367859.html
https://www.zhihu.com/question/400814362/answer/1284775773
###
try:updateBody = {"script": {"source": "ctx._source['字段名'] = params['字段名']",## "source": "ctx._source.'字段名'= params.'字段名'","lang": "painless","params": {"字段名": 0}}}print("here")es_client.update_by_query(index=_index, body=updateBody)
except:pass

批量更新
{'_op_type': 'update','_index': 'index-name','_type': 'document','_id': 42,'doc': {'question': 'The life, universe and everything.'}
}
ACTIONS = []
_index = "*8st_"
k = 0
for i in final:response = es_client.search(body={"query": {"bool": {"must": [{"term": {"aid": i[0]}}], }},# "_source": ["_id"]}, index=_index)# print(response)for j in response["hits"]["hits"]:_id = j["_id"]# print(_id)ACTIONS.append({"_index": _index,'_op_type': 'update',"_id": _id,"_source": {"doc": {"aid_score": float(i[1])}}})k+=1print(k)elasticsearch.helpers.bulk(es_client, ACTIONS, index=_index, raise_on_error=False)