Created
October 20, 2018 15:50
-
-
Save pbindustries/3052c24cbbf66264932ac153c6f7be70 to your computer and use it in GitHub Desktop.
json-to-elasticsearch
This file contains 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
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) |
This file contains 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 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