案例:
from elasticsearch import Elasticsearch
from elasticsearch import helpers
es_conn = Elasticsearch('your hosts', timeout=120)
def update_by_query():
"""
更新指定条件的数据
"""
index_name = '你的表名'
index_type = '的表类型'
query_json = {
"query": {"bool": {
"must": [
{"term": {"字段名.keyword": 字段值}},
{"term": {"字段名.keyword": 字段值}},
{"term": {"字段名": 字段值}}
]}},
"script": {
"inline": "ctx._source.字段名 = params.字段名;"
"ctx._source.字段名 = params.字段名",
"params": {
"字段名": 具体赋值,
"字段名": 具体赋值
},
"lang": "painless"
}
}
es_conn.update_by_query(index=index_name, doc_type=index_type, body=query_json)
if __name__ == "__main__":
update_by_query()