Elasticsearch 使用 Python 导入数据
from elasticsearch import Elasticsearch #引入 es 模块
import csv #引入 python 自带的 csv 模块
#from elasticsearch import helpers
ip = 'xxx.xxx.xxx.xxx'
port = xxxx
es = Elasticsearch([ip],port=port)
file = 'C:\\Users\\Administrator\\Desktop\\data.csv'
print('\nstart to import....................\n')
def parse_csv(datafile):
data = []
#n = 0
with open(datafile, "rt",encoding='utf8') as sd:
r = csv.DictReader(sd) #为每行创建一个字典,同时将字段名称与表头对应
#每行对应返回一个 dict 数据类型
for line in r:
#print('start: ' + str(line) + ' end')
data.append(line)
return data
data = parse_csv(file)
#print(data)
for d in data: