Skip to content

Instantly share code, notes, and snippets.

@dtornow
Last active August 29, 2015 14:08
Show Gist options
  • Save dtornow/b6f54f6053d4d9e01f05 to your computer and use it in GitHub Desktop.
Save dtornow/b6f54f6053d4d9e01f05 to your computer and use it in GitHub Desktop.
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