Created
August 25, 2021 14:43
-
-
Save numanturle/5ac3f00c593fcf1fd484b113dede79b0 to your computer and use it in GitHub Desktop.
elasticsearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
from time import sleep | |
from datetime import datetime | |
from elasticsearch import Elasticsearch, helpers | |
es = Elasticsearch("localhost:9200") | |
def create_index(index): | |
es.indices.create(index=index, ignore=400) | |
def insert_one_data(_index, data,idkey): | |
res = es.index(index=_index, id=idkey, body=data) | |
print(res) | |
index = "huhuhuggggg" | |
num = 1 | |
with open("data.json") as infile: | |
for line in infile: | |
try: | |
dict_doc = json.loads(line.rstrip()) | |
insert_one_data(index,dict_doc) | |
num = num + 1 | |
except json.decoder.JSONDecodeError as err: | |
print ("error pass") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment