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

es 按字段全部更新置0、批量更新bulk_第1张图片

批量更新


{
  '_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)

你可能感兴趣的:(知识点,python,elasticsearch,大数据,big,data)