Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Created April 21, 2013 17:57
Show Gist options
  • Save pulkitsinghal/5430444 to your computer and use it in GitHub Desktop.
Save pulkitsinghal/5430444 to your computer and use it in GitHub Desktop.
How to index documents with elastic.js client?
var ejs = require('elastic.js'),
nc = require('elastic.js/elastic-node-client');
if (!(process.env.ES_HOST &&
process.env.ES_PORT))
{
console.error('FATAL: All of the required environment variables have not been configured');
process.exit(1);
}
console.log(process.env.ES_HOST + ':' +process.env.ES_PORT);
/* setup client */
ejs.client = nc.NodeClient(process.env.ES_HOST, process.env.ES_PORT);
/* construct a Document object */
var doc = ejs.Document('dummy_index', 'dummy_type').source({'type':'blah', 'field1':'value1'});
/* a function to display results */
var resultsCallBack = function(results) {
console.log(results);
};
/* index the document */
doc.doIndex(resultsCallBack);
#!/bin/sh
# Q: How to run this file?
# A: Use ". setenv.sh" instead of "./setenv.sh"
# Q: Why?
# A: http://stackoverflow.com/questions/10781824/export-not-working-in-my-shell-script
export ES_HOST=blah.es.com
export ES_PORT=xxx
echo $ES_HOST $ES_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment