Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesjara/7ec8f6c4a160df6d1f13959ab5714a9f to your computer and use it in GitHub Desktop.
Save jamesjara/7ec8f6c4a160df6d1f13959ab5714a9f to your computer and use it in GitHub Desktop.
import parse fix mongo to elasticsearch bulk
# 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