Last active
August 29, 2015 14:08
-
-
Save dtornow/b6f54f6053d4d9e01f05 to your computer and use it in GitHub Desktop.
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
var npm = require("npm"), | |
querystring = require("querystring"); | |
if(process.env.CONNECTION_STRING && process.env.INDEX && process.env.TYPE) { | |
npm.load({}, function (err) { | |
npm.commands.install(["elasticsearch"], function (err) { | |
var header, body; | |
try { | |
header = querystring.parse(process.env.HTTP_HEADER); | |
} catch(ex){ | |
header = process.env.HTTP_HEADER; | |
} | |
try { | |
body = JSON.parse(process.env.HTTP_BODY); | |
} catch(ex){ | |
body = process.env.HTTP_BODY; | |
} | |
var client = new require("elasticsearch").Client({ | |
host: process.env.CONNECTION_STRING | |
}); | |
client.index({ | |
index: process.env.INDEX, | |
type: process.env.TYPE, | |
body: { | |
header: header, | |
body: body | |
} | |
}, function (err, res) { | |
if (err) { | |
return console.log(err); process.exit(0); | |
} | |
return console.log(res); | |
}); | |
}); | |
}); | |
} else { | |
process.exit(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment