概述
新增字段
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+=1
print(k)
elasticsearch.helpers.bulk(es_client, ACTIONS, index=_index, raise_on_error=False)
最后
以上就是鲤鱼冰淇淋为你收集整理的es 按字段全部更新置0、批量更新bulk的全部内容,希望文章能够帮你解决es 按字段全部更新置0、批量更新bulk所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复