Created
April 21, 2013 17:57
-
-
Save pulkitsinghal/5430444 to your computer and use it in GitHub Desktop.
How to index documents with elastic.js client?
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 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); |
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
#!/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