栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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

新增字段

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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/423194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号