yaml tests passing using a personl instance of ES, working on specifying the host/port
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [bulk](http://elasticsearch.org/guide/reference/api/bulk/) request
|
||||
*
|
||||
@ -17,57 +17,57 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {String} [params.replication=sync] - Explicitely set the replication type
|
||||
* @param {string} params.type - Default document type for items which don't provide one
|
||||
*/
|
||||
function doBulk(params, callback) {
|
||||
function doBulk(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_bulk';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_bulk';
|
||||
delete params.type;
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_bulk';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_bulk';
|
||||
}
|
||||
else {
|
||||
request.url = '/_bulk';
|
||||
request.path = '/_bulk';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -80,7 +80,7 @@ function doBulk(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -90,7 +90,7 @@ function doBulk(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -101,7 +101,7 @@ function doBulk(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
query.type = '' + params.type;
|
||||
@ -109,14 +109,10 @@ function doBulk(params, callback) {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doBulk;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [clear_scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
@ -10,55 +10,51 @@ var _ = require('../lib/toolbelt')
|
||||
* @method clear_scroll
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClearScroll(params, callback) {
|
||||
function doClearScroll(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
switch (typeof params.scroll_id) {
|
||||
case 'string':
|
||||
url.scroll_id = params.scroll_id;
|
||||
parts.scroll_id = params.scroll_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.scroll_id)) {
|
||||
url.scroll_id = params.scroll_id.join(',');
|
||||
parts.scroll_id = params.scroll_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.scroll_id = !!params.scroll_id;
|
||||
parts.scroll_id = !!params.scroll_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.scroll_id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('scroll_id')) {
|
||||
request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClearScroll;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.get_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
@ -10,34 +10,30 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method cluster.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterGetSettings(params, callback) {
|
||||
function doClusterGetSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterGetSettings;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var levelOptions = ['cluster', 'indices', 'shards'];
|
||||
var waitForStatusOptions = ['green', 'yellow', 'red'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.health](http://elasticsearch.org/guide/reference/api/admin-cluster-health/) request
|
||||
*
|
||||
@ -21,36 +21,36 @@ var waitForStatusOptions = ['green', 'yellow', 'red'];
|
||||
* @param {number} params.wait_for_relocating_shards - Wait until the specified number of relocating shards is finished
|
||||
* @param {String} params.wait_for_status - Wait until cluster is in a specific state
|
||||
*/
|
||||
function doClusterHealth(params, callback) {
|
||||
function doClusterHealth(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/_cluster/health/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/_cluster/health/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/_cluster/health';
|
||||
request.path = '/_cluster/health';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.level !== 'undefined') {
|
||||
@ -63,7 +63,7 @@ function doClusterHealth(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.local !== 'undefined') {
|
||||
if (params.local.toLowerCase && (params.local = params.local.toLowerCase())
|
||||
&& (params.local === 'no' || params.local === 'off')
|
||||
@ -73,7 +73,7 @@ function doClusterHealth(params, callback) {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -83,7 +83,7 @@ function doClusterHealth(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -93,7 +93,7 @@ function doClusterHealth(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.wait_for_active_shards !== 'undefined') {
|
||||
if (_.isNumeric(params.wait_for_active_shards)) {
|
||||
query.wait_for_active_shards = params.wait_for_active_shards * 1;
|
||||
@ -101,7 +101,7 @@ function doClusterHealth(params, callback) {
|
||||
throw new TypeError('Invalid wait_for_active_shards: ' + params.wait_for_active_shards + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.wait_for_nodes !== 'undefined') {
|
||||
if (typeof params.wait_for_nodes !== 'object' && params.wait_for_nodes) {
|
||||
query.wait_for_nodes = '' + params.wait_for_nodes;
|
||||
@ -109,7 +109,7 @@ function doClusterHealth(params, callback) {
|
||||
throw new TypeError('Invalid wait_for_nodes: ' + params.wait_for_nodes + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.wait_for_relocating_shards !== 'undefined') {
|
||||
if (_.isNumeric(params.wait_for_relocating_shards)) {
|
||||
query.wait_for_relocating_shards = params.wait_for_relocating_shards * 1;
|
||||
@ -117,7 +117,7 @@ function doClusterHealth(params, callback) {
|
||||
throw new TypeError('Invalid wait_for_relocating_shards: ' + params.wait_for_relocating_shards + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.wait_for_status !== 'undefined') {
|
||||
if (_.contains(waitForStatusOptions, params.wait_for_status)) {
|
||||
query.wait_for_status = params.wait_for_status;
|
||||
@ -128,14 +128,10 @@ function doClusterHealth(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterHealth;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var typeOptions = ['cpu', 'wait', 'block'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_hot_threads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request
|
||||
*
|
||||
@ -16,45 +16,45 @@ var typeOptions = ['cpu', 'wait', 'block'];
|
||||
* @param {number} params.threads - Specify the number of threads to provide information for (default: 3)
|
||||
* @param {String} params.type - The type to sample (default: cpu)
|
||||
*/
|
||||
function doClusterNodeHotThreads(params, callback) {
|
||||
function doClusterNodeHotThreads(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
parts.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/hotthreads';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/hotthreads';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes/hotthreads';
|
||||
request.path = '/_nodes/hotthreads';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.interval !== 'undefined') {
|
||||
@ -66,7 +66,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
throw new TypeError('Invalid interval: ' + params.interval + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.snapshots !== 'undefined') {
|
||||
if (_.isNumeric(params.snapshots)) {
|
||||
query.snapshots = params.snapshots * 1;
|
||||
@ -74,7 +74,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
throw new TypeError('Invalid snapshots: ' + params.snapshots + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.threads !== 'undefined') {
|
||||
if (_.isNumeric(params.threads)) {
|
||||
query.threads = params.threads * 1;
|
||||
@ -82,7 +82,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
throw new TypeError('Invalid threads: ' + params.threads + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (_.contains(typeOptions, params.type)) {
|
||||
query.type = params.type;
|
||||
@ -93,14 +93,10 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeHotThreads;
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
//TODO: this enpoint ***needs*** work, many of the possible urls are not supported
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request
|
||||
@ -23,45 +22,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeInfo(params, callback) {
|
||||
function doClusterNodeInfo(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
parts.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes';
|
||||
request.path = '/_nodes';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -73,7 +72,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -83,7 +82,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
@ -93,7 +92,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
@ -103,7 +102,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
@ -113,7 +112,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
@ -123,7 +122,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.plugin !== 'undefined') {
|
||||
if (params.plugin.toLowerCase && (params.plugin = params.plugin.toLowerCase())
|
||||
&& (params.plugin === 'no' || params.plugin === 'off')
|
||||
@ -133,7 +132,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.plugin = !!params.plugin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
@ -143,7 +142,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.process = !!params.process;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.settings !== 'undefined') {
|
||||
if (params.settings.toLowerCase && (params.settings = params.settings.toLowerCase())
|
||||
&& (params.settings === 'no' || params.settings === 'off')
|
||||
@ -153,7 +152,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.settings = !!params.settings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.thread_pool !== 'undefined') {
|
||||
if (params.thread_pool.toLowerCase && (params.thread_pool = params.thread_pool.toLowerCase())
|
||||
&& (params.thread_pool === 'no' || params.thread_pool === 'off')
|
||||
@ -163,7 +162,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.thread_pool = !!params.thread_pool;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -173,7 +172,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.transport !== 'undefined') {
|
||||
if (params.transport.toLowerCase && (params.transport = params.transport.toLowerCase())
|
||||
&& (params.transport === 'no' || params.transport === 'off')
|
||||
@ -183,14 +182,10 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeInfo;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
|
||||
@ -12,45 +12,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.delay - Set the delay for the operation (default: 1s)
|
||||
* @param {boolean} params.exit - Exit the JVM as well (default: true)
|
||||
*/
|
||||
function doClusterNodeShutdown(params, callback) {
|
||||
function doClusterNodeShutdown(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
parts.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_cluster/nodes/' + encodeURIComponent(url.node_id) + '/_shutdown';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_cluster/nodes/' + encodeURIComponent(parts.node_id) + '/_shutdown';
|
||||
}
|
||||
else {
|
||||
request.url = '/_shutdown';
|
||||
request.path = '/_shutdown';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.delay !== 'undefined') {
|
||||
@ -62,7 +62,7 @@ function doClusterNodeShutdown(params, callback) {
|
||||
throw new TypeError('Invalid delay: ' + params.delay + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.exit !== 'undefined') {
|
||||
if (params.exit.toLowerCase && (params.exit = params.exit.toLowerCase())
|
||||
&& (params.exit === 'no' || params.exit === 'off')
|
||||
@ -72,14 +72,10 @@ function doClusterNodeShutdown(params, callback) {
|
||||
query.exit = !!params.exit;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeShutdown;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var metricFamilyOptions = ['all', 'fs', 'http', 'indices', 'jvm', 'network', 'os', 'process', 'thread_pool', 'transport'];
|
||||
var metricOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'id_cache', 'indexing', 'merges', 'refresh', 'search', 'store', 'warmer'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_stats](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/) request
|
||||
*
|
||||
@ -25,39 +25,39 @@ var metricOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush',
|
||||
* @param {boolean} params.thread_pool - Return information about the thread pool
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeStats(params, callback) {
|
||||
function doClusterNodeStats(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
url.metric_family = params.metric_family;
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
@ -65,10 +65,10 @@ function doClusterNodeStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric !== 'undefined') {
|
||||
if (_.contains(metricOptions, params.metric)) {
|
||||
url.metric = params.metric;
|
||||
parts.metric = params.metric;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric: ' + params.metric +
|
||||
@ -76,33 +76,33 @@ function doClusterNodeStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
parts.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/stats';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/stats';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes/stats';
|
||||
request.path = '/_nodes/stats';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -114,7 +114,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -124,7 +124,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -141,7 +141,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fs !== 'undefined') {
|
||||
if (params.fs.toLowerCase && (params.fs = params.fs.toLowerCase())
|
||||
&& (params.fs === 'no' || params.fs === 'off')
|
||||
@ -151,7 +151,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.fs = !!params.fs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
@ -161,7 +161,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indices !== 'undefined') {
|
||||
if (params.indices.toLowerCase && (params.indices = params.indices.toLowerCase())
|
||||
&& (params.indices === 'no' || params.indices === 'off')
|
||||
@ -171,7 +171,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.indices = !!params.indices;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
@ -181,7 +181,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
@ -191,7 +191,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
@ -201,7 +201,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
@ -211,7 +211,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.process = !!params.process;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.thread_pool !== 'undefined') {
|
||||
if (params.thread_pool.toLowerCase && (params.thread_pool = params.thread_pool.toLowerCase())
|
||||
&& (params.thread_pool === 'no' || params.thread_pool === 'off')
|
||||
@ -221,7 +221,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.thread_pool = !!params.thread_pool;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.transport !== 'undefined') {
|
||||
if (params.transport.toLowerCase && (params.transport = params.transport.toLowerCase())
|
||||
&& (params.transport === 'no' || params.transport === 'off')
|
||||
@ -231,14 +231,10 @@ function doClusterNodeStats(params, callback) {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeStats;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.put_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
@ -10,35 +10,31 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method cluster.put_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterPutSettings(params, callback) {
|
||||
function doClusterPutSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterPutSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.reroute](http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/) request
|
||||
@ -12,25 +12,25 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {boolean} params.dry_run - Simulate the operation only and return the resulting state
|
||||
* @param {boolean} params.filter_metadata - Don't return cluster state metadata (default: false)
|
||||
*/
|
||||
function doClusterReroute(params, callback) {
|
||||
function doClusterReroute(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/reroute';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/reroute';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.dry_run !== 'undefined') {
|
||||
@ -42,7 +42,7 @@ function doClusterReroute(params, callback) {
|
||||
query.dry_run = !!params.dry_run;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_metadata !== 'undefined') {
|
||||
if (params.filter_metadata.toLowerCase && (params.filter_metadata = params.filter_metadata.toLowerCase())
|
||||
&& (params.filter_metadata === 'no' || params.filter_metadata === 'off')
|
||||
@ -52,14 +52,10 @@ function doClusterReroute(params, callback) {
|
||||
query.filter_metadata = !!params.filter_metadata;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterReroute;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.state](http://elasticsearch.org/guide/reference/api/admin-cluster-state/) request
|
||||
@ -18,24 +18,24 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doClusterState(params, callback) {
|
||||
function doClusterState(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/state';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/state';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.filter_blocks !== 'undefined') {
|
||||
@ -47,7 +47,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_blocks = !!params.filter_blocks;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_index_templates !== 'undefined') {
|
||||
if (params.filter_index_templates.toLowerCase && (params.filter_index_templates = params.filter_index_templates.toLowerCase())
|
||||
&& (params.filter_index_templates === 'no' || params.filter_index_templates === 'off')
|
||||
@ -57,7 +57,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_index_templates = !!params.filter_index_templates;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_indices !== 'undefined') {
|
||||
switch (typeof params.filter_indices) {
|
||||
case 'string':
|
||||
@ -74,7 +74,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_indices = !!params.filter_indices;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_metadata !== 'undefined') {
|
||||
if (params.filter_metadata.toLowerCase && (params.filter_metadata = params.filter_metadata.toLowerCase())
|
||||
&& (params.filter_metadata === 'no' || params.filter_metadata === 'off')
|
||||
@ -84,7 +84,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_metadata = !!params.filter_metadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_nodes !== 'undefined') {
|
||||
if (params.filter_nodes.toLowerCase && (params.filter_nodes = params.filter_nodes.toLowerCase())
|
||||
&& (params.filter_nodes === 'no' || params.filter_nodes === 'off')
|
||||
@ -94,7 +94,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_nodes = !!params.filter_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_routing_table !== 'undefined') {
|
||||
if (params.filter_routing_table.toLowerCase && (params.filter_routing_table = params.filter_routing_table.toLowerCase())
|
||||
&& (params.filter_routing_table === 'no' || params.filter_routing_table === 'off')
|
||||
@ -104,7 +104,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_routing_table = !!params.filter_routing_table;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.local !== 'undefined') {
|
||||
if (params.local.toLowerCase && (params.local = params.local.toLowerCase())
|
||||
&& (params.local === 'no' || params.local === 'off')
|
||||
@ -114,7 +114,7 @@ function doClusterState(params, callback) {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -124,14 +124,10 @@ function doClusterState(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterState;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [count](http://elasticsearch.org/guide/reference/api/count/) request
|
||||
*
|
||||
@ -17,74 +17,74 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
*/
|
||||
function doCount(params, callback) {
|
||||
function doCount(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_count';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_count';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_count';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_count';
|
||||
}
|
||||
else {
|
||||
request.url = '/_count';
|
||||
request.path = '/_count';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -97,7 +97,7 @@ function doCount(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.min_score !== 'undefined') {
|
||||
if (_.isNumeric(params.min_score)) {
|
||||
query.min_score = params.min_score * 1;
|
||||
@ -105,7 +105,7 @@ function doCount(params, callback) {
|
||||
throw new TypeError('Invalid min_score: ' + params.min_score + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -113,7 +113,7 @@ function doCount(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -121,7 +121,7 @@ function doCount(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -129,14 +129,10 @@ function doCount(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCount;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
var versionTypeOptions = ['internal', 'external'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [create](http://elasticsearch.org/guide/reference/api/index_/) request
|
||||
*
|
||||
@ -26,61 +26,61 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doCreate(params, callback) {
|
||||
function doCreate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_create';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_create';
|
||||
delete params.id;
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -93,7 +93,7 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
query.id = '' + params.id;
|
||||
@ -101,7 +101,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -109,7 +109,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && params.percolate) {
|
||||
query.percolate = '' + params.percolate;
|
||||
@ -117,7 +117,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -127,7 +127,7 @@ function doCreate(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -138,7 +138,7 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -146,7 +146,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -156,7 +156,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timestamp !== 'undefined') {
|
||||
if (params.timestamp instanceof Date) {
|
||||
query.timestamp = params.timestamp.getTime();
|
||||
@ -166,7 +166,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
@ -174,7 +174,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version !== 'undefined') {
|
||||
if (_.isNumeric(params.version)) {
|
||||
query.version = params.version * 1;
|
||||
@ -182,7 +182,7 @@ function doCreate(params, callback) {
|
||||
throw new TypeError('Invalid version: ' + params.version + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version_type !== 'undefined') {
|
||||
if (_.contains(versionTypeOptions, params.version_type)) {
|
||||
query.version_type = params.version_type;
|
||||
@ -193,14 +193,10 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCreate;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
var versionTypeOptions = ['internal', 'external'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [delete](http://elasticsearch.org/guide/reference/api/delete/) request
|
||||
*
|
||||
@ -22,46 +22,46 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doDelete(params, callback) {
|
||||
function doDelete(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -74,7 +74,7 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -82,7 +82,7 @@ function doDelete(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -92,7 +92,7 @@ function doDelete(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -103,7 +103,7 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -111,7 +111,7 @@ function doDelete(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -121,7 +121,7 @@ function doDelete(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version !== 'undefined') {
|
||||
if (_.isNumeric(params.version)) {
|
||||
query.version = params.version * 1;
|
||||
@ -129,7 +129,7 @@ function doDelete(params, callback) {
|
||||
throw new TypeError('Invalid version: ' + params.version + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version_type !== 'undefined') {
|
||||
if (_.contains(versionTypeOptions, params.version_type)) {
|
||||
query.version_type = params.version_type;
|
||||
@ -140,14 +140,10 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDelete;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [delete_by_query](http://www.elasticsearch.org/guide/reference/api/delete-by-query/) request
|
||||
*
|
||||
@ -25,64 +25,64 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doDeleteByQuery(params, callback) {
|
||||
function doDeleteByQuery(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_query';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_query';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_query';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
@ -92,7 +92,7 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
@ -103,7 +103,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
@ -114,7 +114,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -122,7 +122,7 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid df: ' + params.df + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -133,7 +133,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -144,7 +144,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
@ -152,7 +152,7 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -160,7 +160,7 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -168,7 +168,7 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -178,14 +178,10 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDeleteByQuery;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [exists](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -15,48 +15,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doExists(params, callback) {
|
||||
function doExists(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
@ -66,7 +66,7 @@ function doExists(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -74,7 +74,7 @@ function doExists(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.realtime !== 'undefined') {
|
||||
if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase())
|
||||
&& (params.realtime === 'no' || params.realtime === 'off')
|
||||
@ -84,7 +84,7 @@ function doExists(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -94,7 +94,7 @@ function doExists(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -102,14 +102,16 @@ function doExists(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(err, false);
|
||||
} else {
|
||||
cb(err, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = doExists;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [explain](http://elasticsearch.org/guide/reference/api/explain/) request
|
||||
*
|
||||
@ -27,55 +27,55 @@ var defaultOperatorOptions = ['AND', 'OR'];
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field
|
||||
*/
|
||||
function doExplain(params, callback) {
|
||||
function doExplain(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_explain';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_explain';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyze_wildcard !== 'undefined') {
|
||||
@ -87,7 +87,7 @@ function doExplain(params, callback) {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
@ -95,7 +95,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
@ -106,7 +106,7 @@ function doExplain(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -114,7 +114,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid df: ' + params.df + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -131,7 +131,7 @@ function doExplain(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lenient !== 'undefined') {
|
||||
if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase())
|
||||
&& (params.lenient === 'no' || params.lenient === 'off')
|
||||
@ -141,7 +141,7 @@ function doExplain(params, callback) {
|
||||
query.lenient = !!params.lenient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lowercase_expanded_terms !== 'undefined') {
|
||||
if (params.lowercase_expanded_terms.toLowerCase && (params.lowercase_expanded_terms = params.lowercase_expanded_terms.toLowerCase())
|
||||
&& (params.lowercase_expanded_terms === 'no' || params.lowercase_expanded_terms === 'off')
|
||||
@ -151,7 +151,7 @@ function doExplain(params, callback) {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -159,7 +159,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -167,7 +167,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
@ -175,7 +175,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -183,7 +183,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -191,7 +191,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -208,7 +208,7 @@ function doExplain(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -225,7 +225,7 @@ function doExplain(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -242,14 +242,10 @@ function doExplain(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doExplain;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -19,48 +19,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field
|
||||
*/
|
||||
function doGet(params, callback) {
|
||||
function doGet(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
@ -79,7 +79,7 @@ function doGet(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -87,7 +87,7 @@ function doGet(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -95,7 +95,7 @@ function doGet(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.realtime !== 'undefined') {
|
||||
if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase())
|
||||
&& (params.realtime === 'no' || params.realtime === 'off')
|
||||
@ -105,7 +105,7 @@ function doGet(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -115,7 +115,7 @@ function doGet(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -123,7 +123,7 @@ function doGet(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -140,7 +140,7 @@ function doGet(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -157,7 +157,7 @@ function doGet(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -174,14 +174,10 @@ function doGet(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGet;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get_source](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -17,48 +17,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doGetSource(params, callback) {
|
||||
function doGetSource(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '/_source';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + '/_source';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
@ -77,7 +77,7 @@ function doGetSource(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -94,7 +94,7 @@ function doGetSource(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -102,7 +102,7 @@ function doGetSource(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -110,7 +110,7 @@ function doGetSource(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.realtime !== 'undefined') {
|
||||
if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase())
|
||||
&& (params.realtime === 'no' || params.realtime === 'off')
|
||||
@ -120,7 +120,7 @@ function doGetSource(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -130,7 +130,7 @@ function doGetSource(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -138,14 +138,10 @@ function doGetSource(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGetSource;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var opTypeOptions = ['index', 'create'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
var versionTypeOptions = ['internal', 'external'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [index](http://elasticsearch.org/guide/reference/api/index_/) request
|
||||
*
|
||||
@ -27,60 +27,60 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doIndex(params, callback) {
|
||||
function doIndex(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -93,7 +93,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.op_type !== 'undefined') {
|
||||
if (_.contains(opTypeOptions, params.op_type)) {
|
||||
query.op_type = params.op_type;
|
||||
@ -104,7 +104,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -112,7 +112,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && params.percolate) {
|
||||
query.percolate = '' + params.percolate;
|
||||
@ -120,7 +120,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -130,7 +130,7 @@ function doIndex(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -141,7 +141,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -149,7 +149,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -159,7 +159,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timestamp !== 'undefined') {
|
||||
if (params.timestamp instanceof Date) {
|
||||
query.timestamp = params.timestamp.getTime();
|
||||
@ -169,7 +169,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
@ -177,7 +177,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version !== 'undefined') {
|
||||
if (_.isNumeric(params.version)) {
|
||||
query.version = params.version * 1;
|
||||
@ -185,7 +185,7 @@ function doIndex(params, callback) {
|
||||
throw new TypeError('Invalid version: ' + params.version + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version_type !== 'undefined') {
|
||||
if (_.contains(versionTypeOptions, params.version_type)) {
|
||||
query.version_type = params.version_type;
|
||||
@ -196,14 +196,10 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndex;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var formatOptions = ['detailed', 'text'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.analyze](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/) request
|
||||
*
|
||||
@ -20,46 +20,46 @@ var formatOptions = ['detailed', 'text'];
|
||||
* @param {string} params.tokenizer - The name of the tokenizer to use for the analysis
|
||||
* @param {String} [params.format=detailed] - Format of the output
|
||||
*/
|
||||
function doIndicesAnalyze(params, callback) {
|
||||
function doIndicesAnalyze(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_analyze';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_analyze';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.url = '/_analyze';
|
||||
request.path = '/_analyze';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
@ -69,7 +69,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.field !== 'undefined') {
|
||||
if (typeof params.field !== 'object' && params.field) {
|
||||
query.field = '' + params.field;
|
||||
@ -77,7 +77,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid field: ' + params.field + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filters !== 'undefined') {
|
||||
switch (typeof params.filters) {
|
||||
case 'string':
|
||||
@ -94,7 +94,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
query.filters = !!params.filters;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
query.index = '' + params.index;
|
||||
@ -102,7 +102,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.prefer_local !== 'undefined') {
|
||||
if (params.prefer_local.toLowerCase && (params.prefer_local = params.prefer_local.toLowerCase())
|
||||
&& (params.prefer_local === 'no' || params.prefer_local === 'off')
|
||||
@ -112,7 +112,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.text !== 'undefined') {
|
||||
if (typeof params.text !== 'object' && params.text) {
|
||||
query.text = '' + params.text;
|
||||
@ -120,7 +120,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid text: ' + params.text + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.tokenizer !== 'undefined') {
|
||||
if (typeof params.tokenizer !== 'object' && params.tokenizer) {
|
||||
query.tokenizer = '' + params.tokenizer;
|
||||
@ -128,7 +128,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid tokenizer: ' + params.tokenizer + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.format !== 'undefined') {
|
||||
if (_.contains(formatOptions, params.format)) {
|
||||
query.format = params.format;
|
||||
@ -139,14 +139,10 @@ function doIndicesAnalyze(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesAnalyze;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.clear_cache](http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/) request
|
||||
*
|
||||
@ -23,54 +23,54 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String|ArrayOfStrings|Boolean} params.index - A comma-separated list of index name to limit the operation
|
||||
* @param {boolean} params.recycler - Clear the recycler cache
|
||||
*/
|
||||
function doIndicesClearCache(params, callback) {
|
||||
function doIndicesClearCache(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_cache/clear';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_cache/clear';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.url = '/_cache/clear';
|
||||
request.path = '/_cache/clear';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.field_data !== 'undefined') {
|
||||
@ -82,7 +82,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.field_data = !!params.field_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fielddata !== 'undefined') {
|
||||
if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase())
|
||||
&& (params.fielddata === 'no' || params.fielddata === 'off')
|
||||
@ -92,7 +92,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -109,7 +109,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter !== 'undefined') {
|
||||
if (params.filter.toLowerCase && (params.filter = params.filter.toLowerCase())
|
||||
&& (params.filter === 'no' || params.filter === 'off')
|
||||
@ -119,7 +119,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.filter = !!params.filter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_cache !== 'undefined') {
|
||||
if (params.filter_cache.toLowerCase && (params.filter_cache = params.filter_cache.toLowerCase())
|
||||
&& (params.filter_cache === 'no' || params.filter_cache === 'off')
|
||||
@ -129,7 +129,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.filter_cache = !!params.filter_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_keys !== 'undefined') {
|
||||
if (params.filter_keys.toLowerCase && (params.filter_keys = params.filter_keys.toLowerCase())
|
||||
&& (params.filter_keys === 'no' || params.filter_keys === 'off')
|
||||
@ -139,7 +139,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.filter_keys = !!params.filter_keys;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (params.id.toLowerCase && (params.id = params.id.toLowerCase())
|
||||
&& (params.id === 'no' || params.id === 'off')
|
||||
@ -149,7 +149,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.id = !!params.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.id_cache !== 'undefined') {
|
||||
if (params.id_cache.toLowerCase && (params.id_cache = params.id_cache.toLowerCase())
|
||||
&& (params.id_cache === 'no' || params.id_cache === 'off')
|
||||
@ -159,7 +159,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -170,7 +170,7 @@ function doIndicesClearCache(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
@ -187,7 +187,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.recycler !== 'undefined') {
|
||||
if (params.recycler.toLowerCase && (params.recycler = params.recycler.toLowerCase())
|
||||
&& (params.recycler === 'no' || params.recycler === 'off')
|
||||
@ -197,14 +197,10 @@ function doIndicesClearCache(params, callback) {
|
||||
query.recycler = !!params.recycler;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClearCache;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesClose(params, callback) {
|
||||
function doIndicesClose(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_close';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_close';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -51,7 +51,7 @@ function doIndicesClose(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -61,14 +61,10 @@ function doIndicesClose(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClose;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request
|
||||
@ -12,43 +12,43 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesCreate(params, callback) {
|
||||
function doIndicesCreate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -60,7 +60,7 @@ function doIndicesCreate(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -70,14 +70,10 @@ function doIndicesCreate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesCreate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request
|
||||
@ -12,45 +12,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDelete(params, callback) {
|
||||
function doIndicesDelete(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/';
|
||||
request.path = '/';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -62,7 +62,7 @@ function doIndicesDelete(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -72,14 +72,10 @@ function doIndicesDelete(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDelete;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,40 +12,40 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit timestamp for the document
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteAlias(params, callback) {
|
||||
function doIndicesDeleteAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -57,7 +57,7 @@ function doIndicesDeleteAlias(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -67,14 +67,10 @@ function doIndicesDeleteAlias(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/) request
|
||||
@ -11,49 +11,49 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteMapping(params, callback) {
|
||||
function doIndicesDeleteMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
@ -65,14 +65,10 @@ function doIndicesDeleteMapping(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteTemplate(params, callback) {
|
||||
function doIndicesDeleteTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -51,7 +51,7 @@ function doIndicesDeleteTemplate(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -61,14 +61,10 @@ function doIndicesDeleteTemplate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -11,74 +11,74 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteWarmer(params, callback) {
|
||||
function doIndicesDeleteWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
@ -90,14 +90,10 @@ function doIndicesDeleteWarmer(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteWarmer;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request
|
||||
@ -10,53 +10,55 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.exists
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesExists(params, callback) {
|
||||
function doIndicesExists(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(err, false);
|
||||
} else {
|
||||
cb(err, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = doIndicesExists;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.exists_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
@ -13,63 +13,63 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
*/
|
||||
function doIndicesExistsAlias(params, callback) {
|
||||
function doIndicesExistsAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -82,14 +82,16 @@ function doIndicesExistsAlias(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(err, false);
|
||||
} else {
|
||||
cb(err, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsAlias;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.exists_type](http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/) request
|
||||
*
|
||||
@ -13,58 +13,58 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
*/
|
||||
function doIndicesExistsType(params, callback) {
|
||||
function doIndicesExistsType(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -77,14 +77,16 @@ function doIndicesExistsType(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(err, false);
|
||||
} else {
|
||||
cb(err, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsType;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.flush](http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/) request
|
||||
*
|
||||
@ -16,53 +16,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
*/
|
||||
function doIndicesFlush(params, callback) {
|
||||
function doIndicesFlush(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_flush';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_flush';
|
||||
}
|
||||
else {
|
||||
request.url = '/_flush';
|
||||
request.path = '/_flush';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.force !== 'undefined') {
|
||||
@ -74,7 +74,7 @@ function doIndicesFlush(params, callback) {
|
||||
query.force = !!params.force;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.full !== 'undefined') {
|
||||
if (params.full.toLowerCase && (params.full = params.full.toLowerCase())
|
||||
&& (params.full === 'no' || params.full === 'off')
|
||||
@ -84,7 +84,7 @@ function doIndicesFlush(params, callback) {
|
||||
query.full = !!params.full;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -95,7 +95,7 @@ function doIndicesFlush(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -105,14 +105,10 @@ function doIndicesFlush(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesFlush;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
@ -13,63 +13,63 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
*/
|
||||
function doIndicesGetAlias(params, callback) {
|
||||
function doIndicesGetAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -82,14 +82,10 @@ function doIndicesGetAlias(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -11,45 +11,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doIndicesGetAliases(params, callback) {
|
||||
function doIndicesGetAliases(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_aliases';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_aliases';
|
||||
}
|
||||
else {
|
||||
request.url = '/_aliases';
|
||||
request.path = '/_aliases';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -61,14 +61,10 @@ function doIndicesGetAliases(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAliases;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/) request
|
||||
@ -10,75 +10,71 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_mapping
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetMapping(params, callback) {
|
||||
function doIndicesGetMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mapping';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mapping';
|
||||
request.path = '/_mapping';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/) request
|
||||
@ -10,55 +10,51 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetSettings(params, callback) {
|
||||
function doIndicesGetSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -10,44 +10,40 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_template
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetTemplate(params, callback) {
|
||||
function doIndicesGetTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -10,84 +10,80 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_warmer
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetWarmer(params, callback) {
|
||||
function doIndicesGetWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetWarmer;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesOpen(params, callback) {
|
||||
function doIndicesOpen(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_open';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_open';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -51,7 +51,7 @@ function doIndicesOpen(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -61,14 +61,10 @@ function doIndicesOpen(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOpen;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.optimize](http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/) request
|
||||
*
|
||||
@ -19,53 +19,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {boolean} params.refresh - Specify whether the index should be refreshed after performing the operation (default: true)
|
||||
* @param {boolean} params.wait_for_merge - Specify whether the request should block until the merge process is finished (default: true)
|
||||
*/
|
||||
function doIndicesOptimize(params, callback) {
|
||||
function doIndicesOptimize(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_optimize';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_optimize';
|
||||
}
|
||||
else {
|
||||
request.url = '/_optimize';
|
||||
request.path = '/_optimize';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.flush !== 'undefined') {
|
||||
@ -77,7 +77,7 @@ function doIndicesOptimize(params, callback) {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -88,7 +88,7 @@ function doIndicesOptimize(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.max_num_segments !== 'undefined') {
|
||||
if (_.isNumeric(params.max_num_segments)) {
|
||||
query.max_num_segments = params.max_num_segments * 1;
|
||||
@ -96,7 +96,7 @@ function doIndicesOptimize(params, callback) {
|
||||
throw new TypeError('Invalid max_num_segments: ' + params.max_num_segments + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.only_expunge_deletes !== 'undefined') {
|
||||
if (params.only_expunge_deletes.toLowerCase && (params.only_expunge_deletes = params.only_expunge_deletes.toLowerCase())
|
||||
&& (params.only_expunge_deletes === 'no' || params.only_expunge_deletes === 'off')
|
||||
@ -106,11 +106,11 @@ function doIndicesOptimize(params, callback) {
|
||||
query.only_expunge_deletes = !!params.only_expunge_deletes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -120,7 +120,7 @@ function doIndicesOptimize(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.wait_for_merge !== 'undefined') {
|
||||
if (params.wait_for_merge.toLowerCase && (params.wait_for_merge = params.wait_for_merge.toLowerCase())
|
||||
&& (params.wait_for_merge === 'no' || params.wait_for_merge === 'off')
|
||||
@ -130,14 +130,10 @@ function doIndicesOptimize(params, callback) {
|
||||
query.wait_for_merge = !!params.wait_for_merge;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOptimize;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,47 +12,47 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit timestamp for the document
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutAlias(params, callback) {
|
||||
function doIndicesPutAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias';
|
||||
}
|
||||
else {
|
||||
request.url = '/_alias';
|
||||
request.path = '/_alias';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -64,7 +64,7 @@ function doIndicesPutAlias(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -74,14 +74,10 @@ function doIndicesPutAlias(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/) request
|
||||
@ -13,58 +13,58 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutMapping(params, callback) {
|
||||
function doIndicesPutMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_conflicts !== 'undefined') {
|
||||
@ -76,7 +76,7 @@ function doIndicesPutMapping(params, callback) {
|
||||
query.ignore_conflicts = !!params.ignore_conflicts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -86,7 +86,7 @@ function doIndicesPutMapping(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -96,14 +96,10 @@ function doIndicesPutMapping(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/) request
|
||||
@ -11,46 +11,46 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutSettings(params, callback) {
|
||||
function doIndicesPutSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
@ -62,14 +62,10 @@ function doIndicesPutSettings(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -13,43 +13,43 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutTemplate(params, callback) {
|
||||
function doIndicesPutTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.order !== 'undefined') {
|
||||
@ -59,7 +59,7 @@ function doIndicesPutTemplate(params, callback) {
|
||||
throw new TypeError('Invalid order: ' + params.order + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -69,7 +69,7 @@ function doIndicesPutTemplate(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -79,14 +79,10 @@ function doIndicesPutTemplate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -11,70 +11,70 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutWarmer(params, callback) {
|
||||
function doIndicesPutWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
@ -86,14 +86,10 @@ function doIndicesPutWarmer(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutWarmer;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.refresh](http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh/) request
|
||||
*
|
||||
@ -14,53 +14,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesRefresh(params, callback) {
|
||||
function doIndicesRefresh(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_refresh';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_refresh';
|
||||
}
|
||||
else {
|
||||
request.url = '/_refresh';
|
||||
request.path = '/_refresh';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -73,18 +73,14 @@ function doIndicesRefresh(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesRefresh;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.segments](http://elasticsearch.org/guide/reference/api/admin-indices-segments/) request
|
||||
*
|
||||
@ -14,45 +14,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesSegments(params, callback) {
|
||||
function doIndicesSegments(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_segments';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_segments';
|
||||
}
|
||||
else {
|
||||
request.url = '/_segments';
|
||||
request.path = '/_segments';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -65,18 +65,14 @@ function doIndicesSegments(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSegments;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.snapshot_index](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/) request
|
||||
*
|
||||
@ -13,45 +13,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
*/
|
||||
function doIndicesSnapshotIndex(params, callback) {
|
||||
function doIndicesSnapshotIndex(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_gateway/snapshot';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_gateway/snapshot';
|
||||
}
|
||||
else {
|
||||
request.url = '/_gateway/snapshot';
|
||||
request.path = '/_gateway/snapshot';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -64,14 +64,10 @@ function doIndicesSnapshotIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSnapshotIndex;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
var metricFamilyOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'groups', 'id_cache', 'ignore_indices', 'indexing', 'merge', 'refresh', 'search', 'store', 'warmer'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.stats](http://elasticsearch.org/guide/reference/api/admin-indices-stats/) request
|
||||
*
|
||||
@ -33,73 +33,73 @@ var metricFamilyOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'f
|
||||
* @param {boolean} params.store - Return information about the size of the index
|
||||
* @param {boolean} params.warmer - Return information about warmers
|
||||
*/
|
||||
function doIndicesStats(params, callback) {
|
||||
function doIndicesStats(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indexing_types !== 'undefined') {
|
||||
switch (typeof params.indexing_types) {
|
||||
case 'string':
|
||||
url.indexing_types = params.indexing_types;
|
||||
parts.indexing_types = params.indexing_types;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.indexing_types)) {
|
||||
url.indexing_types = params.indexing_types.join(',');
|
||||
parts.indexing_types = params.indexing_types.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid indexing_types: ' + params.indexing_types + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.indexing_types = !!params.indexing_types;
|
||||
parts.indexing_types = !!params.indexing_types;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
url.metric_family = params.metric_family;
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
@ -107,33 +107,33 @@ function doIndicesStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_groups !== 'undefined') {
|
||||
switch (typeof params.search_groups) {
|
||||
case 'string':
|
||||
url.search_groups = params.search_groups;
|
||||
parts.search_groups = params.search_groups;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_groups)) {
|
||||
url.search_groups = params.search_groups.join(',');
|
||||
parts.search_groups = params.search_groups.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid search_groups: ' + params.search_groups + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.search_groups = !!params.search_groups;
|
||||
parts.search_groups = !!params.search_groups;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_stats';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_stats';
|
||||
}
|
||||
else {
|
||||
request.url = '/_stats';
|
||||
request.path = '/_stats';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -145,7 +145,7 @@ function doIndicesStats(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -155,7 +155,7 @@ function doIndicesStats(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.completion !== 'undefined') {
|
||||
if (params.completion.toLowerCase && (params.completion = params.completion.toLowerCase())
|
||||
&& (params.completion === 'no' || params.completion === 'off')
|
||||
@ -165,7 +165,7 @@ function doIndicesStats(params, callback) {
|
||||
query.completion = !!params.completion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.completion_fields !== 'undefined') {
|
||||
switch (typeof params.completion_fields) {
|
||||
case 'string':
|
||||
@ -182,7 +182,7 @@ function doIndicesStats(params, callback) {
|
||||
query.completion_fields = !!params.completion_fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.docs !== 'undefined') {
|
||||
if (params.docs.toLowerCase && (params.docs = params.docs.toLowerCase())
|
||||
&& (params.docs === 'no' || params.docs === 'off')
|
||||
@ -192,7 +192,7 @@ function doIndicesStats(params, callback) {
|
||||
query.docs = !!params.docs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fielddata !== 'undefined') {
|
||||
if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase())
|
||||
&& (params.fielddata === 'no' || params.fielddata === 'off')
|
||||
@ -202,7 +202,7 @@ function doIndicesStats(params, callback) {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fielddata_fields !== 'undefined') {
|
||||
switch (typeof params.fielddata_fields) {
|
||||
case 'string':
|
||||
@ -219,7 +219,7 @@ function doIndicesStats(params, callback) {
|
||||
query.fielddata_fields = !!params.fielddata_fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -236,7 +236,7 @@ function doIndicesStats(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_cache !== 'undefined') {
|
||||
if (params.filter_cache.toLowerCase && (params.filter_cache = params.filter_cache.toLowerCase())
|
||||
&& (params.filter_cache === 'no' || params.filter_cache === 'off')
|
||||
@ -246,7 +246,7 @@ function doIndicesStats(params, callback) {
|
||||
query.filter_cache = !!params.filter_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.flush !== 'undefined') {
|
||||
if (params.flush.toLowerCase && (params.flush = params.flush.toLowerCase())
|
||||
&& (params.flush === 'no' || params.flush === 'off')
|
||||
@ -256,7 +256,7 @@ function doIndicesStats(params, callback) {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.get !== 'undefined') {
|
||||
if (params.get.toLowerCase && (params.get = params.get.toLowerCase())
|
||||
&& (params.get === 'no' || params.get === 'off')
|
||||
@ -266,7 +266,7 @@ function doIndicesStats(params, callback) {
|
||||
query.get = !!params.get;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.groups !== 'undefined') {
|
||||
if (params.groups.toLowerCase && (params.groups = params.groups.toLowerCase())
|
||||
&& (params.groups === 'no' || params.groups === 'off')
|
||||
@ -276,7 +276,7 @@ function doIndicesStats(params, callback) {
|
||||
query.groups = !!params.groups;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.id_cache !== 'undefined') {
|
||||
if (params.id_cache.toLowerCase && (params.id_cache = params.id_cache.toLowerCase())
|
||||
&& (params.id_cache === 'no' || params.id_cache === 'off')
|
||||
@ -286,7 +286,7 @@ function doIndicesStats(params, callback) {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -297,7 +297,7 @@ function doIndicesStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indexing !== 'undefined') {
|
||||
if (params.indexing.toLowerCase && (params.indexing = params.indexing.toLowerCase())
|
||||
&& (params.indexing === 'no' || params.indexing === 'off')
|
||||
@ -307,7 +307,7 @@ function doIndicesStats(params, callback) {
|
||||
query.indexing = !!params.indexing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.merge !== 'undefined') {
|
||||
if (params.merge.toLowerCase && (params.merge = params.merge.toLowerCase())
|
||||
&& (params.merge === 'no' || params.merge === 'off')
|
||||
@ -317,7 +317,7 @@ function doIndicesStats(params, callback) {
|
||||
query.merge = !!params.merge;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -327,7 +327,7 @@ function doIndicesStats(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search !== 'undefined') {
|
||||
if (params.search.toLowerCase && (params.search = params.search.toLowerCase())
|
||||
&& (params.search === 'no' || params.search === 'off')
|
||||
@ -337,7 +337,7 @@ function doIndicesStats(params, callback) {
|
||||
query.search = !!params.search;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.store !== 'undefined') {
|
||||
if (params.store.toLowerCase && (params.store = params.store.toLowerCase())
|
||||
&& (params.store === 'no' || params.store === 'off')
|
||||
@ -347,7 +347,7 @@ function doIndicesStats(params, callback) {
|
||||
query.store = !!params.store;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.warmer !== 'undefined') {
|
||||
if (params.warmer.toLowerCase && (params.warmer = params.warmer.toLowerCase())
|
||||
&& (params.warmer === 'no' || params.warmer === 'off')
|
||||
@ -357,14 +357,10 @@ function doIndicesStats(params, callback) {
|
||||
query.warmer = !!params.warmer;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStats;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.status](http://elasticsearch.org/guide/reference/api/admin-indices-status/) request
|
||||
*
|
||||
@ -16,45 +16,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {boolean} params.recovery - Return information about shard recovery
|
||||
* @param {boolean} params.snapshot - TODO: ?
|
||||
*/
|
||||
function doIndicesStatus(params, callback) {
|
||||
function doIndicesStatus(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_status';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_status';
|
||||
}
|
||||
else {
|
||||
request.url = '/_status';
|
||||
request.path = '/_status';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -67,11 +67,11 @@ function doIndicesStatus(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.recovery !== 'undefined') {
|
||||
if (params.recovery.toLowerCase && (params.recovery = params.recovery.toLowerCase())
|
||||
&& (params.recovery === 'no' || params.recovery === 'off')
|
||||
@ -81,7 +81,7 @@ function doIndicesStatus(params, callback) {
|
||||
query.recovery = !!params.recovery;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.snapshot !== 'undefined') {
|
||||
if (params.snapshot.toLowerCase && (params.snapshot = params.snapshot.toLowerCase())
|
||||
&& (params.snapshot === 'no' || params.snapshot === 'off')
|
||||
@ -91,14 +91,10 @@ function doIndicesStatus(params, callback) {
|
||||
query.snapshot = !!params.snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStatus;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,41 +12,41 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Request timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesUpdateAliases(params, callback) {
|
||||
function doIndicesUpdateAliases(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_aliases';
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_aliases';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -58,7 +58,7 @@ function doIndicesUpdateAliases(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -68,14 +68,10 @@ function doIndicesUpdateAliases(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesUpdateAliases;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.validate_query](http://www.elasticsearch.org/guide/reference/api/validate/) request
|
||||
*
|
||||
@ -17,74 +17,74 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
* @param {string} params.q - Query in the Lucene query string syntax
|
||||
*/
|
||||
function doIndicesValidateQuery(params, callback) {
|
||||
function doIndicesValidateQuery(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_validate/query';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_validate/query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_validate/query';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_validate/query';
|
||||
}
|
||||
else {
|
||||
request.url = '/_validate/query';
|
||||
request.path = '/_validate/query';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.explain !== 'undefined') {
|
||||
@ -96,7 +96,7 @@ function doIndicesValidateQuery(params, callback) {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -107,11 +107,11 @@ function doIndicesValidateQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -119,7 +119,7 @@ function doIndicesValidateQuery(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
@ -127,14 +127,10 @@ function doIndicesValidateQuery(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesValidateQuery;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [info](http://elasticsearch.org/guide/) request
|
||||
@ -10,42 +10,38 @@ var _ = require('../lib/toolbelt')
|
||||
* @method info
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doInfo(params, callback) {
|
||||
function doInfo(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'head') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'HEAD') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, head');
|
||||
throw new TypeError('Invalid method: should be one of GET, HEAD');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'head' : 'get';
|
||||
request.method = params.body ? 'HEAD' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/';
|
||||
|
||||
// build the path
|
||||
request.path = '/';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doInfo;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request
|
||||
@ -17,56 +17,56 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field
|
||||
*/
|
||||
function doMget(params, callback) {
|
||||
function doMget(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mget';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mget';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mget';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mget';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mget';
|
||||
request.path = '/_mget';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
@ -85,7 +85,7 @@ function doMget(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -93,7 +93,7 @@ function doMget(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.realtime !== 'undefined') {
|
||||
if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase())
|
||||
&& (params.realtime === 'no' || params.realtime === 'off')
|
||||
@ -103,7 +103,7 @@ function doMget(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -113,7 +113,7 @@ function doMget(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -130,7 +130,7 @@ function doMget(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -147,7 +147,7 @@ function doMget(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -164,14 +164,10 @@ function doMget(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMget;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mlt](http://elasticsearch.org/guide/reference/api/more-like-this/) request
|
||||
@ -29,55 +29,55 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {String|ArrayOfStrings|Boolean} params.search_types - A comma-separated list of types to perform the query against (default: the same type as the document)
|
||||
* @param {String|ArrayOfStrings|Boolean} params.stop_words - A list of stop words to be ignored
|
||||
*/
|
||||
function doMlt(params, callback) {
|
||||
function doMlt(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_mlt';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_mlt';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.boost_terms !== 'undefined') {
|
||||
@ -87,7 +87,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid boost_terms: ' + params.boost_terms + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.max_doc_freq !== 'undefined') {
|
||||
if (_.isNumeric(params.max_doc_freq)) {
|
||||
query.max_doc_freq = params.max_doc_freq * 1;
|
||||
@ -95,7 +95,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid max_doc_freq: ' + params.max_doc_freq + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.max_query_terms !== 'undefined') {
|
||||
if (_.isNumeric(params.max_query_terms)) {
|
||||
query.max_query_terms = params.max_query_terms * 1;
|
||||
@ -103,7 +103,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid max_query_terms: ' + params.max_query_terms + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.max_word_len !== 'undefined') {
|
||||
if (_.isNumeric(params.max_word_len)) {
|
||||
query.max_word_len = params.max_word_len * 1;
|
||||
@ -111,7 +111,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid max_word_len: ' + params.max_word_len + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.min_doc_freq !== 'undefined') {
|
||||
if (_.isNumeric(params.min_doc_freq)) {
|
||||
query.min_doc_freq = params.min_doc_freq * 1;
|
||||
@ -119,7 +119,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid min_doc_freq: ' + params.min_doc_freq + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.min_term_freq !== 'undefined') {
|
||||
if (_.isNumeric(params.min_term_freq)) {
|
||||
query.min_term_freq = params.min_term_freq * 1;
|
||||
@ -127,7 +127,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid min_term_freq: ' + params.min_term_freq + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.min_word_len !== 'undefined') {
|
||||
if (_.isNumeric(params.min_word_len)) {
|
||||
query.min_word_len = params.min_word_len * 1;
|
||||
@ -135,7 +135,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid min_word_len: ' + params.min_word_len + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.mlt_fields !== 'undefined') {
|
||||
switch (typeof params.mlt_fields) {
|
||||
case 'string':
|
||||
@ -152,7 +152,7 @@ function doMlt(params, callback) {
|
||||
query.mlt_fields = !!params.mlt_fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.percent_terms_to_match !== 'undefined') {
|
||||
if (_.isNumeric(params.percent_terms_to_match)) {
|
||||
query.percent_terms_to_match = params.percent_terms_to_match * 1;
|
||||
@ -160,7 +160,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid percent_terms_to_match: ' + params.percent_terms_to_match + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -168,7 +168,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_from !== 'undefined') {
|
||||
if (_.isNumeric(params.search_from)) {
|
||||
query.search_from = params.search_from * 1;
|
||||
@ -176,7 +176,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_from: ' + params.search_from + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_indices !== 'undefined') {
|
||||
switch (typeof params.search_indices) {
|
||||
case 'string':
|
||||
@ -193,7 +193,7 @@ function doMlt(params, callback) {
|
||||
query.search_indices = !!params.search_indices;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_query_hint !== 'undefined') {
|
||||
if (typeof params.search_query_hint !== 'object' && params.search_query_hint) {
|
||||
query.search_query_hint = '' + params.search_query_hint;
|
||||
@ -201,7 +201,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_query_hint: ' + params.search_query_hint + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_scroll !== 'undefined') {
|
||||
if (typeof params.search_scroll !== 'object' && params.search_scroll) {
|
||||
query.search_scroll = '' + params.search_scroll;
|
||||
@ -209,7 +209,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_scroll: ' + params.search_scroll + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_size !== 'undefined') {
|
||||
if (_.isNumeric(params.search_size)) {
|
||||
query.search_size = params.search_size * 1;
|
||||
@ -217,7 +217,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_size: ' + params.search_size + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_source !== 'undefined') {
|
||||
if (typeof params.search_source !== 'object' && params.search_source) {
|
||||
query.search_source = '' + params.search_source;
|
||||
@ -225,7 +225,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_source: ' + params.search_source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
if (typeof params.search_type !== 'object' && params.search_type) {
|
||||
query.search_type = '' + params.search_type;
|
||||
@ -233,7 +233,7 @@ function doMlt(params, callback) {
|
||||
throw new TypeError('Invalid search_type: ' + params.search_type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_types !== 'undefined') {
|
||||
switch (typeof params.search_types) {
|
||||
case 'string':
|
||||
@ -250,7 +250,7 @@ function doMlt(params, callback) {
|
||||
query.search_types = !!params.search_types;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.stop_words !== 'undefined') {
|
||||
switch (typeof params.stop_words) {
|
||||
case 'string':
|
||||
@ -267,14 +267,10 @@ function doMlt(params, callback) {
|
||||
query.stop_words = !!params.stop_words;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMlt;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', 'dfs_query_and_fetch', 'count', 'scan'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [msearch](http://www.elasticsearch.org/guide/reference/api/multi-search/) request
|
||||
*
|
||||
@ -13,74 +13,74 @@ var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.search_type - Search operation type
|
||||
*/
|
||||
function doMsearch(params, callback) {
|
||||
function doMsearch(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_msearch';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_msearch';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_msearch';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_msearch';
|
||||
}
|
||||
else {
|
||||
request.url = '/_msearch';
|
||||
request.path = '/_msearch';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
@ -93,14 +93,10 @@ function doMsearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMsearch;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [percolate](http://elasticsearch.org/guide/reference/api/percolate/) request
|
||||
@ -11,49 +11,49 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.prefer_local - With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)
|
||||
*/
|
||||
function doPercolate(params, callback) {
|
||||
function doPercolate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_percolate';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_percolate';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.prefer_local !== 'undefined') {
|
||||
@ -65,14 +65,10 @@ function doPercolate(params, callback) {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doPercolate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
@ -12,46 +12,46 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search
|
||||
* @param {string} params.scroll_id - The scroll ID for scrolled search
|
||||
*/
|
||||
function doScroll(params, callback) {
|
||||
function doScroll(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && params.scroll_id) {
|
||||
url.scroll_id = '' + params.scroll_id;
|
||||
parts.scroll_id = '' + params.scroll_id;
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.scroll_id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('scroll_id')) {
|
||||
request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + '';
|
||||
delete params.scroll_id;
|
||||
}
|
||||
else {
|
||||
request.url = '/_search/scroll';
|
||||
request.path = '/_search/scroll';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
@ -61,7 +61,7 @@ function doScroll(params, callback) {
|
||||
throw new TypeError('Invalid scroll: ' + params.scroll + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && params.scroll_id) {
|
||||
query.scroll_id = '' + params.scroll_id;
|
||||
@ -69,14 +69,10 @@ function doScroll(params, callback) {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doScroll;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', 'dfs_query_and_fetch', 'count', 'scan'];
|
||||
var suggestModeOptions = ['missing', 'popular', 'always'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [search](http://www.elasticsearch.org/guide/reference/api/search/) request
|
||||
*
|
||||
@ -44,71 +44,71 @@ var suggestModeOptions = ['missing', 'popular', 'always'];
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.version - Specify whether to return document version as part of a hit
|
||||
*/
|
||||
function doSearch(params, callback) {
|
||||
function doSearch(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/' + encodeURIComponent(url.type) + '/_search';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/' + encodeURIComponent(parts.type) + '/_search';
|
||||
}
|
||||
else {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/_search';
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/_search';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
@ -118,7 +118,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.analyze_wildcard !== 'undefined') {
|
||||
if (params.analyze_wildcard.toLowerCase && (params.analyze_wildcard = params.analyze_wildcard.toLowerCase())
|
||||
&& (params.analyze_wildcard === 'no' || params.analyze_wildcard === 'off')
|
||||
@ -128,7 +128,7 @@ function doSearch(params, callback) {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
@ -139,7 +139,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -147,7 +147,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid df: ' + params.df + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.explain !== 'undefined') {
|
||||
if (params.explain.toLowerCase && (params.explain = params.explain.toLowerCase())
|
||||
&& (params.explain === 'no' || params.explain === 'off')
|
||||
@ -157,7 +157,7 @@ function doSearch(params, callback) {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -174,7 +174,7 @@ function doSearch(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.from !== 'undefined') {
|
||||
if (_.isNumeric(params.from)) {
|
||||
query.from = params.from * 1;
|
||||
@ -182,7 +182,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid from: ' + params.from + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -193,7 +193,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indices_boost !== 'undefined') {
|
||||
switch (typeof params.indices_boost) {
|
||||
case 'string':
|
||||
@ -210,7 +210,7 @@ function doSearch(params, callback) {
|
||||
query.indices_boost = !!params.indices_boost;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lenient !== 'undefined') {
|
||||
if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase())
|
||||
&& (params.lenient === 'no' || params.lenient === 'off')
|
||||
@ -220,7 +220,7 @@ function doSearch(params, callback) {
|
||||
query.lenient = !!params.lenient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lowercase_expanded_terms !== 'undefined') {
|
||||
if (params.lowercase_expanded_terms.toLowerCase && (params.lowercase_expanded_terms = params.lowercase_expanded_terms.toLowerCase())
|
||||
&& (params.lowercase_expanded_terms === 'no' || params.lowercase_expanded_terms === 'off')
|
||||
@ -230,7 +230,7 @@ function doSearch(params, callback) {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -238,7 +238,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
@ -246,7 +246,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
switch (typeof params.routing) {
|
||||
case 'string':
|
||||
@ -263,7 +263,7 @@ function doSearch(params, callback) {
|
||||
query.routing = !!params.routing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
@ -271,7 +271,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid scroll: ' + params.scroll + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
if (_.contains(searchTypeOptions, params.search_type)) {
|
||||
query.search_type = params.search_type;
|
||||
@ -282,7 +282,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.size !== 'undefined') {
|
||||
if (_.isNumeric(params.size)) {
|
||||
query.size = params.size * 1;
|
||||
@ -290,7 +290,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid size: ' + params.size + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.sort !== 'undefined') {
|
||||
switch (typeof params.sort) {
|
||||
case 'string':
|
||||
@ -307,7 +307,7 @@ function doSearch(params, callback) {
|
||||
query.sort = !!params.sort;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -315,7 +315,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -332,7 +332,7 @@ function doSearch(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -349,7 +349,7 @@ function doSearch(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -366,7 +366,7 @@ function doSearch(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.stats !== 'undefined') {
|
||||
switch (typeof params.stats) {
|
||||
case 'string':
|
||||
@ -383,7 +383,7 @@ function doSearch(params, callback) {
|
||||
query.stats = !!params.stats;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.suggest_field !== 'undefined') {
|
||||
if (typeof params.suggest_field !== 'object' && params.suggest_field) {
|
||||
query.suggest_field = '' + params.suggest_field;
|
||||
@ -391,7 +391,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid suggest_field: ' + params.suggest_field + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.suggest_mode !== 'undefined') {
|
||||
if (_.contains(suggestModeOptions, params.suggest_mode)) {
|
||||
query.suggest_mode = params.suggest_mode;
|
||||
@ -402,7 +402,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.suggest_size !== 'undefined') {
|
||||
if (_.isNumeric(params.suggest_size)) {
|
||||
query.suggest_size = params.suggest_size * 1;
|
||||
@ -410,7 +410,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid suggest_size: ' + params.suggest_size + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.suggest_text !== 'undefined') {
|
||||
if (typeof params.suggest_text !== 'object' && params.suggest_text) {
|
||||
query.suggest_text = '' + params.suggest_text;
|
||||
@ -418,7 +418,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid suggest_text: ' + params.suggest_text + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -428,7 +428,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version !== 'undefined') {
|
||||
if (params.version.toLowerCase && (params.version = params.version.toLowerCase())
|
||||
&& (params.version === 'no' || params.version === 'off')
|
||||
@ -438,14 +438,10 @@ function doSearch(params, callback) {
|
||||
query.version = !!params.version;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSearch;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [suggest](http://elasticsearch.org/guide/reference/api/search/suggest/) request
|
||||
*
|
||||
@ -16,54 +16,54 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded request definition (instead of using request body)
|
||||
*/
|
||||
function doSuggest(params, callback) {
|
||||
function doSuggest(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_suggest';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_suggest';
|
||||
}
|
||||
else {
|
||||
request.url = '/_suggest';
|
||||
request.path = '/_suggest';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -76,7 +76,7 @@ function doSuggest(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -84,7 +84,7 @@ function doSuggest(params, callback) {
|
||||
throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -92,7 +92,7 @@ function doSuggest(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -100,14 +100,10 @@ function doSuggest(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSuggest;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [update](http://elasticsearch.org/guide/reference/api/update/) request
|
||||
*
|
||||
@ -28,47 +28,47 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {number} params.version_type - Explicit version number for concurrency control
|
||||
*/
|
||||
function doUpdate(params, callback) {
|
||||
function doUpdate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
parts.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_update';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_update';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -81,7 +81,7 @@ function doUpdate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -98,7 +98,7 @@ function doUpdate(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lang !== 'undefined') {
|
||||
if (typeof params.lang !== 'object' && params.lang) {
|
||||
query.lang = '' + params.lang;
|
||||
@ -106,7 +106,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid lang: ' + params.lang + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -114,7 +114,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && params.percolate) {
|
||||
query.percolate = '' + params.percolate;
|
||||
@ -122,7 +122,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -132,7 +132,7 @@ function doUpdate(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -143,7 +143,7 @@ function doUpdate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.retry_on_conflict !== 'undefined') {
|
||||
if (_.isNumeric(params.retry_on_conflict)) {
|
||||
query.retry_on_conflict = params.retry_on_conflict * 1;
|
||||
@ -151,7 +151,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid retry_on_conflict: ' + params.retry_on_conflict + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -159,11 +159,11 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.script !== 'undefined') {
|
||||
query.script = params.script;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -173,7 +173,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timestamp !== 'undefined') {
|
||||
if (params.timestamp instanceof Date) {
|
||||
query.timestamp = params.timestamp.getTime();
|
||||
@ -183,7 +183,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
@ -191,7 +191,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version !== 'undefined') {
|
||||
if (_.isNumeric(params.version)) {
|
||||
query.version = params.version * 1;
|
||||
@ -199,7 +199,7 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid version: ' + params.version + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.version_type !== 'undefined') {
|
||||
if (_.isNumeric(params.version_type)) {
|
||||
query.version_type = params.version_type * 1;
|
||||
@ -207,14 +207,10 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid version_type: ' + params.version_type + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doUpdate;
|
||||
|
||||
@ -1,14 +1,3 @@
|
||||
var _ = require('./toolbelt')
|
||||
, transports = _.requireClasses(module, './transports')
|
||||
, serializers = _.requireClasses(module, './serializers')
|
||||
, Log = require('./log')
|
||||
, api = _.reKey(_.requireDir(module, '../api'), _.camelCase);
|
||||
|
||||
// Many API commands are namespaced, like cluster.node_stats. The names of these namespaces will be
|
||||
// tracked here and the namespace objects will be instantiated by reading the values from this
|
||||
// array
|
||||
var namespaces = [];
|
||||
|
||||
/**
|
||||
* A client that makes requests to Elasticsearch via a {{#crossLink "Transport"}}Transport{{/crossLink}}
|
||||
*
|
||||
@ -16,80 +5,126 @@ var namespaces = [];
|
||||
*
|
||||
* ```
|
||||
* var client = new Elasticsearch.Client({
|
||||
* transport: {
|
||||
* hosts: [
|
||||
* 'es1.net:9200',
|
||||
* 'es2.net:9200'
|
||||
* ],
|
||||
* sniff_on_start: true
|
||||
* },
|
||||
* hosts: [
|
||||
* 'es1.net:9200',
|
||||
* {
|
||||
* host: 'es2.net',
|
||||
* port: 9200
|
||||
* }
|
||||
* ],
|
||||
* sniffOnStart: true,
|
||||
* log: {
|
||||
* type: 'file',
|
||||
* level: 'warning'
|
||||
* }
|
||||
* })
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @class Client
|
||||
* @constructor
|
||||
* @param {Object} [config={}] - Configuration for the transport
|
||||
* @param {Object} [config.transport] - Transport settings passed to {{#crossLink "Transport"}}Transport Constructor{{/crossLink}}
|
||||
* @param {String|ArrayOfStrings>} [config.log] - Log output settings {{#crossLink "Log"}}Log Constructor{{/crossLink}}
|
||||
* @param {String|Array<String>} [config.log] - Log output settings {{#crossLink "Log"}}Log Constructor{{/crossLink}}
|
||||
* @param {Object} [config.trace=false] - Create a log output to stdio that only tracks trace logs
|
||||
*/
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
var _ = require('./utils'),
|
||||
ClientConfig = require('./client_config'),
|
||||
api = _.reKey(_.requireDir(module, '../api'), _.camelCase),
|
||||
q = require('q'),
|
||||
Transport = require('./transport'),
|
||||
ConnectionPool = require('./connection_pool'),
|
||||
Log = require('./log'),
|
||||
serializers = _.requireClasses(module, './serializers'),
|
||||
errors = require('./errors');
|
||||
|
||||
// Many API commands are namespaced, like cluster.node_stats. The names of these namespaces will be
|
||||
// tracked here and the namespace objects will be instantiated by reading the values from this
|
||||
// array
|
||||
var namespaces = [];
|
||||
|
||||
function Client(config) {
|
||||
this.client = this;
|
||||
this.config = !config || _.isPlainObject(config) ? new ClientConfig(config) : config;
|
||||
|
||||
for (var i = 0; i < namespaces.length; i++) {
|
||||
this[namespaces[i]] = new this[namespaces[i]](this);
|
||||
}
|
||||
|
||||
this.log = new Log(config && config.log, this);
|
||||
this.log = new Log(this);
|
||||
this.transport = new Transport(this);
|
||||
this.serializer = new serializers.Json(this);
|
||||
this.transport = new transports.NodeHttp(config.hosts || ['//localhost:9200'], this);
|
||||
this.connectionPool = new ConnectionPool(this);
|
||||
}
|
||||
|
||||
Client.prototype.ping = function () {
|
||||
return this.request({
|
||||
url: '/',
|
||||
method: 'HEAD',
|
||||
timeout: '100'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform a request with the client's transport
|
||||
*
|
||||
* @method request
|
||||
* @todo async body writing
|
||||
* @todo abort
|
||||
* @todo access to custom headers, modifying of request in general
|
||||
* @param {object} params
|
||||
* @param {String} params.url - The url for the request
|
||||
* @param {String} params.method - The HTTP method for the request
|
||||
* @param {String} params.body - The body of the HTTP request
|
||||
* @return {Promise} - A promise that will be resolved with the response
|
||||
* @param {Function} cb - A function to call back with (error, responseBody, responseStatus)
|
||||
*/
|
||||
Client.prototype.request = function (params) {
|
||||
|
||||
// serialize the body
|
||||
params.body = this.serializer.serialize(params.body);
|
||||
|
||||
// ensure that ignore is an array
|
||||
if (params.ignore && !_.isArray(params.ignore)) {
|
||||
params.ignore = [params.ignore];
|
||||
Client.prototype.request = function (params, cb) {
|
||||
if (typeof cb !== 'function') {
|
||||
cb = _.noop;
|
||||
}
|
||||
|
||||
// return the request's promise
|
||||
return this.transport.request(params);
|
||||
// get ignore and ensure that it's an array
|
||||
var ignore = params.ignore;
|
||||
if (ignore && !_.isArray(ignore)) {
|
||||
ignore = [ignore];
|
||||
}
|
||||
|
||||
this.transport.request(params, function (err, body, status) {
|
||||
if (err) {
|
||||
return cb(err, body, status);
|
||||
} else if ((status >= 200 && status < 300) || ignore && _.contains(ignore, status)) {
|
||||
return cb(void 0, body, status);
|
||||
} else {
|
||||
if (errors[status]) {
|
||||
return cb(new errors[status](body.error), body, status);
|
||||
} else {
|
||||
console.log({
|
||||
status: status,
|
||||
body: body
|
||||
});
|
||||
return cb(new errors.Generic('unknown error'), body, status);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* These namespaces will be instanciated
|
||||
* Ping some node to ensure that the cluster is available in some respect
|
||||
*
|
||||
* @param {Object} params - Currently just a placeholder, no params used at this time
|
||||
* @param {Function} cb - callback
|
||||
*/
|
||||
Client.prototype.ping = function (params, cb) {
|
||||
this.transport.request({
|
||||
method: 'HEAD',
|
||||
path: '/'
|
||||
}, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* These names of the properties that hold namespace objects in the Client prototype
|
||||
* @type {Array}
|
||||
*/
|
||||
Client.namespaces = [];
|
||||
|
||||
/**
|
||||
* creates a namespace, who's prototype offers the actions within that namespace and this context
|
||||
* Creates a namespace, who's prototype offers the actions within that namespace and this context
|
||||
* provides the API actions and a link back to the client they were intended to operate on.
|
||||
* @param {Object} actions - An object to use as the prototype for the namespace
|
||||
*/
|
||||
function makeNamespaceConstructor(actions) {
|
||||
|
||||
@ -112,5 +147,3 @@ _.extend(Client.prototype, _.map(api, function (action, name) {
|
||||
return makeNamespaceConstructor(action);
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
var _ = require('./toolbelt')
|
||||
, TransportAbstract = require('./transports/TransportAbstract');
|
||||
|
||||
function Interface(methods, properties) {
|
||||
this.methods = methods;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
Interface.properties.implementedBy = function (object) {
|
||||
var i;
|
||||
|
||||
if (this.methods) {
|
||||
for (i = 0; i < this.methods.length; i++) {
|
||||
if (!object[this.methods[i]] || typeof object[this.methods[i]] !== 'function') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var Transport = new Interface(
|
||||
[// methods
|
||||
''
|
||||
],
|
||||
{// properties
|
||||
'': ''
|
||||
}
|
||||
);
|
||||
|
||||
var Client = new Interface(
|
||||
[
|
||||
''
|
||||
],
|
||||
{
|
||||
transport: Transport
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
Transport: Transport,
|
||||
Client: Client
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
var _ = require('./toolbelt')
|
||||
, url = require('url')
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
var _ = require('./utils'),
|
||||
url = require('url'),
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
|
||||
@ -16,10 +16,11 @@ var _ = require('./toolbelt')
|
||||
* @param {string} output.level - One of the keys in Log.levels (error, warning, etc.)
|
||||
* @param {string} output.type - The name of the logger to use for this output
|
||||
*/
|
||||
function Log(output, client) {
|
||||
var i;
|
||||
function Log(client) {
|
||||
this.client = client;
|
||||
|
||||
output = output || 2;
|
||||
var i;
|
||||
var output = client.config.log || 2;
|
||||
|
||||
if (_.isString(output) || _.isFinite(output)) {
|
||||
output = [
|
||||
@ -39,7 +40,7 @@ function Log(output, client) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isArrayOfObjects(output)) {
|
||||
if (!_.isArrayOfPlainObjects(output)) {
|
||||
throw new TypeError('Invalid Logging output config');
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ Log.levels = [
|
||||
* @event error
|
||||
* @param {Error} error - The error object to log
|
||||
*/
|
||||
'error'
|
||||
'error',
|
||||
/**
|
||||
* Event fired for "warning" level log entries, which usually represent things
|
||||
* like correctly formatted error responses from ES (400, ...) and recoverable
|
||||
@ -72,7 +73,7 @@ Log.levels = [
|
||||
* @event warning
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'warning'
|
||||
'warning',
|
||||
/**
|
||||
* Event fired for "info" level log entries, which usually describe what a
|
||||
* client is doing (sniffing etc)
|
||||
@ -80,7 +81,7 @@ Log.levels = [
|
||||
* @event info
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'info'
|
||||
'info',
|
||||
/**
|
||||
* Event fired for "debug" level log entries, which will describe requests sent,
|
||||
* including their url (no data, response codes, or exec times)
|
||||
@ -88,7 +89,7 @@ Log.levels = [
|
||||
* @event debug
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'debug'
|
||||
'debug',
|
||||
/**
|
||||
* Event fired for "trace" level log entries, which provide detailed information
|
||||
* about each request made from a client, including reponse codes, execution times,
|
||||
@ -101,7 +102,7 @@ Log.levels = [
|
||||
* @param {Integer} responseStatus - The status code returned from the response
|
||||
* @param {String} responseBody - The body of the response
|
||||
*/
|
||||
, 'trace'
|
||||
'trace'
|
||||
];
|
||||
|
||||
/**
|
||||
@ -233,11 +234,11 @@ Log.prototype.debug = function (/* ...msg */) {
|
||||
* @param {String|Object} requestUrl - URL requested. If the value is an object,
|
||||
* it is expected to be the return value of Node's url.parse()
|
||||
* @param {String} body - The request's body
|
||||
* @param {Number} responseStatus - The status code returned
|
||||
* @param {String} responseBody - The body of the returned response
|
||||
* @param {String} responseBody - body returned from ES
|
||||
* @param {String} responseStatus - HTTP status code
|
||||
* @return {Boolean} - True if any outputs accepted the message
|
||||
*/
|
||||
Log.prototype.trace = function (method, requestUrl, body, responseStatus, responseBody) {
|
||||
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
|
||||
if (EventEmitter.listenerCount(this, 'trace')) {
|
||||
if (typeof requestUrl === 'object') {
|
||||
if (!requestUrl.protocol) {
|
||||
@ -245,7 +246,7 @@ Log.prototype.trace = function (method, requestUrl, body, responseStatus, respon
|
||||
}
|
||||
requestUrl = url.format(requestUrl);
|
||||
}
|
||||
return this.emit('trace', method, requestUrl, body, responseStatus, responseBody);
|
||||
return this.emit('trace', method, requestUrl, body, responseBody, responseStatus);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,59 +1,90 @@
|
||||
var _ = require('./toolbelt')
|
||||
, selectors = require('./selector');
|
||||
|
||||
var configDefaults = {
|
||||
hosts : [
|
||||
{
|
||||
host: 'localhost',
|
||||
port: 9200
|
||||
}
|
||||
],
|
||||
|
||||
//nodes_to_host_callback : construct_hosts_list,
|
||||
sniff_on_start : false,
|
||||
sniff_after_requests : 0,
|
||||
sniff_on_connection_fail : false,
|
||||
max_retries : 3,
|
||||
selector : 'roundRobin'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Abstract" class responsible for managing connection pools, sniffing for nodes, and serializing/
|
||||
* deserializing requests and ES errors.
|
||||
* Manages connection pools, sniffs for nodes, and runs requests
|
||||
*
|
||||
* @main Transport
|
||||
* @class Transport
|
||||
* @constructor
|
||||
* @param {Object} [config={}] - An object with configuration parameters
|
||||
* @param {String|ArrayOfStrings} [config.hosts='localhost:9200'] - Host(s) that this client should communicate with.
|
||||
* @param {Boolean} [config.sniff_on_start=false] - inspect the cluster for a list of nodes upon startup
|
||||
* @param {Number} [config.sniff_after_requests=false] - Sniff after completing a certain number of request (disabled by default)
|
||||
* @param {Boolean} [config.sniff_on_connection_fail=false] - Sniff after a connection fails (disabled by default)
|
||||
* @param {Number} [config.max_retries=3] - The maximum number of time the client should retry connecting to a node
|
||||
* @param {Boolean} [config.connectionConstructor=false] - A constructor to use for connections to ES nodes
|
||||
* @param {Function} [config.nodesToHostCallback=parseNodeList] - convert the value returned from _cluster/nodes into
|
||||
* a host list
|
||||
* @param {Boolean} [config.sniffOnStart=false] - inspect the cluster for a list of nodes upon startup
|
||||
* @param {Number} [config.sniffAfterRequests=null] - Sniff after completing a certain number of request
|
||||
* @param {Boolean} [config.sniffOnConnectionFail=false] - Sniff after a connection fails
|
||||
* @param {Number} [config.max_retries=3] - The maximum number of times the client should retry connecting to a node
|
||||
*/
|
||||
function Transport(config) {
|
||||
// These are all unique to each instance of client
|
||||
config = _.defaults(config || {}, configDefaults);
|
||||
|
||||
if (_.isFunction(this.opts.selector)) {
|
||||
this.selector = this.opts.selector;
|
||||
} else if (_.has(selectors, this.opts.selector)) {
|
||||
this.selector = selectors[this.opts.selector];
|
||||
} else {
|
||||
throw new Error('Invalid Selector, specify a function or selector name.');
|
||||
}
|
||||
module.exports = Transport;
|
||||
|
||||
var _ = require('./utils'),
|
||||
q = require('q'),
|
||||
ConnectionPool = require('./connection_pool'),
|
||||
errors = require('./errors');
|
||||
|
||||
function Transport(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the defaults for the Transport class
|
||||
*
|
||||
* @method defaults
|
||||
* @param {Object} update An object representing the changes to be made to the defaults.
|
||||
* @static
|
||||
* @return {undefined}
|
||||
*/
|
||||
Transport.defaults = function (update) {
|
||||
_.assign(configDefaults, update);
|
||||
|
||||
Transport.prototype.sniff = function (cb) {
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var connectionPool = this.client.connectionPool,
|
||||
nodesToHostCallback = _.bind(this.client.config.nodesToHostCallback, this);
|
||||
|
||||
this.client.request({
|
||||
path: '/_cluster/nodes'
|
||||
}, function (err, resp) {
|
||||
if (!err && resp && resp.nodes) {
|
||||
connectionPool.setHosts(nodesToHostCallback(resp.nodes));
|
||||
}
|
||||
cb(err, resp);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Transport.prototype.request = function (params, cb) {
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var client = this.client,
|
||||
remainingRetries = client.config.maxRetries,
|
||||
connection;
|
||||
|
||||
// serialize the body
|
||||
params.body = client.serializer.serialize(params.body);
|
||||
|
||||
function sendRequestWithConnection(err, c) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
} else if (c) {
|
||||
connection = c;
|
||||
connection.request(params, checkRespForFailure);
|
||||
} else {
|
||||
cb(new errors.ConnectionError('No active nodes at this time.'));
|
||||
}
|
||||
}
|
||||
|
||||
function checkRespForFailure(err, body, status) {
|
||||
// check for posotive response
|
||||
if (err) {
|
||||
client.connectionPool.setStatus(connection, 'dead');
|
||||
checkForRetry(err, null, status);
|
||||
} else {
|
||||
client.connectionPool.setStatus(connection, 'alive');
|
||||
return cb(null, client.serializer.unserialize(body), status);
|
||||
}
|
||||
}
|
||||
|
||||
function checkForRetry(err, resp) {
|
||||
client.connectionPool.setStatus(connection, 'dead');
|
||||
if (remainingRetries) {
|
||||
remainingRetries--;
|
||||
client.connectionPool.select(sendRequestWithConnection);
|
||||
} else {
|
||||
return cb(err, null);
|
||||
}
|
||||
}
|
||||
|
||||
client.connectionPool.select(sendRequestWithConnection);
|
||||
};
|
||||
|
||||
86
src/lib/client_config.js
Normal file
86
src/lib/client_config.js
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Manages the configuration of the client.
|
||||
*
|
||||
* @class ClientConfig
|
||||
* @type {Function}
|
||||
*/
|
||||
module.exports = ClientConfig;
|
||||
|
||||
var url = require('url'),
|
||||
_ = require('./utils'),
|
||||
selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase),
|
||||
connections = _.requireClasses(module, './connections'),
|
||||
extractHostPartsRE = /\[([^:]+):(\d+)]/,
|
||||
hostProtocolRE = /^([a-z]+:)?\/\//;
|
||||
|
||||
var defaultConfig = {
|
||||
hosts: [
|
||||
{
|
||||
protocol: 'http:',
|
||||
host: 'localhost',
|
||||
port: 9200
|
||||
}
|
||||
],
|
||||
connectionConstructor: 'Http',
|
||||
selector: selectors.roundRobin,
|
||||
nodesToHostCallback: function (nodes) {
|
||||
var hosts = [];
|
||||
_.each(nodes, function (node, id) {
|
||||
var hostnameMatches = extractHostPartsRE.exec(node.hostname);
|
||||
hosts.push({
|
||||
hostname: hostnameMatches[1],
|
||||
port: hostnameMatches[2],
|
||||
id: id,
|
||||
name: node.name,
|
||||
servername: node.hostname,
|
||||
version: node.version
|
||||
});
|
||||
});
|
||||
return hosts;
|
||||
},
|
||||
sniffOnStart: false,
|
||||
sniffAfterRequests: null,
|
||||
sniffOnConnectionFail: false,
|
||||
maxRetries: 3
|
||||
};
|
||||
|
||||
function ClientConfig(config) {
|
||||
_.extend(this, defaultConfig, config);
|
||||
|
||||
if (typeof this.hosts !== 'object') {
|
||||
this.hosts = [this.hosts];
|
||||
}
|
||||
|
||||
this.hosts = _.map(this.hosts, this.transformHost);
|
||||
}
|
||||
|
||||
ClientConfig.prototype.transformHost = function (host) {
|
||||
if (typeof host === 'object') {
|
||||
if (host.protocol) {
|
||||
// the protocol must end in a color
|
||||
if (host.protocol[host.protocol.length - 1] !== ':') {
|
||||
host.protocol = host.protocol + ':';
|
||||
}
|
||||
} else {
|
||||
host.protocol = 'http:';
|
||||
}
|
||||
|
||||
if (host.host && !host.hostname) {
|
||||
// utl.format && url.parse uses "hostname" to represent just the name of the host, "host" is "hostname + port"
|
||||
host.hostname = host.host;
|
||||
delete host.host;
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
if (!hostProtocolRE.test(host)) {
|
||||
host = 'http://' + host;
|
||||
}
|
||||
var urlInfo = url.parse(host, false, true);
|
||||
return {
|
||||
protocol: urlInfo.protocol,
|
||||
hostname: urlInfo.hostname,
|
||||
port: urlInfo.port
|
||||
};
|
||||
};
|
||||
45
src/lib/connection.js
Normal file
45
src/lib/connection.js
Normal file
@ -0,0 +1,45 @@
|
||||
module.exports = ConnectionAbstract;
|
||||
|
||||
var _ = require('./utils'),
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Abstract class used for Connection classes
|
||||
* @param client {Client} - The client that this connection belongs to
|
||||
* @param config {Object} - a map of configuration details for this connection
|
||||
* @param [config.hostname=localhost] {String} - The hostname for the node this connection connects to
|
||||
* @param [config.port=9200] {Integer} - The port on the server that ES is listening to
|
||||
* @class ConnectionAbstract
|
||||
* @constructor
|
||||
*/
|
||||
function ConnectionAbstract(client, config, id) {
|
||||
EventEmitter.call(this);
|
||||
this.client = client;
|
||||
this.id = id;
|
||||
this.hostname = config.hostname || 'localhost';
|
||||
this.port = config.port || 9200;
|
||||
this.timeout = config.timeout || 10000;
|
||||
}
|
||||
_.inherits(ConnectionAbstract, EventEmitter);
|
||||
|
||||
/**
|
||||
* Make a request using this connection. Must be overridden by Connection classes, which can add whatever keys to
|
||||
* params that they like. These are just the basics.
|
||||
*
|
||||
* @param [params] {Object} - The parameters for the request
|
||||
* @param params.path {String} - The path for which you are requesting
|
||||
* @param params.method {String} - The HTTP method for the request (GET, HEAD, etc.)
|
||||
* @param params.timeout {Integer} - The amount of time in milliseconds that this request should be allowed to run for.
|
||||
* @param cb {Function} - A callback to be called once with `cb(err, responseBody, responseStatus)`
|
||||
*/
|
||||
ConnectionAbstract.prototype.request = function () {
|
||||
throw new Error('Connection#request must be overwritten by the Connector');
|
||||
};
|
||||
|
||||
ConnectionAbstract.prototype.ping = function () {
|
||||
return this.request({
|
||||
path: '/',
|
||||
method: 'HEAD',
|
||||
timeout: '100'
|
||||
});
|
||||
};
|
||||
@ -3,9 +3,140 @@
|
||||
* before providing them to the application
|
||||
*
|
||||
* @class ConnectionPool
|
||||
* @constructor
|
||||
* @param {object} [config={}] - an object describing the configuration for the ConnectionPool
|
||||
* @param {Client} client - The client this pool belongs to
|
||||
*/
|
||||
function ConnectionPool(config) {
|
||||
|
||||
}
|
||||
module.exports = ConnectionPool;
|
||||
|
||||
var _ = require('./utils'),
|
||||
selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase),
|
||||
connectors = _.reKey(_.requireDir(module, './connections'), _.studlyCase),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
q = require('q'),
|
||||
errors = require('./errors');
|
||||
|
||||
function ConnectionPool(client) {
|
||||
this.client = client;
|
||||
this.index = {};
|
||||
this.connections = {
|
||||
alive: [],
|
||||
dead: []
|
||||
};
|
||||
|
||||
var config = client.config;
|
||||
|
||||
// validate connectionConstructor
|
||||
if (typeof config.connectionConstructor !== 'function') {
|
||||
if (_.has(connectors, config.connectionConstructor)) {
|
||||
config.connectionConstructor = connectors[config.connectionConstructor];
|
||||
} else {
|
||||
throw new TypeError('Invalid connectionConstructor ' + config.connectionConstructor +
|
||||
', specify a function or one of ' + _.keys(connectors).join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
this.connectionConstructor = config.connectionConstructor;
|
||||
this.setNodes(config.hosts);
|
||||
}
|
||||
|
||||
ConnectionPool.prototype.setNodes = function (nodes) {
|
||||
var client = this.client;
|
||||
|
||||
if (!_.isArrayOfObjects(nodes)) {
|
||||
throw new TypeError('Invalid hosts: specify an Array of Objects with host and port keys');
|
||||
}
|
||||
|
||||
var i, id, prevIndex = _.clone(this.index), connection;
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
id = nodes[i].host + ':' + nodes[i].port;
|
||||
if (prevIndex[id]) {
|
||||
delete prevIndex[id];
|
||||
} else {
|
||||
client.log.info('Creating connection to ' + id);
|
||||
connection = new this.connectionConstructor(this.client, nodes[i]);
|
||||
if (!(connection instanceof EventEmitter)) {
|
||||
throw new Error('ConnectionConstructor does not implement the event interface');
|
||||
} else if (!EventEmitter.listenerCount(connection, 'closed')) {
|
||||
throw new Error(
|
||||
'Connection Constructor ' + this.connectionConstructor.name +
|
||||
' does not listen for the closed event. No bueno.'
|
||||
);
|
||||
}
|
||||
this.index[id] = connection;
|
||||
this.setStatus(connection, 'alive');
|
||||
}
|
||||
}
|
||||
|
||||
var toRemove = _.keys(prevIndex);
|
||||
for (i = 0; i < toRemove.length; i++) {
|
||||
client.log.info('Closing connection to ' + toRemove[i]);
|
||||
this.index[toRemove[i]].isClosed();
|
||||
delete this.index[toRemove[i]];
|
||||
}
|
||||
|
||||
client.log.info('Nodes successfully changed');
|
||||
};
|
||||
|
||||
ConnectionPool.prototype.select = function (cb) {
|
||||
var config = this.client.config;
|
||||
|
||||
if (typeof config.selector !== 'function') {
|
||||
if (_.has(selectors, config.selector)) {
|
||||
config.selector = selectors[config.selector];
|
||||
} else {
|
||||
throw new TypeError('Invalid Selector ' + config.selector + '. specify a function or one of ' + _.keys(selectors).join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.connections.alive.length) {
|
||||
if (config.selector.length > 1) {
|
||||
config.selector(this.connections.alive, cb);
|
||||
} else {
|
||||
cb(null, config.selector(this.connections.alive));
|
||||
}
|
||||
} else {
|
||||
cb(new errors.ConnectionError('No living connections'));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ConnectionPool.prototype.setStatus = function (connection, status) {
|
||||
var origStatus = connection.status, from, to, index;
|
||||
|
||||
if (origStatus === status) {
|
||||
return true;
|
||||
} else {
|
||||
this.client.log.info('connection to', _.formatUrl(connection), 'is', status);
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 'alive':
|
||||
from = this.connections.dead;
|
||||
to = this.connections.alive;
|
||||
break;
|
||||
case 'dead':
|
||||
from = this.connections.alive;
|
||||
to = this.connections.dead;
|
||||
break;
|
||||
case 'closed':
|
||||
from = this.connections[origStatus];
|
||||
break;
|
||||
}
|
||||
|
||||
if (from && from.indexOf) {
|
||||
index = from.indexOf(connection);
|
||||
if (~index) {
|
||||
from.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (to && to.indexOf) {
|
||||
index = to.indexOf(connection);
|
||||
if (!~index) {
|
||||
to.push(connection);
|
||||
}
|
||||
}
|
||||
|
||||
connection.status = status;
|
||||
connection.emit(status, origStatus);
|
||||
};
|
||||
|
||||
15
src/lib/connections/angular.js
vendored
Normal file
15
src/lib/connections/angular.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Connection that registers a module with angular, using angular's $http service
|
||||
* to communicate with ES.
|
||||
*
|
||||
* @class connections.Angular
|
||||
*/
|
||||
module.exports = AngularConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function AngularConnection() {
|
||||
|
||||
}
|
||||
_.inherits(AngularConnection, ConnectionAbstract);
|
||||
117
src/lib/connections/http.js
Normal file
117
src/lib/connections/http.js
Normal file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* A Connection that operates using Node's http module
|
||||
*
|
||||
* @param client {Client} - The Client that this class belongs to
|
||||
* @param config {Object} - Configuration options
|
||||
* @param [config.protocol=http:] {String} - The HTTP protocol that this connection will use, can be set to https:
|
||||
* @class HttpConnection
|
||||
*/
|
||||
module.exports = HttpConnection;
|
||||
|
||||
var http = require('http'),
|
||||
_ = require('../utils'),
|
||||
q = require('q'),
|
||||
errors = require('../errors'),
|
||||
ConnectionAbstract = require('../connection'),
|
||||
defaultHeaders = {
|
||||
'connection': 'keep-alive'
|
||||
};
|
||||
|
||||
|
||||
function HttpConnection(client, config) {
|
||||
ConnectionAbstract.call(this, client, config);
|
||||
|
||||
this.protocol = config.protocol || 'http:';
|
||||
if (this.protocol[this.protocol.length - 1] !== ':') {
|
||||
this.protocol = this.protocol + ':';
|
||||
}
|
||||
|
||||
this.agent = new http.Agent({
|
||||
keepAlive: true,
|
||||
// delay between the last data packet received and the first keepalive probe
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: this.client.config.maxSockets,
|
||||
maxFreeSockets: this.client.config.maxFreeSockets
|
||||
});
|
||||
|
||||
this.on('closed', function () {
|
||||
this.agent.destroy();
|
||||
this.removeAllListeners();
|
||||
});
|
||||
}
|
||||
_.inherits(HttpConnection, ConnectionAbstract);
|
||||
|
||||
HttpConnection.prototype.request = function (params, cb) {
|
||||
var request,
|
||||
response,
|
||||
status = 0,
|
||||
timeout = params.timeout || this.timeout,
|
||||
timeoutId,
|
||||
log = this.client.log;
|
||||
|
||||
var reqParams = _.defaults({
|
||||
protocol: this.protocol,
|
||||
hostname: this.hostname,
|
||||
port: this.port,
|
||||
path: params.path,
|
||||
method: _.toUpperString(params.method) || (params.body ? 'POST' : 'GET'),
|
||||
headers: _.defaults(params.headers || {}, defaultHeaders)
|
||||
});
|
||||
|
||||
// general clean-up procedure to run after the request, can only run once
|
||||
var cleanUp = function (err) {
|
||||
cleanUp = _.noop;
|
||||
|
||||
if (err) {
|
||||
log.error(err);
|
||||
}
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
if (request) {
|
||||
request.removeAllListeners();
|
||||
}
|
||||
_.nextTick(cb, err, response, status);
|
||||
};
|
||||
|
||||
// ensure that "get" isn't being used with a request body
|
||||
if (params.body && reqParams.method === 'GET') {
|
||||
cleanUp(new TypeError('HTTP Method GET can not have a body'));
|
||||
return;
|
||||
}
|
||||
|
||||
reqParams.agent = this.agent;
|
||||
|
||||
request = http.request(reqParams);
|
||||
|
||||
request.on('response', function (incoming) {
|
||||
status = incoming.statusCode;
|
||||
incoming.setEncoding('utf8');
|
||||
|
||||
incoming.on('data', function (d) {
|
||||
response += d;
|
||||
});
|
||||
|
||||
incoming.on('close', function (err) {
|
||||
console.log('closed');
|
||||
cleanUp(err);
|
||||
});
|
||||
|
||||
incoming.on('end', function requestComplete() {
|
||||
incoming.removeAllListeners();
|
||||
log.trace(reqParams.method, reqParams, params.body, response, status);
|
||||
cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', function (err) {
|
||||
request.abort();
|
||||
cleanUp(err);
|
||||
});
|
||||
|
||||
// timeout for the entire request, req.setTimeout only set the socket level timeout
|
||||
timeoutId = setTimeout(function () {
|
||||
request.emit('error', new errors.RequestTimeout('Request timed out at ' + timeout + 'ms'));
|
||||
}, timeout);
|
||||
|
||||
request.end(params.body);
|
||||
};
|
||||
9
src/lib/connections/jquery.js
vendored
Normal file
9
src/lib/connections/jquery.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = JqueryConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function JqueryConnection() {
|
||||
|
||||
}
|
||||
_.inherits(JqueryConnection, ConnectionAbstract);
|
||||
15
src/lib/connections/xhr.js
Normal file
15
src/lib/connections/xhr.js
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generic Transport for the browser, using the XmlHttpRequest object
|
||||
*
|
||||
* @class connections.Xhr
|
||||
*/
|
||||
|
||||
module.exports = XhrConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function XhrConnection() {
|
||||
|
||||
}
|
||||
_.inherits(XhrConnection, ConnectionAbstract);
|
||||
@ -0,0 +1,105 @@
|
||||
var _ = require('./utils'),
|
||||
errors = module.exports;
|
||||
|
||||
function ErrorAbstract(msg) {
|
||||
Error.call(this, msg);
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
|
||||
this.message = msg;
|
||||
}
|
||||
_.inherits(ErrorAbstract, Error);
|
||||
|
||||
/**
|
||||
* Connection Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.ConnectionError = function ConnectionError(msg) {
|
||||
return new Error(msg || 'Connection Failure');
|
||||
ErrorAbstract.call(this, msg || 'Connection Failure');
|
||||
};
|
||||
_.inherits(errors.ConnectionError, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Generic Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.Generic = function Generic(msg) {
|
||||
return new Error(msg || 'Generic Error');
|
||||
ErrorAbstract.call(this, msg || 'Generic Error');
|
||||
};
|
||||
_.inherits(errors.Generic, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Request Timeout Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.RequestTimeout = function RequestTimeout(msg) {
|
||||
return new Error(msg || 'RequestTimeout');
|
||||
ErrorAbstract.call(this, msg || 'Request Timeout');
|
||||
};
|
||||
_.inherits(errors.RequestTimeout, ErrorAbstract);
|
||||
|
||||
|
||||
var statusCodes = {
|
||||
|
||||
/**
|
||||
* Service Unavailable
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
503: 'Service Unavailable',
|
||||
|
||||
/**
|
||||
* Internal Server Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
500: 'Internal Server Error',
|
||||
|
||||
/**
|
||||
* Precondition Failed
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
412: 'Precondition Failed',
|
||||
|
||||
/**
|
||||
* Conflict
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
409: 'Conflict',
|
||||
|
||||
/**
|
||||
* Forbidden
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
403: 'Forbidden',
|
||||
|
||||
/**
|
||||
* Not Found
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
404: 'Not Found',
|
||||
|
||||
/**
|
||||
* Bad Request
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
400: 'Bad Request',
|
||||
|
||||
/**
|
||||
* Moved Permanently
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
301: 'Moved Permanently'
|
||||
};
|
||||
|
||||
_.each(statusCodes, function (name, status) {
|
||||
var className = _.studlyCase(name);
|
||||
|
||||
function StatusCodeError(msg) {
|
||||
return new Error(msg || name);
|
||||
ErrorAbstract.call(this, msg || name);
|
||||
}
|
||||
|
||||
_.inherits(StatusCodeError, ErrorAbstract);
|
||||
errors[className] = StatusCodeError;
|
||||
errors[status] = StatusCodeError;
|
||||
});
|
||||
|
||||
157
src/lib/logger.js
Normal file
157
src/lib/logger.js
Normal file
@ -0,0 +1,157 @@
|
||||
var Log = require('./log'),
|
||||
_ = require('./utils');
|
||||
|
||||
/**
|
||||
* Abstract class providing common functionality to loggers
|
||||
* @param {[type]} config [description]
|
||||
* @param {[type]} bridge [description]
|
||||
*/
|
||||
function LoggerAbstract(config, bridge) {
|
||||
|
||||
this.bridge = bridge;
|
||||
this.listeningLevels = [];
|
||||
|
||||
// bound copies of the event handlers
|
||||
this.handlers = _.reduce(Log.levels, function (handlers, name) {
|
||||
handlers[name] = _.bindKey(this, 'on' + _.studlyCase(name));
|
||||
return handlers;
|
||||
}, {}, this);
|
||||
|
||||
// then the bridge closes, remove our event listeners
|
||||
this.bridge.on('closing', _.bindKey(this, 'cleanUpListeners'));
|
||||
|
||||
this.setupListeners(config.levels);
|
||||
}
|
||||
|
||||
function padNumToTen(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a timestamp string used in the format function. Defers to Log.timestamp if it is defined,
|
||||
* Also, feel free to override this at the logger level.
|
||||
* @return {String} - Timestamp in ISO 8601 UTC
|
||||
*/
|
||||
LoggerAbstract.prototype.timestamp = function () {
|
||||
var d = new Date();
|
||||
return d.getUTCFullYear() + '-' +
|
||||
padNumToTen(d.getUTCMonth() + 1) + '-' +
|
||||
padNumToTen(d.getUTCDate()) + 'T' +
|
||||
padNumToTen(d.getUTCHours()) + ':' +
|
||||
padNumToTen(d.getUTCMinutes()) + ':' +
|
||||
padNumToTen(d.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
function indent(text, spaces) {
|
||||
var space = _.repeat(' ', spaces || 2);
|
||||
return text.split(/\r?\n/).map(function (line) {
|
||||
return space + line;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
LoggerAbstract.prototype.format = function (label, message) {
|
||||
return label + ': ' + this.timestamp() + '\n' + indent(message) + '\n\n';
|
||||
};
|
||||
|
||||
LoggerAbstract.prototype.write = function () {
|
||||
throw new Error('This should be overwritten by the logger');
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners and then re-listen for events based on the level specified
|
||||
*
|
||||
* @method setupListeners
|
||||
* @private
|
||||
* @param {Integer} level - The max log level that this logger should listen to
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.setupListeners = function (levels) {
|
||||
this.cleanUpListeners();
|
||||
|
||||
this.listeningLevels = levels;
|
||||
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.on(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners
|
||||
*
|
||||
* @method cleanUpListeners
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.cleanUpListeners = function () {
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.removeListener(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "error" event
|
||||
*
|
||||
* @method onError
|
||||
* @private
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onError = function (e) {
|
||||
this.write((e.name === 'Error' ? 'ERROR' : e.name), e.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "warning" event
|
||||
*
|
||||
* @method onWarning
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onWarning = function (msg) {
|
||||
this.write('WARNING', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "info" event
|
||||
*
|
||||
* @method onInfo
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onInfo = function (msg) {
|
||||
this.write('INFO', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "debug" event
|
||||
*
|
||||
* @method onDebug
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onDebug = function (msg) {
|
||||
this.write('DEBUG', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "trace" event
|
||||
*
|
||||
* @method onTrace
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onTrace = function (method, url, body, responseBody, responseStatus) {
|
||||
var message = 'curl "' + url.replace(/"/g, '\\"') + '" -X' + method.toUpperCase();
|
||||
if (body) {
|
||||
message += ' -d "' + body.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
message += '\n<- ' + responseStatus + '\n' + responseBody;
|
||||
this.write('TRACE', message);
|
||||
};
|
||||
|
||||
|
||||
module.exports = LoggerAbstract;
|
||||
@ -1,106 +1,26 @@
|
||||
var LogAbstract = require('./log_abstract')
|
||||
, _ = require('../toolbelt')
|
||||
, fs = require('fs');
|
||||
|
||||
function prettyPrint(json) {
|
||||
try {
|
||||
json = JSON.stringify(JSON.parse(json), null, ' ');
|
||||
} catch (e) {}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logger that writes to a file
|
||||
*
|
||||
* @class Loggers.File
|
||||
* @extends StreamLogger
|
||||
* @constructor
|
||||
* @see LoggerAbstract
|
||||
* @param {Object} config - The configuration for the Logger (See LoggerAbstract for generic options)
|
||||
* @param {String} config.path - The location to write
|
||||
* @param {Log} bridge - The object that triggers logging events, which we will record
|
||||
*/
|
||||
function File(config, bridge) {
|
||||
this._constructSuper(arguments);
|
||||
|
||||
this.outputPath = config.path;
|
||||
}
|
||||
_.inherits(File, LogAbstract);
|
||||
|
||||
File.prototype.write = function (label, message) {
|
||||
if (!this.file) {
|
||||
this.file = fs.createWriteStream(this.outputPath, {
|
||||
flags: 'a',
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
|
||||
this.file.write(this.format(label, message), 'utf8');
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "error" event
|
||||
*
|
||||
* @method onError
|
||||
* @private
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onError = function (e) {
|
||||
this.write((e.name === 'Error' ? 'ERROR' : e.name), e.message + '\n\nStack Trace:\n' + e.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "warning" event
|
||||
*
|
||||
* @method onWarning
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onWarning = function (msg) {
|
||||
this.write('WARNING', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "info" event
|
||||
*
|
||||
* @method onInfo
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onInfo = function (msg) {
|
||||
this.write('INFO', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "debug" event
|
||||
*
|
||||
* @method onDebug
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onDebug = function (msg) {
|
||||
this.write('DEBUG', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "trace" event
|
||||
*
|
||||
* @method onTrace
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onTrace = function (method, url, body, responseStatus, responseBody) {
|
||||
var message = 'curl "' + url.replace(/"/g, '\\"') + '" -X' + method.toUpperCase();
|
||||
if (body) {
|
||||
message += ' -d "' + body.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
message += '\n<- ' + responseStatus + '\n' + prettyPrint(responseBody);
|
||||
this.write('TRACE', message);
|
||||
};
|
||||
|
||||
module.exports = File;
|
||||
|
||||
var StreamLogger = require('./stream'),
|
||||
_ = require('../utils'),
|
||||
fs = require('fs');
|
||||
|
||||
function File(config, bridge) {
|
||||
config.stream = fs.createWriteStream(config.path, {
|
||||
flags: 'a',
|
||||
encoding: 'utf8'
|
||||
});
|
||||
|
||||
File.callSuper(this, arguments);
|
||||
}
|
||||
_.inherits(File, StreamLogger);
|
||||
|
||||
@ -1,34 +1,38 @@
|
||||
var clc = require('cli-color')
|
||||
, LogAbstract = require('./log_abstract')
|
||||
, _ = require('../toolbelt');
|
||||
|
||||
/**
|
||||
* Special version of the Stream logger, which logs errors and warnings to stderr and all other
|
||||
* levels to stdout.
|
||||
*
|
||||
* @class Loggers.Stdio
|
||||
* @extends LoggerAbstract
|
||||
* @constructor
|
||||
* @param {Object} config - The configuration for the Logger
|
||||
* @param {string} config.level - The highest log level for this logger to output.
|
||||
* @param {Log} bridge - The object that triggers logging events, which we will record
|
||||
*/
|
||||
|
||||
module.exports = Stdio;
|
||||
|
||||
var clc = require('cli-color'),
|
||||
LoggerAbstract = require('../logger'),
|
||||
_ = require('../utils');
|
||||
|
||||
function Stdio(config, bridge) {
|
||||
this._constructSuper(arguments);
|
||||
Stdio.callSuper(this, arguments);
|
||||
|
||||
// config/state
|
||||
this.color = _.has(config, 'color') ? !!config.color : true;
|
||||
}
|
||||
|
||||
_.inherits(Stdio, LogAbstract);
|
||||
_.inherits(Stdio, LoggerAbstract);
|
||||
|
||||
/**
|
||||
* Sends output to a stream, does some formatting first
|
||||
*
|
||||
* @method write
|
||||
* @private
|
||||
* @param {WriteableStream} to - The stream that should receive this message
|
||||
* @param {String} label - The text that should be used at the begining of the message
|
||||
* @param {function} colorize - A function that recieves a string and returned a colored version of it
|
||||
* @param {WritableStream} to - The stream that should receive this message
|
||||
* @param {String} label - The text that should be used at the beginning the message
|
||||
* @param {function} colorize - A function that receives a string and returned a colored version of it
|
||||
* @param {*} what - The message to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
@ -48,7 +52,7 @@ Stdio.prototype.write = function (to, label, colorize, message) {
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onError = function (e) {
|
||||
this.write(process.stderr, e.name === 'Error' ? 'ERROR' : e.name, clc.red.bold, [e.message, '\n\nStack Trace:\n' + e.stack]);
|
||||
this.write(process.stderr, e.name === 'Error' ? 'ERROR' : e.name, clc.red.bold, e.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -92,11 +96,14 @@ Stdio.prototype.onDebug = function (msg) {
|
||||
*
|
||||
* @method onTrace
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onTrace = function (method, url, body, responseStatus, responseBody) {
|
||||
var message = '\nHTTP ' + method + ' ' + url + ' -> ';
|
||||
Stdio.prototype.onTrace = function (method, url, body, responseBody, responseStatus) {
|
||||
var message = 'curl "' + url.replace(/"/g, '\\"') + '" -X' + method.toUpperCase();
|
||||
if (body) {
|
||||
message += ' -d "' + body.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
message += '\n<- ';
|
||||
if (this.color) {
|
||||
if (responseStatus === 200) {
|
||||
message += clc.green.bold(responseStatus);
|
||||
@ -106,12 +113,7 @@ Stdio.prototype.onTrace = function (method, url, body, responseStatus, responseB
|
||||
} else {
|
||||
message += responseStatus;
|
||||
}
|
||||
message += '\n' + responseBody + '\n\n';
|
||||
message += 'curl "' + url.replace('"', '\\"') + '" -X' + method.toUpperCase();
|
||||
if (body) {
|
||||
message += ' -d ' + JSON.stringify(JSON.stringify(body));
|
||||
}
|
||||
this.write(process.stdout, 'TRACE', clc.cyanBright.bold, message + '\n\n');
|
||||
};
|
||||
message += '\n' + responseBody;
|
||||
|
||||
module.exports = Stdio;
|
||||
this.write(process.stdout, 'TRACE', clc.cyanBright.bold, message);
|
||||
};
|
||||
|
||||
@ -1,14 +1,37 @@
|
||||
/**
|
||||
* A logger object, which listens to the LogBridge for logging events based on it's config. This
|
||||
* logger writes it logs to any [WriteableStream](http://nodejs.org/api/stream.html#stream_class_stream_writable_1).
|
||||
* Logger that writes to a file
|
||||
*
|
||||
* @class Loggers.Stream
|
||||
* @class Loggers.File
|
||||
* @extends LoggerAbstract
|
||||
* @constructor
|
||||
* @param {Object} config - A hash of the config options
|
||||
* @param {Log} logBridge - The log bridge that will emit events for each log entry
|
||||
* @see LoggerAbstract
|
||||
* @param {Object} config - The configuration for the Logger (See LoggerAbstract for generic options)
|
||||
* @param {String} config.path - The location to write
|
||||
* @param {Log} bridge - The object that triggers logging events, which we will record
|
||||
*/
|
||||
function Stream(config, logBridge) {
|
||||
this.setLevel(config.level);
|
||||
}
|
||||
|
||||
module.exports = Stream;
|
||||
module.exports = Stream;
|
||||
|
||||
var LoggerAbstract = require('../Logger'),
|
||||
nodeStreams = require('stream'),
|
||||
_ = require('../utils'),
|
||||
fs = require('fs');
|
||||
|
||||
function Stream(config, bridge) {
|
||||
Stream.callSuper(this, arguments);
|
||||
|
||||
if (config.stream instanceof nodeStreams.Writable) {
|
||||
this.stream = config.stream;
|
||||
} else {
|
||||
throw new TypeError('Invalid stream, use an instance of stream.Writeable');
|
||||
}
|
||||
}
|
||||
_.inherits(Stream, LoggerAbstract);
|
||||
|
||||
Stream.prototype.write = function (label, message) {
|
||||
this.stream.write(this.format(label, message), 'utf8');
|
||||
};
|
||||
|
||||
Stream.prototype.close = function () {
|
||||
this.stream.end();
|
||||
};
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
var Log = require('../log')
|
||||
, _ = require('../toolbelt');
|
||||
|
||||
function LogAbstract(config, bridge) {
|
||||
|
||||
this.bridge = bridge;
|
||||
this.listeningLevels = [];
|
||||
|
||||
// bound copies of the event handlers
|
||||
this.handlers = _.reduce(Log.levels, function (handlers, name) {
|
||||
handlers[name] = _.bindKey(this, 'on' + _.studlyCase(name));
|
||||
return handlers;
|
||||
}, {}, this);
|
||||
|
||||
// then the bridge closes, remove our event listeners
|
||||
this.bridge.on('closing', _.bindKey(this, 'cleanUpListeners'));
|
||||
|
||||
this.setupListeners(config.levels);
|
||||
}
|
||||
|
||||
function padNumToTen(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a timestamp string used in the format function. Defers to Log.timestamp if it is defined,
|
||||
* Also, feel free to override this at the logger level.
|
||||
* @return {String} - Timestamp in ISO 8601 UTC
|
||||
*/
|
||||
LogAbstract.prototype.timestamp = function () {
|
||||
var d = new Date();
|
||||
return d.getUTCFullYear() + '-' +
|
||||
padNumToTen(d.getUTCMonth() + 1) + '-' +
|
||||
padNumToTen(d.getUTCDate()) + 'T' +
|
||||
padNumToTen(d.getUTCHours()) + ':' +
|
||||
padNumToTen(d.getUTCMinutes()) + ':' +
|
||||
padNumToTen(d.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
function indent(test, spaces) {
|
||||
var space = _.repeat(' ', spaces || 2);
|
||||
return test.split(/\r?\n/).map(function (line) {
|
||||
return space + line;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
LogAbstract.prototype.format = function (label, message) {
|
||||
return label + ': ' + this.timestamp() + '\n' + indent(message) + '\n\n';
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners and then re-listen for events based on the level specified
|
||||
*
|
||||
* @method setupListeners
|
||||
* @private
|
||||
* @param {Integer} level - The max log level that this logger should listen to
|
||||
* @return {undefined}
|
||||
*/
|
||||
LogAbstract.prototype.setupListeners = function (levels) {
|
||||
this.cleanUpListeners();
|
||||
|
||||
this.listeningLevels = levels;
|
||||
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.on(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners
|
||||
*
|
||||
* @method cleanUpListeners
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
LogAbstract.prototype.cleanUpListeners = function () {
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.removeListener(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
|
||||
module.exports = LogAbstract;
|
||||
@ -1,4 +1,4 @@
|
||||
var _ = require('./toolbelt');
|
||||
var _ = require('./utils');
|
||||
|
||||
exports.bulkBody = function (val, serializer) {
|
||||
var body = '', i;
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
var _ = require('../toolbelt');
|
||||
module.exports = RandomSelect;
|
||||
|
||||
function RandomSelect(connections) {
|
||||
return _.shuffle(connections).unshift();
|
||||
return connections[Math.floor(Math.random() * connections.length)];
|
||||
}
|
||||
|
||||
module.exports = RandomSelect;
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
/**
|
||||
* Selects a connection the simplest way possible, Round Robin
|
||||
*
|
||||
* @class selector.roundRobin
|
||||
* @constructor
|
||||
* @type {Function}
|
||||
*/
|
||||
module.exports = RoundRobinSelect;
|
||||
|
||||
function RoundRobinSelect(connections) {
|
||||
connections.unshift(connections.pop());
|
||||
return connections[0];
|
||||
}
|
||||
|
||||
module.exports = RoundRobinSelect;
|
||||
@ -1,6 +1,10 @@
|
||||
/* JSON serializer */
|
||||
/**
|
||||
* Simple JSON serializer
|
||||
* @type {[type]}
|
||||
*/
|
||||
module.exports = Json;
|
||||
|
||||
var _ = require('../toolbelt');
|
||||
var _ = require('../utils');
|
||||
|
||||
function Json(client) {
|
||||
this.client = client;
|
||||
@ -11,13 +15,21 @@ Json.prototype.serialize = function (val, replacer, spaces) {
|
||||
return null;
|
||||
}
|
||||
else if (typeof val === 'string') {
|
||||
this.client.log.info('body is already a string, not encoding');
|
||||
return val;
|
||||
} else {
|
||||
return JSON.stringify(val, replacer, spaces);
|
||||
}
|
||||
};
|
||||
|
||||
Json.prototype.unserialize = _.bind(JSON.parse, JSON);
|
||||
|
||||
module.exports = Json;
|
||||
Json.prototype.unserialize = function (str) {
|
||||
if (typeof str === 'string') {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
this.client.log.error(new Error('unable to parse', str));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
/* JSON serializer */
|
||||
|
||||
var _ = require('lodash');
|
||||
|
||||
function QueryString() {}
|
||||
|
||||
QueryString.prototype.serialize = function (obj) {
|
||||
return JSON.stringify(obj);
|
||||
};
|
||||
|
||||
// TODO: real query string parsing... there is a well tested module for this :P
|
||||
QueryString.prototype.unserialize = function (string) {
|
||||
return _.object(_.map(_.map(string.split('&'), function splitOnEqlAndDecode(string) {
|
||||
return _.map(string.split('='), decodeURIComponent);
|
||||
})));
|
||||
};
|
||||
module.exports = QueryString;
|
||||
1
src/lib/transports/angular_http.js
vendored
1
src/lib/transports/angular_http.js
vendored
@ -1 +0,0 @@
|
||||
/* angular.js transport client for elasticsearch-js */
|
||||
9
src/lib/transports/jquery_xhr.js
vendored
9
src/lib/transports/jquery_xhr.js
vendored
@ -1,9 +0,0 @@
|
||||
/**
|
||||
* Transport class for making HTTP requests using jQuery's ajax methods
|
||||
*
|
||||
* @class jQueryXhr
|
||||
* @constructor
|
||||
*/
|
||||
function jQueryXhr() {
|
||||
|
||||
}
|
||||
@ -1,109 +0,0 @@
|
||||
/* elasticsearch-js nodejs transport */
|
||||
var http = require('http')
|
||||
, _ = require('../toolbelt')
|
||||
, url = require('url')
|
||||
, Q = require('q');
|
||||
|
||||
/**
|
||||
* Http transport to use in Node.js
|
||||
*
|
||||
* @class NodeHttp
|
||||
*/
|
||||
function NodeHttp(hosts, client) {
|
||||
this.hosts = _.map(hosts, function (host) {
|
||||
if (!~host.indexOf('//')) {
|
||||
host = '//' + host;
|
||||
}
|
||||
return _.pick(url.parse(host, false, true), ['hostname', 'port']);
|
||||
});
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
NodeHttp.prototype.request = function (params) {
|
||||
var deferred = Q.defer()
|
||||
, req = _.extend(
|
||||
url.parse(params.url, false, false),
|
||||
this.hosts[Math.round(Math.random() * (this.hosts.length - 1))]
|
||||
);
|
||||
|
||||
// we need to have a method
|
||||
req.method = params.method || (params.body ? 'post' : 'get');
|
||||
|
||||
// ensure that get isn't being used with a request body
|
||||
if (params.body && req.method.toLowerCase() === 'get') {
|
||||
deferred.reject(new TypeError('HTTP Method GET can not have a body'));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
var request = http.request(req, function (res) {
|
||||
var response = {
|
||||
data : '',
|
||||
headers : res.headers,
|
||||
status : res.statusCode
|
||||
};
|
||||
|
||||
res.setEncoding('utf8');
|
||||
|
||||
res.on('data', function (d) {
|
||||
response.data += d;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
this.client.log.trace(req.method, req, params.body, response.status, response.data);
|
||||
|
||||
// attempt to parse the response
|
||||
if (response.data) {
|
||||
try {
|
||||
response.data = JSON.parse(response.data);
|
||||
} catch (e) {
|
||||
response.error = new TypeError('Non-valid JSON reponse from Elasticsearch');
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.error && response.status >= 400) {
|
||||
response.error = new Error(errorMessage(response));
|
||||
response.error.status = response.status;
|
||||
}
|
||||
|
||||
if (response.error) {
|
||||
if (_.contains(params.ignore, response.status)) {
|
||||
deferred.resolve(false, response);
|
||||
} else {
|
||||
// reject with error
|
||||
deferred.reject(response.error, response);
|
||||
}
|
||||
} else {
|
||||
// we're done
|
||||
deferred.resolve(req.method === 'head' ? true : response.data, response);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
}.bind(this));
|
||||
|
||||
request.on('error', function (err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
if (params.body) {
|
||||
request.write(params.body);
|
||||
}
|
||||
|
||||
request.end();
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
function errorMessage(response) {
|
||||
if (response.data.error) {
|
||||
return response.data.error;
|
||||
} else {
|
||||
switch (response.status) {
|
||||
case 404:
|
||||
return 'Not Found';
|
||||
default:
|
||||
return response.status + ' - Unkown Error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NodeHttp;
|
||||
@ -1,13 +1,14 @@
|
||||
var path = require('path')
|
||||
, _ = require('lodash')
|
||||
, fs = require('fs')
|
||||
, requireDir = require('require-directory')
|
||||
, qs = require('qs')
|
||||
, nodeUtils = require('util');
|
||||
var path = require('path'),
|
||||
_ = require('lodash'),
|
||||
fs = require('fs'),
|
||||
requireDir = require('require-directory'),
|
||||
qs = require('qs'),
|
||||
url = require('url'),
|
||||
nodeUtils = require('util');
|
||||
|
||||
/**
|
||||
* Custom utils library, basically a modified version of [lodash](http://lodash.com/docs) +
|
||||
* [node.uitls](http://nodejs.org/api/util.html#util_util) that doesn't use mixins to prevent
|
||||
* [node.utils](http://nodejs.org/api/util.html#util_util) that doesn't use mixins to prevent
|
||||
* confusion when requiring lodash itself.
|
||||
*
|
||||
* @class utils
|
||||
@ -33,11 +34,11 @@ utils.inspect = function (thing, opts) {
|
||||
utils.joinPath = path.join;
|
||||
|
||||
/**
|
||||
* Extends lodash's map function so that objects can be passed to map and will be retuned as an object with
|
||||
* each value transformed by the itterator.
|
||||
* Extends lodash's map function so that objects can be passed to map and will be returned as an object with
|
||||
* each value transformed by the iterator.
|
||||
*
|
||||
* @method utils.map
|
||||
* @param [Iterable] obj - the thing to iterate over
|
||||
* @param [Collection] obj - the thing to iterate over
|
||||
* @param [Function] mapper - the function to call for each element in obj
|
||||
* @param [*] context - the this context to use for each call to mapper
|
||||
*/
|
||||
@ -53,7 +54,7 @@ utils.map = function (obj, mapper, context) {
|
||||
* Require all of the modules in a directory
|
||||
*
|
||||
* @method requireDir
|
||||
* @param {Module} module - The module object which will own the required modules.
|
||||
* @param {Function} module - The module object which will own the required modules.
|
||||
* @param {String} path - Path to the directory which will be traversed (can be relative to module)
|
||||
* @return {Object} - An object with each required files
|
||||
*/
|
||||
@ -67,9 +68,9 @@ utils.requireDir = function (module, dirPath) {
|
||||
/**
|
||||
* Requires all of the files in a directory, then transforms the filenames into
|
||||
* StudlyCase -- one level deep for now.
|
||||
* @param {Module} module - The module object which will own the required modules.
|
||||
* @param {String} path - Path to the directory which will be traversed (can be relative to module)
|
||||
* @return {Object} - An object with each required files, keys will be the StudlyCase version of the filesnames.
|
||||
* @param {Function} module - The module object which will own the required modules.
|
||||
* @param {String} dirPath - Path to the directory which will be traversed (can be relative to module)
|
||||
* @return {Object} - An object with each required files, keys will be the StudlyCase version of the filenames.
|
||||
*/
|
||||
utils.requireClasses = function (module, dirPath) {
|
||||
return utils.reKey(utils.requireDir(module, dirPath), utils.studlyCase, false);
|
||||
@ -79,7 +80,7 @@ utils.requireClasses = function (module, dirPath) {
|
||||
* Recursively re-key an object, applying "transform" to each key
|
||||
* @param {Object} obj - The object to re-key
|
||||
* @param {Function} transform - The transformation function to apply to each key
|
||||
* @param {Boolean} recursive - Should this act recursively?
|
||||
* @param {Boolean} [recursive=false] - Should this act recursively?
|
||||
* @param {Object} out - used primarily for recursion, allows you to specify the object which new keys will be written to
|
||||
* @return {Object}
|
||||
*/
|
||||
@ -102,11 +103,11 @@ utils.reKey = function (obj, transform, recursive) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Recursively merge two objects, walking into each object and concating arrays.
|
||||
* If both to and from have a value at a key, but the values' types don't match
|
||||
* to's value is left unmodified. Only Array and Object values are merged - that
|
||||
* Recursively merge two objects, walking into each object and concating arrays. If both to and from have a value at a
|
||||
* key, but the values' types don't match to's value is left unmodified. Only Array and Object values are merged - that
|
||||
* it to say values with a typeof "object"
|
||||
* @param {Obejct} to - Object to merge into (no cloning, the original object
|
||||
*
|
||||
* @param {Object} to - Object to merge into (no cloning, the original object
|
||||
* is modified)
|
||||
* @param {Object} from - Object to pull changed from
|
||||
* @return {Object} - returns the modified to value
|
||||
@ -132,18 +133,16 @@ utils.deepMerge = function (to, from) {
|
||||
/**
|
||||
* Test if a value is an array and it's contents are of a specific type
|
||||
*
|
||||
* @method isArrayOf<Strings|Objects|Arrays|Finites|Functions|RegExps>
|
||||
* @method isArrayOf<Strings|Object|Array|Finite|Function|RegExp>s
|
||||
* @param {Array} arr - An array to check
|
||||
* @return {Boolean}
|
||||
*/
|
||||
'String Object PlainObject Array Finite Function RegExp'.split(' ').forEach(function (type) {
|
||||
var check = _.bind(_['is' + type], _)
|
||||
// used to find the first value that isn't of the sub type specified
|
||||
, checkForNotType = function (val) { return !check(val); };
|
||||
var check = _.bind(_['is' + type], _);
|
||||
|
||||
utils['isArrayOf' + type + 's'] = function (arr) {
|
||||
// quick shallow check of arrays
|
||||
return _.isArray(arr) && !_.find(arr.slice(0, 10), checkForNotType);
|
||||
return _.isArray(arr) && _.every(arr.slice(0, 10), check);
|
||||
};
|
||||
});
|
||||
|
||||
@ -175,7 +174,7 @@ utils.studlyCase = function (string) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Transfor a string into camelCase
|
||||
* Transform a string into camelCase
|
||||
*
|
||||
* @todo Tests
|
||||
* @method cameCase
|
||||
@ -192,6 +191,13 @@ utils.camelCase = function (string) {
|
||||
}).join('');
|
||||
};
|
||||
|
||||
/**
|
||||
* Lower-case a string, and return an empty string if any is not a string
|
||||
*
|
||||
* @todo Tests
|
||||
* @param any {*} - Something or nothing
|
||||
* @returns {string}
|
||||
*/
|
||||
utils.toLowerString = function (any) {
|
||||
if (any) {
|
||||
if (typeof any !== 'string') {
|
||||
@ -203,10 +209,28 @@ utils.toLowerString = function (any) {
|
||||
return any.toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Upper-case the string, return an empty string if any is not a string
|
||||
*
|
||||
* @todo Tests
|
||||
* @param any {*} - Something or nothing
|
||||
* @returns {string}
|
||||
*/
|
||||
utils.toUpperString = function (any) {
|
||||
if (any) {
|
||||
if (typeof any !== 'string') {
|
||||
any = any.toString();
|
||||
}
|
||||
} else {
|
||||
any = '';
|
||||
}
|
||||
return any.toUpperCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if a value is "numeric" meaning that it can be transformed into something besides NaN
|
||||
*
|
||||
* @todo Test
|
||||
* @todo Tests
|
||||
* @method isNumeric
|
||||
* @param {*} val
|
||||
* @return {Boolean}
|
||||
@ -257,13 +281,39 @@ utils.makeQueryString = function (obj, start) {
|
||||
return (start === false || str === '') ? str : '?' + str;
|
||||
};
|
||||
|
||||
/**
|
||||
* Override node's util.inherits function to also supply a callSuper function on the child class that can be called
|
||||
* with the instance and the arguments passed to the child's constructor. This should only be called from within the
|
||||
* constructor of the child class and should be removed from the code once the constructor is "done".
|
||||
*
|
||||
* @param constructor {Function} - the constructor that should subClass superConstructor
|
||||
* @param superConstructor {Function} - The parent constructor
|
||||
*/
|
||||
utils.inherits = function (constructor, superConstructor) {
|
||||
nodeUtils.inherits(constructor, superConstructor);
|
||||
constructor.prototype._constructSuper = function (args) {
|
||||
constructor.super_.apply(this, _.toArray(args));
|
||||
constructor.callSuper = function (inst, args) {
|
||||
if (args) {
|
||||
if (_.isArguments(args)) {
|
||||
utils.applyArgs(superConstructor, inst, args);
|
||||
} else {
|
||||
utils.applyArgs(superConstructor, inst, arguments, 1);
|
||||
}
|
||||
} else {
|
||||
superConstructor.call(inst);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove leading/trailing spaces from a string
|
||||
*
|
||||
* @param str {String} - Any string
|
||||
* @returns {String}
|
||||
*/
|
||||
utils.trim = function (str) {
|
||||
return typeof str !== 'string' ? str.replace(/^\s+|\s+$/g, '') : '';
|
||||
};
|
||||
|
||||
utils.collectMatches = function (text, regExp) {
|
||||
var matches = [], match;
|
||||
while (match = regExp.exec(text)) {
|
||||
@ -276,4 +326,86 @@ utils.collectMatches = function (text, regExp) {
|
||||
return matches;
|
||||
};
|
||||
|
||||
var startsWithProtocolRE = /^([a-z]+:)?\/\//;
|
||||
|
||||
/**
|
||||
* Runs a string through node's url.parse, removing the return value's host property and insuring the text has a
|
||||
* protocol first
|
||||
*
|
||||
* @todo Tests
|
||||
* @param urlString {String} - a url of some sort
|
||||
* @returns {Object} - an object containing 'hostname', 'port', 'protocol', 'path', and a few other keys
|
||||
*/
|
||||
utils.parseUrl = function (urlString) {
|
||||
if (!startsWithProtocolRE.text(urlString)) {
|
||||
urlString = 'http://' + urlString;
|
||||
}
|
||||
var info = url.parse(urlString);
|
||||
delete info.host;
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats a urlinfo object, sort of juggling the 'host' and 'hostname' keys based on the presense of the port and
|
||||
* including http: as the default protocol.
|
||||
*
|
||||
* @todo Tests,
|
||||
* @todo add checking for ':' at the end of the protocol
|
||||
* @param urlInfo {Object} - An object, similar to that returned from _.parseUrl
|
||||
* @returns {String}
|
||||
*/
|
||||
utils.formatUrl = function (urlInfo) {
|
||||
var info = _.clone(urlInfo);
|
||||
if (info.port && info.host && !info.hostname) {
|
||||
info.hostname = info.host;
|
||||
delete info.host;
|
||||
}
|
||||
if (!info.protocol) {
|
||||
info.protocol = 'http:';
|
||||
}
|
||||
return url.format(info);
|
||||
};
|
||||
|
||||
/**
|
||||
* Call a function, applying the arguments object to it in an optimized way, rather than always turning it into an array
|
||||
*
|
||||
* @param func {Function} - The function to execute
|
||||
* @param context {*} - The context the function will be executed with
|
||||
* @param args {Arguments} - The arguments to send to func
|
||||
* @param [sliceIndex=0] {Integer} - The index that args should be sliced at, before feeding args to func
|
||||
* @returns {*} - the return value of func
|
||||
*/
|
||||
utils.applyArgs = function (func, context, args, sliceIndex) {
|
||||
sliceIndex = sliceIndex || 0;
|
||||
switch (args.length - sliceIndex) {
|
||||
case 0:
|
||||
return func.call(context);
|
||||
case 1:
|
||||
return func.call(context, args[0 + sliceIndex]);
|
||||
case 2:
|
||||
return func.call(context, args[0 + sliceIndex], args[1 + sliceIndex]);
|
||||
case 3:
|
||||
return func.call(context, args[0 + sliceIndex], args[1 + sliceIndex], args[2 + sliceIndex]);
|
||||
case 4:
|
||||
return func.call(context, args[0 + sliceIndex], args[1 + sliceIndex], args[2 + sliceIndex], args[3 + sliceIndex]);
|
||||
case 5:
|
||||
return func.call(context, args[0 + sliceIndex], args[1 + sliceIndex],
|
||||
args[2 + sliceIndex], args[3 + sliceIndex], args[4 + sliceIndex]);
|
||||
default:
|
||||
return func.apply(context, Array.prototype.slice.call(args, sliceIndex));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Schedule a function to be called on the next tick, and supply it with these arguments
|
||||
* when it is called.
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
utils.nextTick = function (cb) {
|
||||
// bind the function and schedule it
|
||||
process.nextTick(utils.bindKey(utils, 'applyArgs', cb, null, arguments, 1));
|
||||
};
|
||||
|
||||
utils.noop = function () {};
|
||||
|
||||
module.exports = utils;
|
||||
Reference in New Issue
Block a user