Created
August 17, 2017 22:52
-
-
Save tombasche/dec2cc17451b338e254dcaa807597078 to your computer and use it in GitHub Desktop.
Index a json file into elasticsearch pip install 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 | |
import elasticsearch | |
def send_to_es(payload, _id, list_name): | |
es = elasticsearch.Elasticsearch() | |
es.index(index=list_name, doc_type='item', id=_id, body=payload) | |
def process_file(file, list_name): | |
with open(file) as data_file: | |
data = json.load(data_file) | |
_id = 1 | |
for med in data[list_name]: | |
send_to_es(med, _id) | |
_id += 1 | |
if __name__ == '__main__': | |
""" | |
Usage: | |
python process.py file.json name_of_list_to_process | |
""" | |
process_file(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment