node-esc
node-esc is a small client that helps you interact with ElasticSearch.
Installation
$ npm install node-esc
Usage
var ESIndex = ;var esi = 'http://localhost:9200/twitter';esi; esitweet;
API
Each type added to ESIndex instance has following methods:
query(urlParam, respBody, callback)
call index with urlParam added to url and respBody passed as responseBody, and pass ElasicSearch response to callback. With this method you are able to do any operation on type.
// search for tweets by user esitweet;
index(id, data, callback)
add (or update) document to index (http://www.elasticsearch.org/guide/reference/api/index_.html) When first parameter (id) is absent then _id from data will be used
esitweetindex1 user: 'foo' message: 'lorem ipsum' { console; /** logs response from ElasticSearch: { ok : true, _index : "twitter", _id : "1", _version : 1, _type : "tweet" } */ };
delete(id/doc, callback)
delete document (http://www.elasticsearch.org/guide/reference/api/delete.html) with passed id (when first param is object then use _id as document identifier)
esitweet;
update(id, configObject, callback)
update document with passed id. Send configObject as response body (http://www.elasticsearch.org/guide/reference/api/update.html)
esitweet;
getById(id, callback)
get document by id (http://www.elasticsearch.org/guide/reference/api/get.html) (number or string) and pass response from ElasticSearch to callback.
esitweet;
mGetById(ids, callback)
get multiple documents by array of ids () and pass response from ElasticSearch to callback.
esitweet;
search(searchConfig, callback)
execute search in type, with searchConfig passed as request body (http://www.elasticsearch.org/guide/reference/api/search/request-body.html) and pass ElasticSearch reponse to callback.
esitweet;