热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

es按字段全部更新置0、批量更新bulk

新增字段PUThttp:hostindex名字_mapping{properties:{last_time_used:{type:date}}}全部更新参考

新增字段

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)

推荐阅读
author-avatar
小杰01234
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有