1. 批量建索引
for i in range(0,1000):
newDic = {"key":"value"}
action = {"_index": IndexName, "_type": TypeName, "_id": _id, "_source": newDic}
actions.append(action)
#--------------bukl index actions
if len(actions)>0:
finished = False
while not finished:
try:
# bulk create index
helpers.bulk(es, actions, chunk_size=1000, request_timeout=30)
finished = True
except ConnectionTimeout:
s = traceback.format_exc()
print s
del actions[:]
2. 批量删除
action = {
'_op_type': 'delete',
'_index': 'index-name',
'_type': 'document',
'_id': 42,
}
actions.append(action)
3. 批量更新
action = {
'_op_type': 'update',
'_index': 'index-name',
'_type': 'document',
'_id': 42,
'doc': {'question': 'The life, universe and everything.'}
}
actions.append(action)