python + elasticsearch : csv => bulk json 변환
## csv => bulk type의 파일로 변환
def csvFileRead(self):
with open(self._csv_path, "r", encoding="utf-8") as csv_file:
with open("/home/elastic/test.dir/py_test/the_planet_code/the_planet.json", "a", encoding="utf-8") as f:
csv_reader = csv.DictReader(csv_file, delimiter=",")
for c, r in enumerate(csv_reader):
h = json.dumps({"index": {"_index": "the_planet_poc_index_1", "_type": "_doc", "_id": "the_planet_" + str(c+1)}},
ensure_ascii=False)
f.write(h + "\n")
e = json.dumps((dict(r)),
ensure_ascii=False)
f.write(e + "\n")
time.sleep(2)
f.close()
csv_file.close()
'ELK > elasticsearch' 카테고리의 다른 글
Elasticsearch + python + pipeline (0) | 2019.12.02 |
---|---|
네이버 무비 정보 크롤링 => logstash data pipe_line => kibana 시각화 (0) | 2019.11.10 |
elasticsearch SSL 적용 connect code + python (0) | 2019.10.22 |
logstash_01 / json (0) | 2019.10.19 |
elasticsearch + java _api + match_all (0) | 2019.06.04 |