代码
# -*- coding: utf-8 -*-
# @Author : markadc
import random
from elasticsearch import Elasticsearch, helpers
url = '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)