Using with Node.js
Elasticsearch Node.js client is official client for Node.js.
A sample Node.js application can be found on GitHub https://github.com/searchly/searchly-nodejs-sample.
Configuration
Add elasticsearch dependency to your
package.json
file and use
npm
to install your dependencies
"dependencies": {
"elasticsearch": ">=1.1.0"
}
Search
Create a search client:
var elasticsearch = require('elasticsearch');
var connectionstring = process.env.searchbox_url;
var client = new elasticsearch.client({
host: connectionstring
});
Index a document
client.index({
index: 'sample',
type: 'document',
id: '1',
body: {
name: 'reliability',
text: 'reliability is improved if multiple redundant sites are used, which makes well-designed cloud computing suitable for business continuity.'
}
}, function (error, response) {
console.log(response);
});
Create a query and search it
client.search({
index: 'sample',
type: 'document',
body: {
query: {
query_string:{
query:"reliability"
}
}
}
}).then(function (resp) {
console.log(resp);
}, function (err) {
console.log(err.message);
});
Detailed documentation for Nodejs client can be found here