Permalink
Browse files

Merge pull request #5 from richmarr/master

Added some more of Elasticsearch's API calls
  • Loading branch information...
ncb000gt committed Nov 8, 2011
2 parents d583ad0 + 6724490 commit 56f9e33287a35cdc464f916965ccfb515f4b4df0
Showing with 116 additions and 0 deletions.
  1. +116 −0 lib/elasticsearch.js
View
@@ -85,6 +85,34 @@ ElasticSearch.prototype.query = function(opts, query, cb) {
utils.request(utils.mapConfig(def, utils.default_config, opts), query, cb);
}
+ElasticSearch.prototype.count = function(opts, query, cb) {
+ if (opts && query && !cb && typeof (query) == 'function') {
+ cb = query;
+ query = opts;
+ opts = {};
+ }
+ var def = {
+ method: 'POST',
+ path: '/' + this.index + '/_count'
+ };
+
+ utils.request(utils.mapConfig(def, utils.default_config, opts), query, cb);
+}
+
+ElasticSearch.prototype.terms = function(opts, query, cb) {
+ if (opts && query && !cb && typeof (query) == 'function') {
+ cb = query;
+ query = opts;
+ opts = {};
+ }
+ var def = {
+ method: 'GET',
+ path: '/' + this.index + '/_terms'
+ };
+
+ utils.request(utils.mapConfig(def, utils.default_config, opts), query, cb);
+}
+
ElasticSearch.prototype.queryAll = function(opts, query, cb) {
var def = {
method: 'POST',
@@ -93,3 +121,91 @@ ElasticSearch.prototype.queryAll = function(opts, query, cb) {
utils.request(utils.mapConfig(def, utils.default_config, opts), query, cb);
}
+
+ElasticSearch.prototype.deleteRiver = function(opts, name, cb) {
+ if (opts && name && !cb && typeof(name) == 'function') {
+ cb = name;
+ name = opts;
+ opts = {};
+ }
+ var def = {
+ method: 'DELETE',
+ path: '/_river/'+name+'/'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), cb);
+}
+
+ElasticSearch.prototype.putRiver = function(opts, river, cb) {
+ if (opts && river && !cb ) {
+ cb = river;
+ river = opts;
+ opts = {};
+ }
+ var name = opts.name || river.index && river.index.index;
+ var def = {
+ method: 'PUT',
+ path: '/_river/'+name+'/_meta'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), river, cb);
+}
+
+ElasticSearch.prototype.getRiver = function(opts, name, cb) {
+ if (opts && name && !cb ) {
+ cb = name;
+ name = opts;
+ opts = {};
+ }
+ var def = {
+ method: 'GET',
+ path: '/_river/'+name+'/_meta'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), cb);
+}
+
+ElasticSearch.prototype.getMapping = function(opts, type, cb) {
+ if (opts && type && !cb ) {
+ cb = type;
+ type = opts;
+ opts = {};
+ }
+ if ( type.constructor.name === 'Array' ) type = type.join();
+ var def = {
+ method : 'GET',
+ path : '/'+this.index+'/'+type+'/_mapping'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), cb);
+};
+
+ElasticSearch.prototype.putMapping = function(opts, config, cb) {
+ if (opts && config && !cb ) {
+ cb = config;
+ config = opts;
+ opts = {};
+ }
+ var def = {
+ method : 'PUT',
+ path : '/'+this.index+'/'+config.name+'/_mapping'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), config.mapping, cb);
+};
+
+ElasticSearch.prototype.deleteMapping = function(opts, config, cb) {
+ if (opts && config && !cb ) {
+ cb = config;
+ config = opts;
+ opts = {};
+ }
+ var def = {
+ method : 'DELETE',
+ path : '/'+this.index+'/'+config.name+'/_mapping'
+ };
+ utils.request(utils.mapConfig(def, utils.default_config, opts), cb);
+};
+
+exports.createMapping = function( type, mapping, callback ){
+ client.createMapping( opts, type, callback );
+};
+
+exports.deleteMapping = function( type, callback ){
+ client.deleteMapping( opts, type, callback );
+};

0 comments on commit 56f9e33

Please sign in to comment.