Skip to content

Instantly share code, notes, and snippets.

@pbindustries
Created October 20, 2018 15:50
Show Gist options
  • Save pbindustries/3052c24cbbf66264932ac153c6f7be70 to your computer and use it in GitHub Desktop.
Save pbindustries/3052c24cbbf66264932ac153c6f7be70 to your computer and use it in GitHub Desktop.
json-to-elasticsearch
es = Elasticsearch(
['localhost'],
port=9200
)
es = Elasticsearch(ES_CLUSTER)
with open("C:\ElasticSearch\shakespeare_6.0.json") as json_file:
json_docs = json.load(json_file)
es.bulk(ES_INDEX, ES_TYPE, json_docs)
import sys
import json
from pprint import pprint
from elasticsearch import Elasticsearch
es = Elasticsearch(
['localhost'],
port=9200
)
MyFile= open("C:\ElasticSearch\shakespeare_6.0.json",'r').read()
ClearData = MyFile.splitlines(True)
i=0
json_str=""
docs ={}
for line in ClearData:
line = ''.join(line.split())
if line != "},":
json_str = json_str+line
else:
docs[i]=json_str+"}"
json_str=""
print(docs[i])
es.index(index='shakespeare', doc_type='Blog', id=i, body=docs[i])
i=i+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment