Skip to content

Instantly share code, notes, and snippets.

@numanturle
Created August 25, 2021 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numanturle/5ac3f00c593fcf1fd484b113dede79b0 to your computer and use it in GitHub Desktop.
Save numanturle/5ac3f00c593fcf1fd484b113dede79b0 to your computer and use it in GitHub Desktop.
elasticsearch
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