Created
July 19, 2017 21:45
-
-
Save afym/f1ac96d2fae449b3392c39d69b20781a to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# 0. Some constants to re-define to match your environment | |
ES_HOST=localhost:9200 | |
ES_INDEX=bookingmotor/hotels | |
JSON_FILE_IN=/home/angel/personal/elasticsearch/result-14-v1.json | |
JSON_FILE_OUT=/home/angel/personal/elasticsearch/result-14-bulk-v1.json | |
# 1. Python code to transform your JSON file | |
PYTHON="import json,sys; | |
out = open('$JSON_FILE_OUT', 'w'); | |
with open('$JSON_FILE_IN') as json_in: | |
docs = json.loads(json_in.read()); | |
for doc in docs: | |
out.write('%s\n' % json.dumps({'index': {}})); | |
out.write('%s\n' % json.dumps(doc, indent=0).replace('\n', '')); | |
" | |
# 2. run the Python script from step 1 | |
python -c "$PYTHON" | |
# 3. use the output file from step 2 in the curl command | |
curl -s -XPOST $ES_HOST/$ES_INDEX/_bulk --data-binary @$JSON_FILE_OUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment