Makes life easy with ElasticSearch.
elastic = require('elasticsearch');
Etk = require('etk');
// Elasticsearch instance is initialized as documented at it's
// project space
var client = elastic.Client({hosts: ['localhost:9200']});
// Etk instance "tk_1" calls against index = my_index and type = my_type
var tk_1 = Etk(client, {index: "my_index", type: "my_type"});
// search Etk API call returns back the search result
tk_1.search("foo", "bar", function (err, resp) {
// Etk inserts "source()" method to response, so you can easily get
// the data array found in search
console.log(JSON.stringify(resp.source());
// Etk inserts "score()" method to response, so you can easily get
// the score array found in search
console.log(JSON.stringify(resp.score());
// elasticsearch original response can be reached from resp.resp
// for further data manipulation for special cases.
console.log(JSON.stringify(resp.resp);
});
// Etk instance "tk_2" forwards elasticsearch error and response messages
// to application. See class documentation for full list of options
// you can configure
var tk_2 = Etk(client, {index: "another_index",
type: "another_type",
raw_response: true,
raw_error: true});
// search Etk API call returns back the search result
tk_2.search("baz", "bar", function (err, resp) {
// Application should handle raw error and response messages
// received from elasticsearch.
...
});
$ npm install etk
Project site documents the latest NPM release.
Original author of Etk is R. Saltuk Alakus
Looking for maintainers. Please drop me an email at saltukalakus@gmail.com