elasticsearch更新数据操作update_by_query

  update_by_query 顾名思义,通过查询更新,既先query出符合条件的内容再进行update操作,新增字段,修改字段值都可以满足

demo:

es = Elasticsearch()
body = {
            "script": {
            "lang": "painless",
            # "inline": "if (ctx._source.test_code == null) {ctx._source.test_code= '02'}"
            "inline": "ctx._source.kw_sourceType= 'trueTime'"   #新增字段kw_sourceType值为trueTime
              }
            }
res = es.update_by_query(index="hot_rank", doc_type="baidu_hot_search_rank", body=body)

painless更多内容参见:https://blog.csdn.net/u013613428/article/details/78134170#%E9%80%9A%E8%BF%87painless%E6%9B%B4%E6%96%B0%E5%AF%B9%E8%B1%A1%E5%80%BC

update_by_query更多内容参见:

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

 

posted @ 2018-08-17 14:47  穷开心y  阅读(33932)  评论(0编辑  收藏  举报