Permalink
Browse files

Added a 'get' method and some testing around that and deletion.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent eae5ae7 commit f0361589158ef8cb4fe1ed113ef3ce99078f0b03 @ncb000gt committed Mar 8, 2011
Showing with 45 additions and 1 deletion.
  1. +10 −1 lib/elasticsearch.js
  2. +35 −0 tests/suites/test-client.js
View
@@ -69,12 +69,21 @@ ElasticSearch.prototype.delete = function(opts, cb) {
}
var def = {
method: 'DELETE',
- path: '/' + this.index + '/' + ((opts.type)?(opts.type+(opts.id)?'/'+opts.id:''):'')
+ path: '/' + this.index + '/' + ((opts.type)?(''+opts.type+((opts.id)?'/'+opts.id:'')):'') + ((opts.refresh)?'?refresh=true':'')
};
utils.request(utils.mapConfig(def, utils.default_config, opts), undefined, cb);
}
+ElasticSearch.prototype.get = function(opts, cb) {
+ var def = {
+ method: 'GET',
+ path: '/' + this.index + '/' + opts.type + '/' + opts.id
+ };
+
+ utils.request(utils.mapConfig(def, utils.default_config, opts), cb);
+}
+
ElasticSearch.prototype.query = function(opts, query, cb) {
if (opts && query && !cb && typeof (query) == 'function') {
cb = query;
@@ -10,6 +10,20 @@ module.exports = testCase({
assert.done();
});
},
+ 'add and get document': function(assert) {
+ assert.expect(3);
+ var self = this,
+ config = {type:'info', id:'1', refresh: true},
+ doc = {field1: 'test field', field2: 'second test field'};
+ this.client.add(config, doc, function(err, result) {
+ assert.ok(result.ok);
+ self.client.get(config, function(err, result) {
+ assert.ifError(err);
+ assert.deepEqual(result._source, doc);
+ assert.done();
+ });
+ });
+ },
'add and find document': function(assert) {
assert.expect(3);
var self = this,
@@ -25,5 +39,26 @@ module.exports = testCase({
assert.done();
});
});
+ },
+ 'add, get and delete a document': function(assert) {
+ assert.expect(6);
+ var self = this,
+ config = {type:'info', id:'1', refresh: true},
+ doc = {field1: 'test field', field2: 'second test field'};
+ this.client.add(config, doc, function(err, result) {
+ assert.ifError(err);
+ assert.ok(result.ok);
+ self.client.get(config, function(err, result) {
+ assert.ifError(err);
+ assert.deepEqual(result._source, doc);
+ self.client.delete(config, function(err, result) {
+ assert.ifError(err);
+ self.client.get(config, function(err, result) {
+ assert.ok(err);
+ assert.done();
+ });
+ });
+ });
+ });
}
})

0 comments on commit f036158

Please sign in to comment.