Created
July 31, 2016 21:52
-
-
Save jamesjara/7ec8f6c4a160df6d1f13959ab5714a9f to your computer and use it in GitHub Desktop.
import parse fix mongo to elasticsearch bulk
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
# export mongo db as json data | |
mongoexport -d corex1 -c data -o data.json | |
# to fix " contains an unknown parameter [$oid]" need to delete key with JQ command | |
sudo apt-get install jq | |
jq -c 'del(._id)' data.json > tmp.$$.json && mv tmp.$$.json data_fixed.json | |
# also lets fix date field eg "t":{"$date":1463606674833} | |
# hardcoded time for now | |
jq -c '. + {t: 1469998152}' data_fixed.json > tmp.$$.json && mv tmp.$$.json data_fixed.json | |
# add new index | |
curl -XPUT http:xxx/<index>/_mapping/<type> -d ' | |
{ | |
"properties" : { | |
"location": { "type" : "geo_point" } | |
} | |
}' | |
# add format of Elastic search to bulk create "Malformed action/metadata line [1]" | |
# will generate a file with the format of elastic | |
./convertoElastic.py | |
# import as bulk | |
curl -XPOST http://xxxxx00/mynewdb/results/_bulk --data-binary @data_elastic.json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment