代码
# -*- coding: utf-8 -*-
# @Author : markadcimport randomfrom elasticsearch import Elasticsearch, helpersurl = 'http://localhost:9200/'
client = Elasticsearch(url)
index = 'test'some = []
for i in range(1, 10001):docu = {'uid': i, 'age': random.randint(1, 100)} # 每一条数据one = {'_index': index,'_id': i, # ES索引数据的唯一标识,不指定_id的值ES也会自动生成'_source': docu}some.append(one)result = helpers.bulk(client, some)
print(result)