Refactored the API, moving it into a single api.js file which can be
exluded from a build if desired.
This commit is contained in:
@ -1,4 +0,0 @@
|
||||
{
|
||||
"extends": "../../.jshintrc",
|
||||
"maxlen": 0
|
||||
}
|
||||
124
src/api/bulk.js
124
src/api/bulk.js
@ -1,124 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method bulk
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.consistency - Explicit write consistency setting for the operation
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: this.client.config.serializer.bulkBody(params.body || null)
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && 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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_bulk';
|
||||
delete params.type;
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_bulk';
|
||||
}
|
||||
else {
|
||||
request.path = '/_bulk';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
query.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doBulk;
|
||||
@ -1,65 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [clear_scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method clear_scroll
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClearScroll(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
switch (typeof params.scroll_id) {
|
||||
case 'string':
|
||||
parts.scroll_id = params.scroll_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.scroll_id)) {
|
||||
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:
|
||||
parts.scroll_id = !!params.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 path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClearScroll;
|
||||
@ -1,44 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.get_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterGetSettings(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterGetSettings;
|
||||
@ -1,142 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.health
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} [params.level=cluster] - Specify the level of detail for returned information
|
||||
* @param {boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
|
||||
* @param {Date|Number} params.master_timeout - Explicit operation timeout for connection to master node
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {number} params.wait_for_active_shards - Wait until the specified number of shards is active
|
||||
* @param {string} params.wait_for_nodes - Wait until the specified number of nodes is available
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/_cluster/health/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.path = '/_cluster/health';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.level !== 'undefined') {
|
||||
if (_.contains(levelOptions, params.level)) {
|
||||
query.level = params.level;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid level: ' + params.level +
|
||||
' should be one of ' + levelOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.local !== 'undefined') {
|
||||
if (params.local.toLowerCase && (params.local = params.local.toLowerCase())
|
||||
&& (params.local === 'no' || params.local === 'off')
|
||||
) {
|
||||
query.local = false;
|
||||
} else {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid wait_for_status: ' + params.wait_for_status +
|
||||
' should be one of ' + waitForStatusOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterHealth;
|
||||
@ -1,107 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.node_hot_threads
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.interval - The interval for the second sampling of threads
|
||||
* @param {number} params.snapshots - Number of samples of thread stacktrace (default: 10)
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
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:
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/hotthreads';
|
||||
}
|
||||
else {
|
||||
request.path = '/_nodes/hotthreads';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.interval !== 'undefined') {
|
||||
if (params.interval instanceof Date) {
|
||||
query.interval = params.interval.getTime();
|
||||
} else if (_.isNumeric(params.interval)) {
|
||||
query.interval = params.interval;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid type: ' + params.type +
|
||||
' should be one of ' + typeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeHotThreads;
|
||||
@ -1,196 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.node_info
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.all - Return all available information
|
||||
* @param {boolean} params.clear - Reset the default settings
|
||||
* @param {boolean} params.http - Return information about HTTP
|
||||
* @param {boolean} params.jvm - Return information about the JVM
|
||||
* @param {boolean} params.network - Return information about network
|
||||
* @param {boolean} params.os - Return information about the operating system
|
||||
* @param {boolean} params.plugin - Return information about plugins
|
||||
* @param {boolean} params.process - Return information about the Elasticsearch process
|
||||
* @param {boolean} params.settings - Return information about node settings
|
||||
* @param {boolean} params.thread_pool - Return information about the thread pool
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeInfo(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
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:
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '';
|
||||
}
|
||||
else {
|
||||
request.path = '/_nodes';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
if (params.all.toLowerCase && (params.all = params.all.toLowerCase())
|
||||
&& (params.all === 'no' || params.all === 'off')
|
||||
) {
|
||||
query.all = false;
|
||||
} else {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
) {
|
||||
query.clear = false;
|
||||
} else {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
) {
|
||||
query.http = false;
|
||||
} else {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
) {
|
||||
query.jvm = false;
|
||||
} else {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
) {
|
||||
query.network = false;
|
||||
} else {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
) {
|
||||
query.os = false;
|
||||
} else {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.plugin !== 'undefined') {
|
||||
if (params.plugin.toLowerCase && (params.plugin = params.plugin.toLowerCase())
|
||||
&& (params.plugin === 'no' || params.plugin === 'off')
|
||||
) {
|
||||
query.plugin = false;
|
||||
} else {
|
||||
query.plugin = !!params.plugin;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
) {
|
||||
query.process = false;
|
||||
} else {
|
||||
query.process = !!params.process;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.settings !== 'undefined') {
|
||||
if (params.settings.toLowerCase && (params.settings = params.settings.toLowerCase())
|
||||
&& (params.settings === 'no' || params.settings === 'off')
|
||||
) {
|
||||
query.settings = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.thread_pool = false;
|
||||
} else {
|
||||
query.thread_pool = !!params.thread_pool;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.transport = false;
|
||||
} else {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeInfo;
|
||||
@ -1,86 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.node_shutdown
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
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:
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_cluster/nodes/' + encodeURIComponent(parts.node_id) + '/_shutdown';
|
||||
}
|
||||
else {
|
||||
request.path = '/_shutdown';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.delay !== 'undefined') {
|
||||
if (params.delay instanceof Date) {
|
||||
query.delay = params.delay.getTime();
|
||||
} else if (_.isNumeric(params.delay)) {
|
||||
query.delay = params.delay;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.exit = false;
|
||||
} else {
|
||||
query.exit = !!params.exit;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeShutdown;
|
||||
@ -1,245 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.node_stats
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.all - Return all available information
|
||||
* @param {boolean} params.clear - Reset the default level of detail
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields for `fielddata` metric (supports wildcards)
|
||||
* @param {boolean} params.fs - Return information about the filesystem
|
||||
* @param {boolean} params.http - Return information about HTTP
|
||||
* @param {boolean} params.indices - Return information about indices
|
||||
* @param {boolean} params.jvm - Return information about the JVM
|
||||
* @param {boolean} params.network - Return information about network
|
||||
* @param {boolean} params.os - Return information about the operating system
|
||||
* @param {boolean} params.process - Return information about the Elasticsearch process
|
||||
* @param {boolean} params.thread_pool - Return information about the thread pool
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeStats(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
' should be one of ' + metricFamilyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.metric !== 'undefined') {
|
||||
if (_.contains(metricOptions, params.metric)) {
|
||||
parts.metric = params.metric;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric: ' + params.metric +
|
||||
' should be one of ' + metricOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
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:
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/stats';
|
||||
}
|
||||
else {
|
||||
request.path = '/_nodes/stats';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
if (params.all.toLowerCase && (params.all = params.all.toLowerCase())
|
||||
&& (params.all === 'no' || params.all === 'off')
|
||||
) {
|
||||
query.all = false;
|
||||
} else {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
) {
|
||||
query.clear = false;
|
||||
} else {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fs !== 'undefined') {
|
||||
if (params.fs.toLowerCase && (params.fs = params.fs.toLowerCase())
|
||||
&& (params.fs === 'no' || params.fs === 'off')
|
||||
) {
|
||||
query.fs = false;
|
||||
} else {
|
||||
query.fs = !!params.fs;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
) {
|
||||
query.http = false;
|
||||
} else {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.indices !== 'undefined') {
|
||||
if (params.indices.toLowerCase && (params.indices = params.indices.toLowerCase())
|
||||
&& (params.indices === 'no' || params.indices === 'off')
|
||||
) {
|
||||
query.indices = false;
|
||||
} else {
|
||||
query.indices = !!params.indices;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
) {
|
||||
query.jvm = false;
|
||||
} else {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
) {
|
||||
query.network = false;
|
||||
} else {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
) {
|
||||
query.os = false;
|
||||
} else {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
) {
|
||||
query.process = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.thread_pool = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.transport = false;
|
||||
} else {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeStats;
|
||||
@ -1,45 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.put_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.put_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterPutSettings(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'PUT'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterPutSettings;
|
||||
@ -1,66 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.reroute](http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.reroute
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/reroute';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.dry_run !== 'undefined') {
|
||||
if (params.dry_run.toLowerCase && (params.dry_run = params.dry_run.toLowerCase())
|
||||
&& (params.dry_run === 'no' || params.dry_run === 'off')
|
||||
) {
|
||||
query.dry_run = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_metadata = false;
|
||||
} else {
|
||||
query.filter_metadata = !!params.filter_metadata;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterReroute;
|
||||
@ -1,138 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.state](http://elasticsearch.org/guide/reference/api/admin-cluster-state/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.state
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.filter_blocks - Do not return information about blocks
|
||||
* @param {boolean} params.filter_index_templates - Do not return information about index templates
|
||||
* @param {String|ArrayOfStrings|Boolean} params.filter_indices - Limit returned metadata information to specific indices
|
||||
* @param {boolean} params.filter_metadata - Do not return information about indices metadata
|
||||
* @param {boolean} params.filter_nodes - Do not return information about nodes
|
||||
* @param {boolean} params.filter_routing_table - Do not return information about shard allocation (`routing_table` and `routing_nodes`)
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/state';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.filter_blocks !== 'undefined') {
|
||||
if (params.filter_blocks.toLowerCase && (params.filter_blocks = params.filter_blocks.toLowerCase())
|
||||
&& (params.filter_blocks === 'no' || params.filter_blocks === 'off')
|
||||
) {
|
||||
query.filter_blocks = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_index_templates = false;
|
||||
} else {
|
||||
query.filter_index_templates = !!params.filter_index_templates;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.filter_indices !== 'undefined') {
|
||||
switch (typeof params.filter_indices) {
|
||||
case 'string':
|
||||
query.filter_indices = params.filter_indices;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.filter_indices)) {
|
||||
query.filter_indices = params.filter_indices.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid filter_indices: ' + params.filter_indices + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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')
|
||||
) {
|
||||
query.filter_metadata = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_nodes = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_routing_table = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.local = false;
|
||||
} else {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterState;
|
||||
144
src/api/count.js
144
src/api/count.js
@ -1,144 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [count](http://elasticsearch.org/guide/reference/api/count/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method count
|
||||
* @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
|
||||
* @param {number} params.min_score - Include only documents with a specific `_score` value in the result
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_count';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_count';
|
||||
}
|
||||
else {
|
||||
request.path = '/_count';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.min_score !== 'undefined') {
|
||||
if (_.isNumeric(params.min_score)) {
|
||||
query.min_score = params.min_score * 1;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCount;
|
||||
@ -1,208 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method create
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.consistency - Explicit write consistency setting for the operation
|
||||
* @param {string} params.id - Specific document ID (when the POST method is used)
|
||||
* @param {string} params.parent - ID of the parent document
|
||||
* @param {string} params.percolate - Percolator queries to execute while indexing the document
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
* @param {String} [params.replication=sync] - Specific replication type
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.timestamp - Explicit timestamp for the document
|
||||
* @param {duration} params.ttl - Expiration time for the document
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doCreate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
query.id = '' + params.id;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timestamp)) {
|
||||
query.timestamp = params.timestamp;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid version_type: ' + params.version_type +
|
||||
' should be one of ' + versionTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCreate;
|
||||
@ -1,154 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method delete
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.consistency - Specific write consistency setting for the operation
|
||||
* @param {string} params.parent - ID of parent document
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
* @param {String} [params.replication=sync] - Specific replication type
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doDelete(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid version_type: ' + params.version_type +
|
||||
' should be one of ' + versionTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDelete;
|
||||
@ -1,192 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method delete_by_query
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {string} params.analyzer - The analyzer to use for the query string
|
||||
* @param {String} params.consistency - Specific write consistency setting for the operation
|
||||
* @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR)
|
||||
* @param {string} params.df - The field to use as default where no field prefix is given in the query string
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {String} [params.replication=sync] - Specific replication type
|
||||
* @param {string} params.q - Query in the Lucene query string syntax
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_query';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_query';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid default_operator: ' + params.default_operator +
|
||||
' should be one of ' + defaultOperatorOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDeleteByQuery;
|
||||
@ -1,122 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [exists](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method exists
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {string} params.parent - The ID of the parent document
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doExists(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore),
|
||||
method: 'HEAD'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.realtime = false;
|
||||
} else {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
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,257 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [explain](http://elasticsearch.org/guide/reference/api/explain/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method explain
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.analyze_wildcard - Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false)
|
||||
* @param {string} params.analyzer - The analyzer for the query string query
|
||||
* @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR)
|
||||
* @param {string} params.df - The default field for query string query (default: _all)
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response
|
||||
* @param {boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
|
||||
* @param {boolean} params.lowercase_expanded_terms - Specify whether query terms should be lowercased
|
||||
* @param {string} params.parent - The ID of the parent document
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {string} params.q - Query in the Lucene query string syntax
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query 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')
|
||||
) {
|
||||
query.analyze_wildcard = false;
|
||||
} else {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid default_operator: ' + params.default_operator +
|
||||
' should be one of ' + defaultOperatorOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
} else {
|
||||
throw new TypeError('Invalid df: ' + params.df + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.lenient !== 'undefined') {
|
||||
if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase())
|
||||
&& (params.lenient === 'no' || params.lenient === 'off')
|
||||
) {
|
||||
query.lenient = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.lowercase_expanded_terms = false;
|
||||
} else {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
query._source = params._source;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source)) {
|
||||
query._source = params._source.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
query._source_exclude = params._source_exclude;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_exclude)) {
|
||||
query._source_exclude = params._source_exclude.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
query._source_include = params._source_include;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_include)) {
|
||||
query._source_include = params._source_include.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doExplain;
|
||||
188
src/api/get.js
188
src/api/get.js
@ -1,188 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method get
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response
|
||||
* @param {string} params.parent - The ID of the parent document
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.realtime = false;
|
||||
} else {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
query._source = params._source;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source)) {
|
||||
query._source = params._source.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
query._source_exclude = params._source_exclude;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_exclude)) {
|
||||
query._source_exclude = params._source_exclude.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
query._source_include = params._source_include;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_include)) {
|
||||
query._source_include = params._source_include.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGet;
|
||||
@ -1,152 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get_source](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method get_source
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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
|
||||
* @param {string} params.parent - The ID of the parent document
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doGetSource(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
query._source_exclude = params._source_exclude;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_exclude)) {
|
||||
query._source_exclude = params._source_exclude.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
query._source_include = params._source_include;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_include)) {
|
||||
query._source_include = params._source_include.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.realtime = false;
|
||||
} else {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGetSource;
|
||||
211
src/api/index.js
211
src/api/index.js
@ -1,211 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method index
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.consistency - Explicit write consistency setting for the operation
|
||||
* @param {String} [params.op_type=index] - Explicit operation type
|
||||
* @param {string} params.parent - ID of the parent document
|
||||
* @param {string} params.percolate - Percolator queries to execute while indexing the document
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
* @param {String} [params.replication=sync] - Specific replication type
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.timestamp - Explicit timestamp for the document
|
||||
* @param {duration} params.ttl - Expiration time for the document
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doIndex(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.op_type !== 'undefined') {
|
||||
if (_.contains(opTypeOptions, params.op_type)) {
|
||||
query.op_type = params.op_type;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid op_type: ' + params.op_type +
|
||||
' should be one of ' + opTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timestamp)) {
|
||||
query.timestamp = params.timestamp;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid version_type: ' + params.version_type +
|
||||
' should be one of ' + versionTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndex;
|
||||
@ -1,154 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.analyze
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {string} params.analyzer - The name of the analyzer to use
|
||||
* @param {string} params.field - Use the analyzer configured for this field (instead of passing the analyzer name)
|
||||
* @param {String|ArrayOfStrings|Boolean} params.filters - A comma-separated list of filters to use for the analysis
|
||||
* @param {string} params.index - The name of the index to scope the operation
|
||||
* @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)
|
||||
* @param {string} params.text - The text on which the analysis should be performed (when request body is not used)
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_analyze';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.path = '/_analyze';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid field: ' + params.field + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.filters !== 'undefined') {
|
||||
switch (typeof params.filters) {
|
||||
case 'string':
|
||||
query.filters = params.filters;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.filters)) {
|
||||
query.filters = params.filters.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid filters: ' + params.filters + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.filters = !!params.filters;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
query.index = '' + params.index;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.prefer_local = false;
|
||||
} else {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.text !== 'undefined') {
|
||||
if (typeof params.text !== 'object' && params.text) {
|
||||
query.text = '' + params.text;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid format: ' + params.format +
|
||||
' should be one of ' + formatOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesAnalyze;
|
||||
@ -1,212 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.clear_cache
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.field_data - Clear field data
|
||||
* @param {boolean} params.fielddata - Clear field data
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to clear when using the `field_data` parameter (default: all)
|
||||
* @param {boolean} params.filter - Clear filter caches
|
||||
* @param {boolean} params.filter_cache - Clear filter caches
|
||||
* @param {boolean} params.filter_keys - A comma-separated list of keys to clear when using the `filter_cache` parameter (default: all)
|
||||
* @param {boolean} params.id - Clear ID caches for parent/child
|
||||
* @param {boolean} params.id_cache - Clear ID caches for parent/child
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_cache/clear';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.path = '/_cache/clear';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.field_data !== 'undefined') {
|
||||
if (params.field_data.toLowerCase && (params.field_data = params.field_data.toLowerCase())
|
||||
&& (params.field_data === 'no' || params.field_data === 'off')
|
||||
) {
|
||||
query.field_data = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.fielddata = false;
|
||||
} else {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.filter !== 'undefined') {
|
||||
if (params.filter.toLowerCase && (params.filter = params.filter.toLowerCase())
|
||||
&& (params.filter === 'no' || params.filter === 'off')
|
||||
) {
|
||||
query.filter = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_cache = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.filter_keys = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.id = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.id_cache = false;
|
||||
} else {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
query.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
query.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.recycler !== 'undefined') {
|
||||
if (params.recycler.toLowerCase && (params.recycler = params.recycler.toLowerCase())
|
||||
&& (params.recycler === 'no' || params.recycler === 'off')
|
||||
) {
|
||||
query.recycler = false;
|
||||
} else {
|
||||
query.recycler = !!params.recycler;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClearCache;
|
||||
@ -1,75 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.close
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesClose(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_close';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClose;
|
||||
@ -1,85 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.create
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesCreate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesCreate;
|
||||
@ -1,86 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.delete
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDelete(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.path = '/';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDelete;
|
||||
@ -1,81 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.delete_alias
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && 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) {
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteAlias;
|
||||
@ -1,79 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.delete_mapping
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteMapping;
|
||||
@ -1,75 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.delete_template
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteTemplate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteTemplate;
|
||||
@ -1,104 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.delete_warmer
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'DELETE'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && 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':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteWarmer;
|
||||
@ -1,69 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.exists
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesExists(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore),
|
||||
method: 'HEAD'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
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 = doIndicesExists;
|
||||
@ -1,102 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.exists_alias
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore),
|
||||
method: 'HEAD'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,97 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.exists_type
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore),
|
||||
method: 'HEAD'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.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 path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,120 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.flush
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.force - TODO: ?
|
||||
* @param {boolean} params.full - TODO: ?
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_flush';
|
||||
}
|
||||
else {
|
||||
request.path = '/_flush';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.force !== 'undefined') {
|
||||
if (params.force.toLowerCase && (params.force = params.force.toLowerCase())
|
||||
&& (params.force === 'no' || params.force === 'off')
|
||||
) {
|
||||
query.force = false;
|
||||
} else {
|
||||
query.force = !!params.force;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.full !== 'undefined') {
|
||||
if (params.full.toLowerCase && (params.full = params.full.toLowerCase())
|
||||
&& (params.full === 'no' || params.full === 'off')
|
||||
) {
|
||||
query.full = false;
|
||||
} else {
|
||||
query.full = !!params.full;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesFlush;
|
||||
@ -1,96 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_alias
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAlias;
|
||||
@ -1,75 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_aliases
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doIndicesGetAliases(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_aliases';
|
||||
}
|
||||
else {
|
||||
request.path = '/_aliases';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAliases;
|
||||
@ -1,85 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_mapping
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetMapping(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
request.path = '/_mapping';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetMapping;
|
||||
@ -1,65 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetSettings(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetSettings;
|
||||
@ -1,54 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_template
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetTemplate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetTemplate;
|
||||
@ -1,94 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.get_warmer
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetWarmer(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && 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':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetWarmer;
|
||||
@ -1,75 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.open
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesOpen(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_open';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOpen;
|
||||
@ -1,145 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.optimize
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.flush - Specify whether the index should be flushed after performing the operation (default: true)
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {number} params.max_num_segments - The number of segments the index should be merged into (default: dynamic)
|
||||
* @param {boolean} params.only_expunge_deletes - Specify whether the operation should only expunge deleted documents
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_optimize';
|
||||
}
|
||||
else {
|
||||
request.path = '/_optimize';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.flush !== 'undefined') {
|
||||
if (params.flush.toLowerCase && (params.flush = params.flush.toLowerCase())
|
||||
&& (params.flush === 'no' || params.flush === 'off')
|
||||
) {
|
||||
query.flush = false;
|
||||
} else {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.max_num_segments !== 'undefined') {
|
||||
if (_.isNumeric(params.max_num_segments)) {
|
||||
query.max_num_segments = params.max_num_segments * 1;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.only_expunge_deletes = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.wait_for_merge = false;
|
||||
} else {
|
||||
query.wait_for_merge = !!params.wait_for_merge;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOptimize;
|
||||
@ -1,88 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.put_alias
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'PUT'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && 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) {
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias';
|
||||
}
|
||||
else {
|
||||
request.path = '/_alias';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutAlias;
|
||||
@ -1,111 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.put_mapping
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.ignore_conflicts - Specify whether to ignore conflicts while updating the mapping (default: false)
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutMapping(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_conflicts !== 'undefined') {
|
||||
if (params.ignore_conflicts.toLowerCase && (params.ignore_conflicts = params.ignore_conflicts.toLowerCase())
|
||||
&& (params.ignore_conflicts === 'no' || params.ignore_conflicts === 'off')
|
||||
) {
|
||||
query.ignore_conflicts = false;
|
||||
} else {
|
||||
query.ignore_conflicts = !!params.ignore_conflicts;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutMapping;
|
||||
@ -1,76 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.put_settings
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'PUT'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutSettings;
|
||||
@ -1,94 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.put_template
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {number} params.order - The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutTemplate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (_.isNumeric(params.order)) {
|
||||
query.order = params.order * 1;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutTemplate;
|
||||
@ -1,100 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.put_warmer
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'PUT'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'object' && 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':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
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') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutWarmer;
|
||||
@ -1,92 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.refresh
|
||||
* @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
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesRefresh(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_refresh';
|
||||
}
|
||||
else {
|
||||
request.path = '/_refresh';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesRefresh;
|
||||
@ -1,83 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.segments
|
||||
* @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
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesSegments(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_segments';
|
||||
}
|
||||
else {
|
||||
request.path = '/_segments';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSegments;
|
||||
@ -1,78 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.snapshot_index
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_gateway/snapshot';
|
||||
}
|
||||
else {
|
||||
request.path = '/_gateway/snapshot';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSnapshotIndex;
|
||||
@ -1,371 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.stats
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.all - Return all available information
|
||||
* @param {boolean} params.clear - Reset the default level of detail
|
||||
* @param {boolean} params.completion - Return information about completion suggester stats
|
||||
* @param {String|ArrayOfStrings|Boolean} params.completion_fields - A comma-separated list of fields for `completion` metric (supports wildcards)
|
||||
* @param {boolean} params.docs - Return information about indexed and deleted documents
|
||||
* @param {boolean} params.fielddata - Return information about field data
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fielddata_fields - A comma-separated list of fields for `fielddata` metric (supports wildcards)
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields for `fielddata` and `completion` metric (supports wildcards)
|
||||
* @param {boolean} params.filter_cache - Return information about filter cache
|
||||
* @param {boolean} params.flush - Return information about flush operations
|
||||
* @param {boolean} params.get - Return information about get operations
|
||||
* @param {boolean} params.groups - A comma-separated list of search groups for `search` statistics
|
||||
* @param {boolean} params.id_cache - Return information about ID cache
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {boolean} params.indexing - Return information about indexing operations
|
||||
* @param {boolean} params.merge - Return information about merge operations
|
||||
* @param {boolean} params.refresh - Return information about refresh operations
|
||||
* @param {boolean} params.search - Return information about search operations; use the `groups` parameter to include information for specific search groups
|
||||
* @param {boolean} params.store - Return information about the size of the index
|
||||
* @param {boolean} params.warmer - Return information about warmers
|
||||
*/
|
||||
function doIndicesStats(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.indexing_types !== 'undefined') {
|
||||
switch (typeof params.indexing_types) {
|
||||
case 'string':
|
||||
parts.indexing_types = params.indexing_types;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.indexing_types)) {
|
||||
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:
|
||||
parts.indexing_types = !!params.indexing_types;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
' should be one of ' + metricFamilyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.search_groups !== 'undefined') {
|
||||
switch (typeof params.search_groups) {
|
||||
case 'string':
|
||||
parts.search_groups = params.search_groups;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_groups)) {
|
||||
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:
|
||||
parts.search_groups = !!params.search_groups;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_stats';
|
||||
}
|
||||
else {
|
||||
request.path = '/_stats';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
if (params.all.toLowerCase && (params.all = params.all.toLowerCase())
|
||||
&& (params.all === 'no' || params.all === 'off')
|
||||
) {
|
||||
query.all = false;
|
||||
} else {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
) {
|
||||
query.clear = false;
|
||||
} else {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.completion !== 'undefined') {
|
||||
if (params.completion.toLowerCase && (params.completion = params.completion.toLowerCase())
|
||||
&& (params.completion === 'no' || params.completion === 'off')
|
||||
) {
|
||||
query.completion = false;
|
||||
} else {
|
||||
query.completion = !!params.completion;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.completion_fields !== 'undefined') {
|
||||
switch (typeof params.completion_fields) {
|
||||
case 'string':
|
||||
query.completion_fields = params.completion_fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.completion_fields)) {
|
||||
query.completion_fields = params.completion_fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid completion_fields: ' + params.completion_fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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')
|
||||
) {
|
||||
query.docs = false;
|
||||
} else {
|
||||
query.docs = !!params.docs;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fielddata !== 'undefined') {
|
||||
if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase())
|
||||
&& (params.fielddata === 'no' || params.fielddata === 'off')
|
||||
) {
|
||||
query.fielddata = false;
|
||||
} else {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fielddata_fields !== 'undefined') {
|
||||
switch (typeof params.fielddata_fields) {
|
||||
case 'string':
|
||||
query.fielddata_fields = params.fielddata_fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fielddata_fields)) {
|
||||
query.fielddata_fields = params.fielddata_fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fielddata_fields: ' + params.fielddata_fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fielddata_fields = !!params.fielddata_fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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')
|
||||
) {
|
||||
query.filter_cache = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.flush = false;
|
||||
} else {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.get !== 'undefined') {
|
||||
if (params.get.toLowerCase && (params.get = params.get.toLowerCase())
|
||||
&& (params.get === 'no' || params.get === 'off')
|
||||
) {
|
||||
query.get = false;
|
||||
} else {
|
||||
query.get = !!params.get;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.groups !== 'undefined') {
|
||||
if (params.groups.toLowerCase && (params.groups = params.groups.toLowerCase())
|
||||
&& (params.groups === 'no' || params.groups === 'off')
|
||||
) {
|
||||
query.groups = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.id_cache = false;
|
||||
} else {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.indexing !== 'undefined') {
|
||||
if (params.indexing.toLowerCase && (params.indexing = params.indexing.toLowerCase())
|
||||
&& (params.indexing === 'no' || params.indexing === 'off')
|
||||
) {
|
||||
query.indexing = false;
|
||||
} else {
|
||||
query.indexing = !!params.indexing;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.merge !== 'undefined') {
|
||||
if (params.merge.toLowerCase && (params.merge = params.merge.toLowerCase())
|
||||
&& (params.merge === 'no' || params.merge === 'off')
|
||||
) {
|
||||
query.merge = false;
|
||||
} else {
|
||||
query.merge = !!params.merge;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.search !== 'undefined') {
|
||||
if (params.search.toLowerCase && (params.search = params.search.toLowerCase())
|
||||
&& (params.search === 'no' || params.search === 'off')
|
||||
) {
|
||||
query.search = false;
|
||||
} else {
|
||||
query.search = !!params.search;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.store !== 'undefined') {
|
||||
if (params.store.toLowerCase && (params.store = params.store.toLowerCase())
|
||||
&& (params.store === 'no' || params.store === 'off')
|
||||
) {
|
||||
query.store = false;
|
||||
} else {
|
||||
query.store = !!params.store;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.warmer !== 'undefined') {
|
||||
if (params.warmer.toLowerCase && (params.warmer = params.warmer.toLowerCase())
|
||||
&& (params.warmer === 'no' || params.warmer === 'off')
|
||||
) {
|
||||
query.warmer = false;
|
||||
} else {
|
||||
query.warmer = !!params.warmer;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStats;
|
||||
@ -1,105 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.status
|
||||
* @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
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
* @param {boolean} params.recovery - Return information about shard recovery
|
||||
* @param {boolean} params.snapshot - TODO: ?
|
||||
*/
|
||||
function doIndicesStatus(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
method: 'GET'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_status';
|
||||
}
|
||||
else {
|
||||
request.path = '/_status';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
) {
|
||||
query.recovery = false;
|
||||
} else {
|
||||
query.recovery = !!params.recovery;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.snapshot !== 'undefined') {
|
||||
if (params.snapshot.toLowerCase && (params.snapshot = params.snapshot.toLowerCase())
|
||||
&& (params.snapshot === 'no' || params.snapshot === 'off')
|
||||
) {
|
||||
query.snapshot = false;
|
||||
} else {
|
||||
query.snapshot = !!params.snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStatus;
|
||||
@ -1,82 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.update_aliases
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Request timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesUpdateAliases(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_aliases';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.master_timeout)) {
|
||||
query.master_timeout = params.master_timeout;
|
||||
} else {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesUpdateAliases;
|
||||
@ -1,142 +0,0 @@
|
||||
var _ = require('../../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.validate_query
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {boolean} params.explain - Return detailed information about the error
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_validate/query';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_validate/query';
|
||||
}
|
||||
else {
|
||||
request.path = '/_validate/query';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.explain !== 'undefined') {
|
||||
if (params.explain.toLowerCase && (params.explain = params.explain.toLowerCase())
|
||||
&& (params.explain === 'no' || params.explain === 'off')
|
||||
) {
|
||||
query.explain = false;
|
||||
} else {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesValidateQuery;
|
||||
@ -1,53 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [info](http://elasticsearch.org/guide/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method info
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doInfo(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'HEAD' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doInfo;
|
||||
179
src/api/mget.js
179
src/api/mget.js
@ -1,179 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method mget
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && 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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mget';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mget';
|
||||
}
|
||||
else {
|
||||
request.path = '/_mget';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.realtime = false;
|
||||
} else {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
query._source = params._source;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source)) {
|
||||
query._source = params._source.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
query._source_exclude = params._source_exclude;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_exclude)) {
|
||||
query._source_exclude = params._source_exclude.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
query._source_include = params._source_include;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_include)) {
|
||||
query._source_include = params._source_include.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMget;
|
||||
282
src/api/mlt.js
282
src/api/mlt.js
@ -1,282 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mlt](http://elasticsearch.org/guide/reference/api/more-like-this/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method mlt
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {number} params.boost_terms - The boost factor
|
||||
* @param {number} params.max_doc_freq - The word occurrence frequency as count: words with higher occurrence in the corpus will be ignored
|
||||
* @param {number} params.max_query_terms - The maximum query terms to be included in the generated query
|
||||
* @param {number} params.max_word_len - The minimum length of the word: longer words will be ignored
|
||||
* @param {number} params.min_doc_freq - The word occurrence frequency as count: words with lower occurrence in the corpus will be ignored
|
||||
* @param {number} params.min_term_freq - The term frequency as percent: terms with lower occurence in the source document will be ignored
|
||||
* @param {number} params.min_word_len - The minimum length of the word: shorter words will be ignored
|
||||
* @param {String|ArrayOfStrings|Boolean} params.mlt_fields - Specific fields to perform the query against
|
||||
* @param {number} params.percent_terms_to_match - How many terms have to match in order to consider the document a match (default: 0.3)
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {number} params.search_from - The offset from which to return results
|
||||
* @param {String|ArrayOfStrings|Boolean} params.search_indices - A comma-separated list of indices to perform the query against (default: the index containing the document)
|
||||
* @param {string} params.search_query_hint - The search query hint
|
||||
* @param {string} params.search_scroll - A scroll search request definition
|
||||
* @param {number} params.search_size - The number of documents to return (default: 10)
|
||||
* @param {string} params.search_source - A specific search request definition (instead of using the request body)
|
||||
* @param {string} params.search_type - Specific search type (eg. `dfs_then_fetch`, `count`, etc)
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.boost_terms !== 'undefined') {
|
||||
if (_.isNumeric(params.boost_terms)) {
|
||||
query.boost_terms = params.boost_terms * 1;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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':
|
||||
query.mlt_fields = params.mlt_fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.mlt_fields)) {
|
||||
query.mlt_fields = params.mlt_fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid mlt_fields: ' + params.mlt_fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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':
|
||||
query.search_indices = params.search_indices;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_indices)) {
|
||||
query.search_indices = params.search_indices.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid search_indices: ' + params.search_indices + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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':
|
||||
query.search_types = params.search_types;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_types)) {
|
||||
query.search_types = params.search_types.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid search_types: ' + params.search_types + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.search_types = !!params.search_types;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.stop_words !== 'undefined') {
|
||||
switch (typeof params.stop_words) {
|
||||
case 'string':
|
||||
query.stop_words = params.stop_words;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.stop_words)) {
|
||||
query.stop_words = params.stop_words.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid stop_words: ' + params.stop_words + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.stop_words = !!params.stop_words;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMlt;
|
||||
@ -1,108 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method msearch
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.search_type - Search operation type
|
||||
*/
|
||||
function doMsearch(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: this.client.config.serializer.bulkBody(params.body || null)
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_msearch';
|
||||
}
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_msearch';
|
||||
}
|
||||
else {
|
||||
request.path = '/_msearch';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
if (_.contains(searchTypeOptions, params.search_type)) {
|
||||
query.search_type = params.search_type;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid search_type: ' + params.search_type +
|
||||
' should be one of ' + searchTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMsearch;
|
||||
@ -1,80 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [percolate](http://elasticsearch.org/guide/reference/api/percolate/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method percolate
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && 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) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query 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')
|
||||
) {
|
||||
query.prefer_local = false;
|
||||
} else {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doPercolate;
|
||||
@ -1,84 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method scroll
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && 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 path
|
||||
if (parts.hasOwnProperty('scroll_id')) {
|
||||
request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + '';
|
||||
delete params.scroll_id;
|
||||
}
|
||||
else {
|
||||
request.path = '/_search/scroll';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doScroll;
|
||||
@ -1,453 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method search
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {string} params.analyzer - The analyzer to use for the query string
|
||||
* @param {boolean} params.analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false)
|
||||
* @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR)
|
||||
* @param {string} params.df - The field to use as default where no field prefix is given in the query string
|
||||
* @param {boolean} params.explain - Specify whether to return detailed information about score computation as part of a hit
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return as part of a hit
|
||||
* @param {number} params.from - Starting offset (default: 0)
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {String|ArrayOfStrings|Boolean} params.indices_boost - Comma-separated list of index boosts
|
||||
* @param {boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
|
||||
* @param {boolean} params.lowercase_expanded_terms - Specify whether query terms should be lowercased
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {string} params.q - Query in the Lucene query string syntax
|
||||
* @param {String|ArrayOfStrings|Boolean} params.routing - A comma-separated list of specific routing values
|
||||
* @param {duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search
|
||||
* @param {String} params.search_type - Search operation type
|
||||
* @param {number} params.size - Number of hits to return (default: 10)
|
||||
* @param {String|ArrayOfStrings|Boolean} params.sort - A comma-separated list of <field>:<direction> pairs
|
||||
* @param {string} params.source - The URL-encoded request definition using the Query DSL (instead of using request body)
|
||||
* @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return
|
||||
* @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
|
||||
* @param {String|ArrayOfStrings|Boolean} params.stats - Specific 'tag' of the request for logging and statistical purposes
|
||||
* @param {string} params.suggest_field - Specify which field to use for suggestions
|
||||
* @param {String} [params.suggest_mode=missing] - Specify suggest mode
|
||||
* @param {number} params.suggest_size - How many suggestions to return in response
|
||||
* @param {text} params.suggest_text - The source text for which the suggestions should be returned
|
||||
* @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, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/' + encodeURIComponent(parts.type) + '/_search';
|
||||
}
|
||||
else {
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/_search';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.analyze_wildcard = false;
|
||||
} else {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid default_operator: ' + params.default_operator +
|
||||
' should be one of ' + defaultOperatorOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.explain = false;
|
||||
} else {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.from !== 'undefined') {
|
||||
if (_.isNumeric(params.from)) {
|
||||
query.from = params.from * 1;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.indices_boost !== 'undefined') {
|
||||
switch (typeof params.indices_boost) {
|
||||
case 'string':
|
||||
query.indices_boost = params.indices_boost;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.indices_boost)) {
|
||||
query.indices_boost = params.indices_boost.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid indices_boost: ' + params.indices_boost + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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')
|
||||
) {
|
||||
query.lenient = false;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.lowercase_expanded_terms = false;
|
||||
} else {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
switch (typeof params.routing) {
|
||||
case 'string':
|
||||
query.routing = params.routing;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.routing)) {
|
||||
query.routing = params.routing.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.routing = !!params.routing;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid search_type: ' + params.search_type +
|
||||
' should be one of ' + searchTypeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.size !== 'undefined') {
|
||||
if (_.isNumeric(params.size)) {
|
||||
query.size = params.size * 1;
|
||||
} else {
|
||||
throw new TypeError('Invalid size: ' + params.size + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.sort !== 'undefined') {
|
||||
switch (typeof params.sort) {
|
||||
case 'string':
|
||||
query.sort = params.sort;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.sort)) {
|
||||
query.sort = params.sort.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid sort: ' + params.sort + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.sort = !!params.sort;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
} else {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
query._source = params._source;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source)) {
|
||||
query._source = params._source.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
query._source_exclude = params._source_exclude;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_exclude)) {
|
||||
query._source_exclude = params._source_exclude.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
query._source_include = params._source_include;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params._source_include)) {
|
||||
query._source_include = params._source_include.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.stats !== 'undefined') {
|
||||
switch (typeof params.stats) {
|
||||
case 'string':
|
||||
query.stats = params.stats;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.stats)) {
|
||||
query.stats = params.stats.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid stats: ' + params.stats + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid suggest_mode: ' + params.suggest_mode +
|
||||
' should be one of ' + suggestModeOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.suggest_size !== 'undefined') {
|
||||
if (_.isNumeric(params.suggest_size)) {
|
||||
query.suggest_size = params.suggest_size * 1;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.version = false;
|
||||
} else {
|
||||
query.version = !!params.version;
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSearch;
|
||||
@ -1,115 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [suggest](http://elasticsearch.org/guide/reference/api/search/suggest/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method suggest
|
||||
* @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
|
||||
* @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random)
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded request definition (instead of using request body)
|
||||
*/
|
||||
function doSuggest(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
// figure out the method
|
||||
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');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_suggest';
|
||||
}
|
||||
else {
|
||||
request.path = '/_suggest';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ignore_indices: ' + params.ignore_indices +
|
||||
' should be one of ' + ignoreIndicesOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSuggest;
|
||||
@ -1,221 +0,0 @@
|
||||
var _ = require('../lib/utils'),
|
||||
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
|
||||
*
|
||||
* @for Client
|
||||
* @method update
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.consistency - Explicit write consistency setting for the operation
|
||||
* @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response
|
||||
* @param {string} params.lang - The script language (default: mvel)
|
||||
* @param {string} params.parent - ID of the parent document
|
||||
* @param {string} params.percolate - Perform percolation during the operation; use specific registered query name, attribute, or wildcard
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
* @param {String} [params.replication=sync] - Specific replication type
|
||||
* @param {number} params.retry_on_conflict - Specify how many times should the operation be retried when a conflict occurs (default: 0)
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {*} params.script - The URL-encoded script definition (instead of using request body)
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.timestamp - Explicit timestamp for the document
|
||||
* @param {duration} params.ttl - Expiration time for the document
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {number} params.version_type - Explicit version number for concurrency control
|
||||
*/
|
||||
function doUpdate(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null,
|
||||
method: 'POST'
|
||||
},
|
||||
parts = {},
|
||||
query = {},
|
||||
responseOpts = {};
|
||||
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && 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) {
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// 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 path with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
if (_.contains(consistencyOptions, params.consistency)) {
|
||||
query.consistency = params.consistency;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid consistency: ' + params.consistency +
|
||||
' should be one of ' + consistencyOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.lang !== 'undefined') {
|
||||
if (typeof params.lang !== 'object' && params.lang) {
|
||||
query.lang = '' + params.lang;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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')
|
||||
) {
|
||||
query.refresh = false;
|
||||
} else {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid replication: ' + params.replication +
|
||||
' should be one of ' + replicationOptions.join(', ') + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.retry_on_conflict !== 'undefined') {
|
||||
if (_.isNumeric(params.retry_on_conflict)) {
|
||||
query.retry_on_conflict = params.retry_on_conflict * 1;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timeout)) {
|
||||
query.timeout = params.timeout;
|
||||
} else {
|
||||
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();
|
||||
} else if (_.isNumeric(params.timestamp)) {
|
||||
query.timestamp = params.timestamp;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
} else {
|
||||
throw new TypeError('Invalid version_type: ' + params.version_type + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doUpdate;
|
||||
@ -32,15 +32,10 @@ module.exports = Client;
|
||||
|
||||
var _ = require('./utils');
|
||||
var ClientConfig = require('./client_config');
|
||||
var api = _.reKey(_.requireDir(module, '../api'), _.camelCase);
|
||||
// var api = _.reKey(_.requireDir(module, '../api'), _.camelCase);
|
||||
var q = require('q');
|
||||
var errors = require('./errors');
|
||||
|
||||
// Many API commands are namespaced, like cluster.nodeStats. 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;
|
||||
|
||||
@ -53,8 +48,8 @@ function Client(config) {
|
||||
});
|
||||
this.config.client = this;
|
||||
|
||||
for (var i = 0; i < namespaces.length; i++) {
|
||||
this[namespaces[i]] = new this[namespaces[i]](this);
|
||||
for (var i = 0; i < _namespaces.length; i++) {
|
||||
this[_namespaces[i]] = new this[_namespaces[i]](this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +72,13 @@ Client.prototype.request = function (params, cb) {
|
||||
// in cb isn't a function make it one
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var connectionPool = this.config.connectionPool;
|
||||
var log = this.config.log;
|
||||
var remainingRetries = this.config.maxRetries;
|
||||
var connection;
|
||||
|
||||
log.debug('starting request', params);
|
||||
|
||||
// get ignore and ensure that it's an array
|
||||
var ignore = params.ignore;
|
||||
if (ignore && !_.isArray(ignore)) {
|
||||
@ -85,12 +87,50 @@ Client.prototype.request = function (params, cb) {
|
||||
|
||||
// serialize the body
|
||||
if (params.body) {
|
||||
params.body = serializer.serialize(params.body);
|
||||
params.body = params.bulkBody ? serializer.bulkBody(params.body) : serializer.serialize(params.body);
|
||||
}
|
||||
|
||||
this.config.transport.request(params, function (err, reqParams, body, status) {
|
||||
if (params.body && params.method === 'GET') {
|
||||
_.nextTick(cb, new TypeError('Body can not be sent with method "GET"'));
|
||||
return;
|
||||
}
|
||||
|
||||
function sendRequestWithConnection(err, _connection) {
|
||||
if (err) {
|
||||
log.error(err);
|
||||
respond(err);
|
||||
} else if (_connection) {
|
||||
connection = _connection;
|
||||
log.info('Selected', _connection.status, 'Connection, making request');
|
||||
connection.request(params, checkRespForFailure);
|
||||
} else {
|
||||
log.warning('No living connections');
|
||||
respond(new errors.ConnectionFault('No living connections.'));
|
||||
}
|
||||
}
|
||||
|
||||
function checkRespForFailure(err, reqParams, body, status) {
|
||||
connection.setStatus(err ? 'dead' : 'alive');
|
||||
|
||||
if (err) {
|
||||
log.error(err);
|
||||
}
|
||||
|
||||
if (err && remainingRetries) {
|
||||
remainingRetries--;
|
||||
log.info('Connection error, retrying');
|
||||
connectionPool.select(sendRequestWithConnection);
|
||||
} else {
|
||||
log.info('Request complete');
|
||||
respond(err, reqParams, body, status);
|
||||
}
|
||||
}
|
||||
|
||||
function respond(err, reqParams, body, status) {
|
||||
var parsedBody = null;
|
||||
if (reqParams) {
|
||||
log.trace(reqParams.method, reqParams, params.body, body, status);
|
||||
}
|
||||
if (!err) {
|
||||
if (body) {
|
||||
parsedBody = serializer.unserialize(body);
|
||||
@ -103,17 +143,19 @@ Client.prototype.request = function (params, cb) {
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return cb(err, parsedBody, status);
|
||||
cb(err, parsedBody, status);
|
||||
} else if ((status >= 200 && status < 300) || ignore && _.contains(ignore, status)) {
|
||||
return cb(void 0, parsedBody, status);
|
||||
cb(void 0, parsedBody, status);
|
||||
} else {
|
||||
if (errors[status]) {
|
||||
return cb(new errors[status](parsedBody.error), parsedBody, status);
|
||||
cb(new errors[status](parsedBody.error), parsedBody, status);
|
||||
} else {
|
||||
return cb(new errors.Generic('unknown error'), parsedBody, status);
|
||||
cb(new errors.Generic('unknown error'), parsedBody, status);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
connectionPool.select(sendRequestWithConnection);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -123,41 +165,54 @@ Client.prototype.request = function (params, cb) {
|
||||
* @param {Function} cb - callback
|
||||
*/
|
||||
Client.prototype.ping = function (params, cb) {
|
||||
this.config.transport.request({
|
||||
this.request({
|
||||
method: 'HEAD',
|
||||
path: '/'
|
||||
}, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Ask an ES node for a list of all the nodes, add/remove nodes from the connection
|
||||
* pool as appropriate
|
||||
*
|
||||
* @param {Function} cb - Function to call back once complete
|
||||
*/
|
||||
Client.prototype.sniff = function (cb) {
|
||||
var config = this.config;
|
||||
|
||||
// make cb a function if it isn't
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
this.request({
|
||||
path: '/_cluster/nodes',
|
||||
method: 'GET'
|
||||
}, function (err, resp) {
|
||||
if (!err && resp && resp.nodes) {
|
||||
var nodes = config.nodesToHostCallback(resp.nodes);
|
||||
config.connectionPool.setNodes(nodes);
|
||||
}
|
||||
cb(err, resp);
|
||||
});
|
||||
}
|
||||
|
||||
var _namespaces = [];
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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) {
|
||||
|
||||
function Namespace(client) {
|
||||
this.client = client;
|
||||
Client.namespace = function (namespace) {
|
||||
var steps = namespace.split('.');
|
||||
var path = [];
|
||||
var on = Client;
|
||||
var i;
|
||||
for (i = 0; i < steps.length; i ++) {
|
||||
path.push(steps[i]);
|
||||
_namespaces.push(path.join('.'));
|
||||
on.prototype[steps[i]] = function ClientActionNamespace(client) {
|
||||
this.client = client;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Namespace.prototype = actions;
|
||||
|
||||
return Namespace;
|
||||
}
|
||||
|
||||
// Extend the Client prototype with the top level API actions and the namespaces for other API actions
|
||||
_.extend(Client.prototype, _.map(api, function (action, name) {
|
||||
switch (typeof action) {
|
||||
case 'function':
|
||||
return action;
|
||||
case 'object':
|
||||
namespaces.push(name);
|
||||
return makeNamespaceConstructor(action);
|
||||
}
|
||||
}));
|
||||
require('./api.js').attach(Client);
|
||||
|
||||
@ -1,96 +0,0 @@
|
||||
/**
|
||||
* 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.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
|
||||
*/
|
||||
|
||||
module.exports = Transport;
|
||||
|
||||
var _ = require('./utils'),
|
||||
q = require('q'),
|
||||
ConnectionPool = require('./connection_pool'),
|
||||
errors = require('./errors');
|
||||
|
||||
function Transport(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
Transport.prototype.sniff = function (cb) {
|
||||
var self = this;
|
||||
|
||||
// make cb a function if it isn't
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
self.request({
|
||||
path: '/_cluster/nodes',
|
||||
method: 'GET'
|
||||
}, function (err, resp) {
|
||||
if (!err && resp && resp.nodes) {
|
||||
self.createConnections(self.config.nodesToHostCallback(resp.nodes));
|
||||
}
|
||||
cb(err, resp);
|
||||
});
|
||||
};
|
||||
|
||||
Transport.prototype.createConnections = function (hosts) {
|
||||
for (var i = 0; i < hosts.length; i++) {
|
||||
this.config.connectionPool.add(new this.config.connectionConstructor(
|
||||
this.config,
|
||||
hosts[i]
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
Transport.prototype.request = function (params, cb) {
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var connectionPool = this.config.connectionPool;
|
||||
var log = this.config.log;
|
||||
var remainingRetries = this.config.maxRetries;
|
||||
var connection;
|
||||
|
||||
function sendRequestWithConnection(err, _connection) {
|
||||
if (err) {
|
||||
log.error(err);
|
||||
cb(err);
|
||||
} else if (_connection) {
|
||||
connection = _connection;
|
||||
log.info('Selected', _connection.status, 'Connection, making request');
|
||||
connection.request(params, checkRespForFailure);
|
||||
} else {
|
||||
log.warning('No living connections');
|
||||
cb(new errors.ConnectionFault('No living connections.'));
|
||||
}
|
||||
}
|
||||
|
||||
function checkRespForFailure(err, reqParams, body, status) {
|
||||
connection.setStatus(err ? 'dead' : 'alive');
|
||||
|
||||
if (err) {
|
||||
log.error(err);
|
||||
}
|
||||
|
||||
if (err && remainingRetries) {
|
||||
remainingRetries--;
|
||||
log.info('connection error, retrying');
|
||||
connectionPool.select(sendRequestWithConnection);
|
||||
} else {
|
||||
log.info('Request complete');
|
||||
cb(err, reqParams, body, status);
|
||||
}
|
||||
}
|
||||
|
||||
connectionPool.select(sendRequestWithConnection);
|
||||
};
|
||||
3298
src/lib/api.js
Normal file
3298
src/lib/api.js
Normal file
File diff suppressed because it is too large
Load Diff
241
src/lib/client_action.js
Normal file
241
src/lib/client_action.js
Normal file
@ -0,0 +1,241 @@
|
||||
/**
|
||||
* Constructs a function that can be called to make a request to ES
|
||||
* @type {[type]}
|
||||
*/
|
||||
module.exports = function clientAction(spec) {
|
||||
return function (params, cb) {
|
||||
return exec(this.client, spec, params, cb);
|
||||
}
|
||||
};
|
||||
|
||||
var errors = require('./errors');
|
||||
|
||||
var _ = require('./utils');
|
||||
var urlParamRE = /\{(\w+)\}/g;
|
||||
|
||||
function exec(client, spec, params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
};
|
||||
var parts = {};
|
||||
var query = {};
|
||||
var i;
|
||||
|
||||
if (spec.needsBody && !params.body) {
|
||||
return _.nextTick(cb, new TyperError(spec.name + ' requires a request body.'));
|
||||
}
|
||||
|
||||
if (params.body) {
|
||||
request.body = params.body;
|
||||
request.bulkBody = spec.bulkBody;
|
||||
}
|
||||
|
||||
if (spec.methods.length === 1) {
|
||||
request.method = spec.methods[0];
|
||||
} else {
|
||||
// if set, uppercase the user's choice, other wise returns ""
|
||||
request.method = _.toUpperString(params.method);
|
||||
|
||||
if (request.method) {
|
||||
// use the one specified as long as it's a valid option
|
||||
if (!_.contains(spec.methods, request.method)) {
|
||||
return _.nextTick(cb, new TypeError('Invalid method: should be one of ' + spec.methods.join(', ')));
|
||||
}
|
||||
} else {
|
||||
// pick a method
|
||||
if (request.body) {
|
||||
// first method that isn't "GET"
|
||||
request.method = spec.methodWithBody || (
|
||||
spec.methodWithBody = _.find(spec.methods, function (m) { return m !== 'GET'; })
|
||||
);
|
||||
} else {
|
||||
// just use the first option
|
||||
request.method = spec.methods[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spec.url) {
|
||||
// only one url option
|
||||
request.path = resolveUrl(spec.url, params);
|
||||
} else {
|
||||
for (i = 0; i < spec.urls.length; i++) {
|
||||
if (request.path = resolveUrl(spec.urls[i], params)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!request.path) {
|
||||
// there must have been some mimimun requirements that were not met
|
||||
return _.nextTick(
|
||||
cb,
|
||||
new TypeError(
|
||||
'Unable to build a path with those params. Supply at least ' +
|
||||
_.keys(spec.urls[spec.urls.length - 1].req).join(', ')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// build the query string
|
||||
if (!spec.paramKeys) {
|
||||
// build a key list on demand
|
||||
spec.paramKeys = _.keys(spec.params);
|
||||
}
|
||||
var key, param;
|
||||
for (i = 0; i < spec.paramKeys.length; i++) {
|
||||
key = spec.paramKeys[i];
|
||||
param = spec.params[key];
|
||||
try {
|
||||
if (params[key] != null) {
|
||||
query[key] = castType[param.type] ? castType[param.type](param, params[key], key) : params[key];
|
||||
if (param['default'] && query[key] === param['default']) {
|
||||
delete query[key];
|
||||
}
|
||||
} else if (param.required) {
|
||||
throw new TypeError('Missing required parameter ' + key);
|
||||
}
|
||||
} catch (e) {
|
||||
return _.nextTick(cb, e);
|
||||
}
|
||||
}
|
||||
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
if (spec.castNotFound) {
|
||||
client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(null, false);
|
||||
} else {
|
||||
cb(err, !err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
client.request(request, cb);
|
||||
}
|
||||
};
|
||||
|
||||
var castType = {
|
||||
enum: function (param, val, name) {
|
||||
if (_.contains(param.options, val)) {
|
||||
return val;
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected one of ' + param.options.join(','));
|
||||
}
|
||||
},
|
||||
duration: function (param, val, name) {
|
||||
if (_.isNumeric(val) || _.isInterval(val)) {
|
||||
return val;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid ' + name + ': expected a number or interval ' +
|
||||
'(an integer followed by one of Mwdhmsy).'
|
||||
);
|
||||
}
|
||||
},
|
||||
list: function (param, val, name) {
|
||||
switch (typeof val) {
|
||||
case 'string':
|
||||
return val;
|
||||
case 'object':
|
||||
if (_.isArray(val)) {
|
||||
return val.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return !!val;
|
||||
}
|
||||
},
|
||||
boolean: function (param, val, name) {
|
||||
val = _.isString(val) ? val.toLowerCase() : val;
|
||||
return (val === 'no' || val === 'off') ? false : !!val;
|
||||
},
|
||||
number: function (param, val, name) {
|
||||
if (_.isNumeric(val)) {
|
||||
return val * 1;
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected a number.');
|
||||
}
|
||||
},
|
||||
string: function (param, val, name) {
|
||||
if (typeof val !== 'object' && val) {
|
||||
return '' + val;
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected a string.');
|
||||
}
|
||||
},
|
||||
time: function (param, val, name) {
|
||||
if (val instanceof Date) {
|
||||
return val.getTime();
|
||||
} else if (_.isNumeric(val)) {
|
||||
return val;
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected some sort of time.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function resolveUrl (url, params) {
|
||||
var vars = {}, name, i, key;
|
||||
|
||||
if (url.req) {
|
||||
// url has required params
|
||||
if (!url.reqParamKeys) {
|
||||
// create cached key list on demand
|
||||
url.reqParamKeys = _.keys(url.req);
|
||||
}
|
||||
|
||||
for (i = 0; i < url.reqParamKeys.length; i ++) {
|
||||
key = url.reqParamKeys[i];
|
||||
if (!params.hasOwnProperty(key)) {
|
||||
// missing a required param
|
||||
return false;
|
||||
} else {
|
||||
// copy param vals into vars
|
||||
vars[key] = params[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url.opt) {
|
||||
// url has optional params
|
||||
if (!url.optParamKeys) {
|
||||
url.optParamKeys = _.keys(url.opt);
|
||||
}
|
||||
|
||||
for (i = 0; i < url.optParamKeys.length; i ++) {
|
||||
key = url.optParamKeys[i];
|
||||
if (params[key]) {
|
||||
if (castType[url.opt[key].type]) {
|
||||
vars[key] = castType[url.opt[key].type](url.opt[key], params[key], key);
|
||||
} else {
|
||||
vars[key] = params[key];
|
||||
}
|
||||
} else {
|
||||
vars[key] = url.opt[key]['default'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!url.template) {
|
||||
// compile the template on demand
|
||||
url.template = _.template(url.fmt);
|
||||
}
|
||||
|
||||
return url.template(_.transform(vars, function (note, val, name) {
|
||||
// encode each value
|
||||
note[name] = encodeURIComponent(val);
|
||||
// remove it from the params so that it isn't sent to the final request
|
||||
delete params[name];
|
||||
}, {}));
|
||||
};
|
||||
@ -11,7 +11,6 @@ var _ = require('./utils');
|
||||
var selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase);
|
||||
var connections = _.requireClasses(module, './connections');
|
||||
var serializers = _.requireClasses(module, './serializers');
|
||||
var Transport = require('./transport');
|
||||
var ConnectionPool = require('./connection_pool');
|
||||
var Log = require('./log');
|
||||
|
||||
@ -54,10 +53,6 @@ var defaultConfig = {
|
||||
function ClientConfig(config) {
|
||||
_.extend(this, defaultConfig, config);
|
||||
|
||||
if (typeof this.hosts !== 'object') {
|
||||
this.hosts = [this.hosts];
|
||||
}
|
||||
|
||||
// validate connectionConstructor
|
||||
if (typeof this.connectionConstructor !== 'function') {
|
||||
if (_.has(connections, this.connectionConstructor)) {
|
||||
@ -73,52 +68,76 @@ function ClientConfig(config) {
|
||||
if (_.has(selectors, this.selector)) {
|
||||
this.selector = selectors[this.selector];
|
||||
} else {
|
||||
throw new TypeError('Invalid Selector ' + this.selector + '. specify a function or one of ' + _.keys(selectors).join(', '));
|
||||
throw new TypeError('Invalid Selector ' + this.selector + '. ' +
|
||||
'Expected a function or one of ' + _.keys(selectors).join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
this.serializer = new serializers.Json(this);
|
||||
this.hosts = _.map(this.hosts, this.transformHost);
|
||||
|
||||
// currently not configurable because!
|
||||
this.log = new Log(this);
|
||||
this.transport = new Transport(this);
|
||||
this.connectionPool = new ConnectionPool(this);
|
||||
this.serializer = new serializers.Json(this);
|
||||
|
||||
this.transport.createConnections(this.hosts);
|
||||
|
||||
if (this.randomizeHosts) {
|
||||
this.connectionPool.connections.alive = _.shuffle(this.connectionPool.connections.alive);
|
||||
}
|
||||
// populate the connection pool
|
||||
this.connectionPool.setNodes(this.prepareHosts(this.hosts));
|
||||
|
||||
// nodes are completely managed by the connection pool, remove traces of the config
|
||||
// value to prevent confusion
|
||||
delete this.hosts;
|
||||
}
|
||||
|
||||
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 + ':';
|
||||
ClientConfig.prototype.prepareHosts = function (hosts) {
|
||||
var host;
|
||||
var i;
|
||||
|
||||
if (_.isArray(hosts)) {
|
||||
hosts = [hosts];
|
||||
}
|
||||
|
||||
for(i = 0; i < hosts.length; i++) {
|
||||
host = hosts[i];
|
||||
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;
|
||||
}
|
||||
|
||||
if (!host.hostname) {
|
||||
host.hostname = 'localhost';
|
||||
}
|
||||
|
||||
if (!host.port) {
|
||||
host.port = 9200;
|
||||
}
|
||||
} else {
|
||||
host.protocol = 'http:';
|
||||
}
|
||||
// assume it is a string.
|
||||
|
||||
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;
|
||||
}
|
||||
if (!hostProtocolRE.test(host)) {
|
||||
// add a defaul protocol
|
||||
host = 'http://' + host;
|
||||
}
|
||||
|
||||
return host;
|
||||
// parse the url please, node
|
||||
var urlInfo = url.parse(host, false, true);
|
||||
|
||||
// override the host value
|
||||
hosts[i] = {
|
||||
protocol: urlInfo.protocol || 'http:',
|
||||
hostname: urlInfo.hostname || 'localhost',
|
||||
port: urlInfo.port || 9200
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!hostProtocolRE.test(host)) {
|
||||
host = 'http://' + host;
|
||||
}
|
||||
var urlInfo = url.parse(host, false, true);
|
||||
return {
|
||||
protocol: urlInfo.protocol,
|
||||
hostname: urlInfo.hostname,
|
||||
port: urlInfo.port
|
||||
};
|
||||
return hosts;
|
||||
};
|
||||
|
||||
@ -41,15 +41,6 @@ ConnectionPool.prototype.select = function (cb) {
|
||||
}
|
||||
};
|
||||
|
||||
ConnectionPool.prototype.empty = function () {
|
||||
_.each(this.connection.dead, function (connection) {
|
||||
connection.setStatus('closed');
|
||||
});
|
||||
_.each(this.connection.alive, function (connection) {
|
||||
connection.setStatus('closed');
|
||||
});
|
||||
};
|
||||
|
||||
ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus, connection) {
|
||||
var from, to, index;
|
||||
|
||||
@ -70,7 +61,6 @@ ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus
|
||||
break;
|
||||
case 'closed':
|
||||
from = this.connections[oldStatus];
|
||||
connection.removeListener('status changed', this.bound.onStatusChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -89,10 +79,45 @@ ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus
|
||||
}
|
||||
});
|
||||
|
||||
ConnectionPool.prototype.add = function (connection) {
|
||||
if (!~this.connections.alive.indexOf(connection) && !~this.connections.dead.indexOf(connection)) {
|
||||
connection.status = 'alive';
|
||||
ConnectionPool.prototype._add = function (connection) {
|
||||
if (!this.index[connection.__id]) {
|
||||
this.index[connection.__id] = connection;
|
||||
connection.on('status changed', this.bound.onStatusChanged);
|
||||
this.connections.alive.push(connection);
|
||||
connection.setStatus('alive');
|
||||
}
|
||||
};
|
||||
|
||||
ConnectionPool.prototype._remove = function (connection) {
|
||||
if (this.index[connection.__id]) {
|
||||
delete this.index[connection.__id];
|
||||
connection.setStatus('closed');
|
||||
connection.removeListener('status changed', this.bound.onStatusChanged);
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionPool.prototype.setNodes = function (nodeConfigs) {
|
||||
var i;
|
||||
var connection;
|
||||
var node;
|
||||
var toRemove = _.clone(this.index);
|
||||
for (i = 0; i < nodeConfigs.length; i++) {
|
||||
node = nodeConfigs[i];
|
||||
if (node.hostname && node.port) {
|
||||
id = node.hostname + ':' + node.port;
|
||||
if (this.index[id]) {
|
||||
delete toRemove[id];
|
||||
} else {
|
||||
connection = new this.config.connectionConstructor(this.config, nodeConfigs[i]);
|
||||
connection.__id = id;
|
||||
this._add(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_.each(toRemove, this._remove, this);
|
||||
}
|
||||
|
||||
|
||||
ConnectionPool.prototype.empty = function () {
|
||||
this.setNodes([]);
|
||||
};
|
||||
|
||||
@ -86,12 +86,6 @@ HttpConnection.prototype.request = function (params, cb) {
|
||||
cleanUp = _.noop;
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
@ -101,7 +101,7 @@ _.each(statusCodes, function (name, status) {
|
||||
var className = _.studlyCase(name);
|
||||
|
||||
function StatusCodeError(msg) {
|
||||
ErrorAbstract.call(this, msg || name, errors.StatusCodeError);
|
||||
ErrorAbstract.call(this, msg || name, errors[className]);
|
||||
}
|
||||
|
||||
_.inherits(StatusCodeError, ErrorAbstract);
|
||||
|
||||
@ -15,6 +15,7 @@ var path = require('path'),
|
||||
* @static
|
||||
*/
|
||||
var utils = _.extend({}, _, nodeUtils);
|
||||
_ = utils;
|
||||
|
||||
utils.inspect = function (thing, opts) {
|
||||
return nodeUtils.inspect(thing, _.defaults(opts || {}, {
|
||||
@ -33,23 +34,6 @@ 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 returned as an object with
|
||||
* each value transformed by the iterator.
|
||||
*
|
||||
* @method utils.map
|
||||
* @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
|
||||
*/
|
||||
utils.map = function (obj, mapper, context) {
|
||||
if (_.isPlainObject(obj)) {
|
||||
return _.reduce(obj, function (note, val, key) { note[key] = mapper.call(context, val, key); return note; }, {});
|
||||
} else {
|
||||
return _.map(obj, mapper, context);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Require all of the modules in a directory
|
||||
*
|
||||
@ -400,9 +384,9 @@ utils.applyArgs = function (func, context, args, sliceIndex) {
|
||||
* when it is called.
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
utils.nextTick = function (cb) {
|
||||
_.nextTick = function (cb) {
|
||||
// bind the function and schedule it
|
||||
process.nextTick(utils.bindKey(utils, 'applyArgs', cb, null, arguments, 1));
|
||||
process.nextTick(_.bindKey(_, 'applyArgs', cb, null, arguments, 1));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -416,15 +400,15 @@ utils.nextTick = function (cb) {
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @alias utils.scheduled
|
||||
* @alias _.scheduled
|
||||
* @param {Function} func - The method that is being defined
|
||||
* @return {Function}
|
||||
*/
|
||||
utils.handler = function (func) {
|
||||
_.handler = function (func) {
|
||||
func._provideBound = true;
|
||||
return func;
|
||||
};
|
||||
utils.scheduled = utils.handler;
|
||||
_.scheduled = _.handler;
|
||||
|
||||
/**
|
||||
* Creates an "bound" property on an object, which all or a subset of methods from
|
||||
@ -443,28 +427,28 @@ utils.scheduled = utils.handler;
|
||||
* @param {Object} obj - The object to bind the methods to
|
||||
* @param {Array} [methods] - The methods to bind, false values === bind them all
|
||||
*/
|
||||
utils.makeBoundMethods = function (obj, methods) {
|
||||
_.makeBoundMethods = function (obj, methods) {
|
||||
obj.bound = {};
|
||||
if (!methods) {
|
||||
methods = [];
|
||||
for (var prop in obj) {
|
||||
// dearest maintainer, we want to look through the prototype
|
||||
if (typeof obj[prop] === 'function' && obj[prop]._provideBound === true) {
|
||||
obj.bound[prop] = utils.bind(obj[prop], obj);
|
||||
obj.bound[prop] = _.bind(obj[prop], obj);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_.each(methods, function (method) {
|
||||
obj.bound[method] = utils.bindKey(obj, method);
|
||||
obj.bound[method] = _.bindKey(obj, method);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
utils.noop = function () {};
|
||||
_.noop = function () {};
|
||||
|
||||
utils.getStackTrace = function (callee) {
|
||||
_.getStackTrace = function (callee) {
|
||||
var e = {};
|
||||
Error.captureStackTrace(e, callee || utils.getStackTrace);
|
||||
Error.captureStackTrace(e, callee || _.getStackTrace);
|
||||
return '\n' + e.stack.split('\n').slice(1).join('\n');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user