All tests are passing. Removed the HTML docs
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
@ -16,27 +17,30 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {String} [params.replication=sync] - Explicitely set the replication type
|
||||
* @param {string} params.type - Default document type for items which don't provide one
|
||||
*/
|
||||
function doBulk(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doBulk(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = 'post';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -44,7 +48,7 @@ function doBulk(params) {
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -54,12 +58,13 @@ function doBulk(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_bulk';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_bulk';
|
||||
delete params.type;
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_bulk';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_bulk';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_bulk';
|
||||
}
|
||||
|
||||
@ -98,7 +103,7 @@ function doBulk(params) {
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && 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.');
|
||||
@ -107,7 +112,11 @@ function doBulk(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doBulk;
|
||||
module.exports = doBulk;
|
||||
|
||||
64
src/api/clear_scroll.js
Normal file
64
src/api/clear_scroll.js
Normal file
@ -0,0 +1,64 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
switch (typeof params.scroll_id) {
|
||||
case 'string':
|
||||
url.scroll_id = params.scroll_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.scroll_id)) {
|
||||
url.scroll_id = params.scroll_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.scroll_id = !!params.scroll_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.scroll_id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClearScroll;
|
||||
@ -1,35 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.getSettings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.getSettings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterGetSettings(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doClusterGetSettings;
|
||||
43
src/api/cluster/get_settings.js
Normal file
43
src/api/cluster/get_settings.js
Normal file
@ -0,0 +1,43 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterGetSettings;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var levelOptions = ['cluster', 'indices', 'shards'];
|
||||
var waitForStatusOptions = ['green', 'yellow', 'red'];
|
||||
@ -16,22 +17,25 @@ var waitForStatusOptions = ['green', 'yellow', 'red'];
|
||||
* @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 {number} params.wait_for_nodes - Wait until the specified number of nodes is available
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterHealth(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -41,9 +45,9 @@ function doClusterHealth(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/_cluster/health/' + url.index + '';
|
||||
request.url = '/_cluster/health/' + encodeURIComponent(url.index) + '';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_cluster/health';
|
||||
}
|
||||
|
||||
@ -99,10 +103,10 @@ function doClusterHealth(params) {
|
||||
}
|
||||
|
||||
if (typeof params.wait_for_nodes !== 'undefined') {
|
||||
if (_.isNumeric(params.wait_for_nodes)) {
|
||||
query.wait_for_nodes = params.wait_for_nodes * 1;
|
||||
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 number.');
|
||||
throw new TypeError('Invalid wait_for_nodes: ' + params.wait_for_nodes + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +131,11 @@ function doClusterHealth(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterHealth;
|
||||
module.exports = doClusterHealth;
|
||||
|
||||
@ -1,46 +1,57 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var typeOptions = ['cpu', 'wait', 'block'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.nodeHotThreads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request
|
||||
* Perform an elasticsearch [cluster.node_hot_threads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.nodeHotThreads
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterNodeHotThreads(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
if (typeof params.node_id === 'string') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
} else if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + url.node_id + '/hotthreads';
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/hotthreads';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_nodes/hotthreads';
|
||||
}
|
||||
|
||||
@ -85,7 +96,11 @@ function doClusterNodeHotThreads(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeHotThreads;
|
||||
module.exports = doClusterNodeHotThreads;
|
||||
@ -1,12 +1,14 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
//TODO: this enpoint ***needs*** work, many of the possible urls are not supported
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.nodeInfo](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request
|
||||
* Perform an elasticsearch [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.nodeInfo
|
||||
* @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
|
||||
@ -21,32 +23,42 @@ var _ = require('../../lib/utils');
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeInfo(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterNodeInfo(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
if (typeof params.node_id === 'string') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
} else if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + url.node_id + '';
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_nodes';
|
||||
}
|
||||
|
||||
@ -174,7 +186,11 @@ function doClusterNodeInfo(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeInfo;
|
||||
module.exports = doClusterNodeInfo;
|
||||
@ -1,42 +1,53 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.nodeShutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
|
||||
* Perform an elasticsearch [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.nodeShutdown
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterNodeShutdown(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
if (typeof params.node_id === 'string') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
} else if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_cluster/nodes/' + url.node_id + '/_shutdown';
|
||||
request.url = '/_cluster/nodes/' + encodeURIComponent(url.node_id) + '/_shutdown';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_shutdown';
|
||||
}
|
||||
|
||||
@ -64,7 +75,11 @@ function doClusterNodeShutdown(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeShutdown;
|
||||
module.exports = doClusterNodeShutdown;
|
||||
@ -1,19 +1,20 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var metricFamilyOptions = ['all', 'fs', 'http', 'indices', 'jvm', 'network', 'os', 'process', 'thread_pool', 'transport'];
|
||||
var metricOptions = ['docs', 'fielddata', 'filter_cache', 'flush', 'get', 'id_cache', 'indexing', 'merges', 'refresh', 'search', 'store', 'warmer'];
|
||||
var metricOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'id_cache', 'indexing', 'merges', 'refresh', 'search', 'store', 'warmer'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.nodeStats](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/) request
|
||||
* Perform an elasticsearch [cluster.node_stats](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.nodeStats
|
||||
* @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 {list} params.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` 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
|
||||
@ -24,23 +25,33 @@ var metricOptions = ['docs', 'fielddata', 'filter_cache', 'flush', 'get', 'id_ca
|
||||
* @param {boolean} params.thread_pool - Return information about the thread pool
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeStats(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterNodeStats(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,21 +78,28 @@ function doClusterNodeStats(params) {
|
||||
}
|
||||
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
if (typeof params.node_id === 'string') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
} else if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + url.node_id + '/stats';
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/stats';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_nodes/stats';
|
||||
}
|
||||
|
||||
@ -108,12 +126,19 @@ function doClusterNodeStats(params) {
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +234,11 @@ function doClusterNodeStats(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeStats;
|
||||
module.exports = doClusterNodeStats;
|
||||
@ -1,36 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.putSettings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method cluster.putSettings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterPutSettings(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the url's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doClusterPutSettings;
|
||||
44
src/api/cluster/put_settings.js
Normal file
44
src/api/cluster/put_settings.js
Normal file
@ -0,0 +1,44 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterPutSettings;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,15 +12,18 @@ var _ = require('../../lib/utils');
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterReroute(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
|
||||
@ -51,7 +55,11 @@ function doClusterReroute(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterReroute;
|
||||
module.exports = doClusterReroute;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -10,21 +11,24 @@ var _ = require('../../lib/utils');
|
||||
* @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 {list} params.filter_indices - Limit returned metadata information to specific indices
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doClusterState(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
|
||||
@ -55,12 +59,19 @@ function doClusterState(params) {
|
||||
}
|
||||
|
||||
if (typeof params.filter_indices !== 'undefined') {
|
||||
if (typeof params.filter_indices === 'string') {
|
||||
switch (typeof params.filter_indices) {
|
||||
case 'string':
|
||||
query.filter_indices = params.filter_indices;
|
||||
} else 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 or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +127,11 @@ function doClusterState(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doClusterState;
|
||||
module.exports = doClusterState;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -16,54 +17,71 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
*/
|
||||
function doCount(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doCount(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_count';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_count';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_count';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_count';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_count';
|
||||
}
|
||||
|
||||
@ -89,7 +107,7 @@ function doCount(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -97,7 +115,7 @@ function doCount(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -105,7 +123,7 @@ function doCount(params) {
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && 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.');
|
||||
@ -114,7 +132,11 @@ function doCount(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doCount;
|
||||
module.exports = doCount;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
@ -25,40 +26,43 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doCreate(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doCreate(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = 'post';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -67,13 +71,14 @@ function doCreate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '/_create';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_create';
|
||||
delete params.id;
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +95,7 @@ function doCreate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && 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.');
|
||||
@ -98,7 +103,7 @@ function doCreate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && 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.');
|
||||
@ -106,7 +111,7 @@ function doCreate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && 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.');
|
||||
@ -135,7 +140,7 @@ function doCreate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -163,10 +168,10 @@ function doCreate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isInterval(params.ttl)) {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
} else {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +196,11 @@ function doCreate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doCreate;
|
||||
module.exports = doCreate;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
@ -21,29 +22,32 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doDelete(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doDelete(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -52,10 +56,10 @@ function doDelete(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +76,7 @@ function doDelete(params) {
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && 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.');
|
||||
@ -101,7 +105,7 @@ function doDelete(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -139,7 +143,11 @@ function doDelete(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doDelete;
|
||||
module.exports = doDelete;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
@ -8,10 +9,10 @@ var replicationOptions = ['sync', 'async'];
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [deleteByQuery](http://www.elasticsearch.org/guide/reference/api/delete-by-query/) request
|
||||
* Perform an elasticsearch [delete_by_query](http://www.elasticsearch.org/guide/reference/api/delete-by-query/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method deleteByQuery
|
||||
* @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
|
||||
@ -24,51 +25,68 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doDeleteByQuery(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doDeleteByQuery(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'DELETE';
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_query';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_query';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_query';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && 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.');
|
||||
@ -98,7 +116,7 @@ function doDeleteByQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && 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.');
|
||||
@ -128,7 +146,7 @@ function doDeleteByQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && 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.');
|
||||
@ -136,7 +154,7 @@ function doDeleteByQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -144,7 +162,7 @@ function doDeleteByQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && 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.');
|
||||
@ -163,7 +181,11 @@ function doDeleteByQuery(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doDeleteByQuery;
|
||||
module.exports = doDeleteByQuery;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -14,30 +15,33 @@ var _ = require('../lib/utils');
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doExists(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doExists(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'HEAD';
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.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' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -46,17 +50,17 @@ function doExists(params) {
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '';
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url 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' && 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.');
|
||||
@ -64,7 +68,7 @@ function doExists(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -92,7 +96,7 @@ function doExists(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -101,7 +105,11 @@ function doExists(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doExists;
|
||||
module.exports = doExists;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
|
||||
@ -14,7 +15,7 @@ var defaultOperatorOptions = ['AND', 'OR'];
|
||||
* @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 {list} params.fields - A comma-separated list of fields to return in the response
|
||||
* @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
|
||||
@ -22,39 +23,45 @@ var defaultOperatorOptions = ['AND', 'OR'];
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doExplain(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -63,10 +70,10 @@ function doExplain(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '/_explain';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_explain';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +89,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && 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.');
|
||||
@ -101,7 +108,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && 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.');
|
||||
@ -109,12 +116,19 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +153,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && 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.');
|
||||
@ -147,7 +161,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -155,7 +169,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && 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.');
|
||||
@ -163,7 +177,7 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -171,16 +185,71 @@ function doExplain(params) {
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doExplain;
|
||||
module.exports = doExplain;
|
||||
|
||||
117
src/api/get.js
117
src/api/get.js
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -8,37 +9,43 @@ var _ = require('../lib/utils');
|
||||
* @for Client
|
||||
* @method get
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {list} params.fields - A comma-separated list of fields to return in the response
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doGet(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.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' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -47,27 +54,34 @@ function doGet(params) {
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '';
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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' && 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.');
|
||||
@ -75,7 +89,7 @@ function doGet(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -103,16 +117,71 @@ function doGet(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doGet;
|
||||
module.exports = doGet;
|
||||
|
||||
@ -1,107 +0,0 @@
|
||||
var _ = require('../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [getSource](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method getSource
|
||||
* @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 doGetSource(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
url.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' && typeof params.type !== 'undefined') {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '/_source';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && typeof params.parent !== 'undefined') {
|
||||
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' && typeof params.preference !== 'undefined') {
|
||||
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' && typeof params.routing !== 'undefined') {
|
||||
query.routing = '' + params.routing;
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doGetSource;
|
||||
151
src/api/get_source.js
Normal file
151
src/api/get_source.js
Normal file
@ -0,0 +1,151 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '/_source';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doGetSource;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var opTypeOptions = ['index', 'create'];
|
||||
@ -26,40 +27,43 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doIndex(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndex(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'PUT') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
throw new TypeError('Invalid method: should be one of post, put');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = 'post';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -68,13 +72,13 @@ function doIndex(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +106,7 @@ function doIndex(params) {
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && 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.');
|
||||
@ -110,7 +114,7 @@ function doIndex(params) {
|
||||
}
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && 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.');
|
||||
@ -139,7 +143,7 @@ function doIndex(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -167,10 +171,10 @@ function doIndex(params) {
|
||||
}
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isInterval(params.ttl)) {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
} else {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +199,11 @@ function doIndex(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndex;
|
||||
module.exports = doIndex;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var formatOptions = ['detailed', 'text'];
|
||||
|
||||
@ -12,34 +13,37 @@ var formatOptions = ['detailed', 'text'];
|
||||
* @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 {list} params.filters - A comma-separated list of filters to use for the analysis
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesAnalyze(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -49,16 +53,17 @@ function doIndicesAnalyze(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_analyze';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_analyze';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_analyze';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && 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.');
|
||||
@ -66,7 +71,7 @@ function doIndicesAnalyze(params) {
|
||||
}
|
||||
|
||||
if (typeof params.field !== 'undefined') {
|
||||
if (typeof params.field !== 'object' && 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.');
|
||||
@ -74,17 +79,24 @@ function doIndicesAnalyze(params) {
|
||||
}
|
||||
|
||||
if (typeof params.filters !== 'undefined') {
|
||||
if (typeof params.filters === 'string') {
|
||||
switch (typeof params.filters) {
|
||||
case 'string':
|
||||
query.filters = params.filters;
|
||||
} else if (_.isArray(params.filters)) {
|
||||
query.filters = params.filters.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid filters: ' + params.filters + ' should be a comma seperated list or array.');
|
||||
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' && 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.');
|
||||
@ -102,7 +114,7 @@ function doIndicesAnalyze(params) {
|
||||
}
|
||||
|
||||
if (typeof params.text !== 'undefined') {
|
||||
if (typeof params.text !== 'object' && 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.');
|
||||
@ -110,7 +122,7 @@ function doIndicesAnalyze(params) {
|
||||
}
|
||||
|
||||
if (typeof params.tokenizer !== 'undefined') {
|
||||
if (typeof params.tokenizer !== 'object' && 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.');
|
||||
@ -130,7 +142,11 @@ function doIndicesAnalyze(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesAnalyze;
|
||||
module.exports = doIndicesAnalyze;
|
||||
|
||||
@ -1,61 +1,73 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.clearCache](http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/) request
|
||||
* Perform an elasticsearch [indices.clear_cache](http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.clearCache
|
||||
* @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 {list} params.fields - A comma-separated list of fields to clear when using the `field_data` parameter (default: all)
|
||||
* @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 {list} params.index - A comma-separated list of index name to limit the operation
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesClearCache(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_cache/clear';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_cache/clear';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_cache/clear';
|
||||
}
|
||||
|
||||
@ -82,12 +94,19 @@ function doIndicesClearCache(params) {
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,12 +172,19 @@ function doIndicesClearCache(params) {
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
query.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
query.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +200,11 @@ function doIndicesClearCache(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesClearCache;
|
||||
module.exports = doIndicesClearCache;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,17 +12,20 @@ var _ = require('../../lib/utils');
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesClose(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesClose(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -30,10 +34,10 @@ function doIndicesClose(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_close';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_close';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +64,11 @@ function doIndicesClose(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesClose;
|
||||
module.exports = doIndicesClose;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,26 +12,29 @@ var _ = require('../../lib/utils');
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesCreate(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesCreate(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
request.method = 'put';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -39,10 +43,10 @@ function doIndicesCreate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +73,11 @@ function doIndicesCreate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesCreate;
|
||||
module.exports = doIndicesCreate;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,32 +12,42 @@ var _ = require('../../lib/utils');
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDelete(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesDelete(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/';
|
||||
}
|
||||
|
||||
@ -64,7 +75,11 @@ function doIndicesDelete(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesDelete;
|
||||
module.exports = doIndicesDelete;
|
||||
|
||||
@ -1,63 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.deleteMapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.deleteMapping
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteMapping;
|
||||
@ -1,81 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.deleteWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.deleteWarmer
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteWarmer;
|
||||
@ -1,33 +1,37 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.deleteAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
* Perform an elasticsearch [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.deleteAlias
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesDeleteAlias(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
@ -36,10 +40,10 @@ function doIndicesDeleteAlias(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_alias/' + url.name + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, name');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +70,11 @@ function doIndicesDeleteAlias(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteAlias;
|
||||
module.exports = doIndicesDeleteAlias;
|
||||
78
src/api/indices/delete_mapping.js
Normal file
78
src/api/indices/delete_mapping.js
Normal file
@ -0,0 +1,78 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteMapping;
|
||||
@ -1,27 +1,31 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.deleteTemplate](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
* Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.deleteTemplate
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesDeleteTemplate(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'DELETE';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
@ -30,10 +34,10 @@ function doIndicesDeleteTemplate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + url.name + '';
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least name');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +64,11 @@ function doIndicesDeleteTemplate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteTemplate;
|
||||
module.exports = doIndicesDeleteTemplate;
|
||||
103
src/api/indices/delete_warmer.js
Normal file
103
src/api/indices/delete_warmer.js
Normal file
@ -0,0 +1,103 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteWarmer;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -9,31 +10,41 @@ var _ = require('../../lib/utils');
|
||||
* @method indices.exists
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesExists(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesExists(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'HEAD';
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +52,11 @@ function doIndicesExists(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesExists;
|
||||
module.exports = doIndicesExists;
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.existsAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.existsAlias
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.name === 'string') {
|
||||
url.name = params.name;
|
||||
} else if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_alias/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + url.name + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least name');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsAlias;
|
||||
@ -1,68 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.existsType](http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.existsType
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
if (typeof params.type === 'string') {
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsType;
|
||||
95
src/api/indices/exists_alias.js
Normal file
95
src/api/indices/exists_alias.js
Normal file
@ -0,0 +1,95 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsAlias;
|
||||
90
src/api/indices/exists_type.js
Normal file
90
src/api/indices/exists_type.js
Normal file
@ -0,0 +1,90 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesExistsType;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -15,40 +16,50 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {boolean} params.refresh - Refresh the index after performing the operation
|
||||
*/
|
||||
function doIndicesFlush(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesFlush(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_flush';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_flush';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_flush';
|
||||
}
|
||||
|
||||
@ -97,7 +108,11 @@ function doIndicesFlush(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesFlush;
|
||||
module.exports = doIndicesFlush;
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getAlias
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.name === 'string') {
|
||||
url.name = params.name;
|
||||
} else if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_alias/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + url.name + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least name');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAlias;
|
||||
@ -1,59 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getAliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getAliases
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doIndicesGetAliases(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_aliases';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAliases;
|
||||
@ -1,62 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getMapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getMapping
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetMapping(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_mapping';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_mapping';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mapping';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetMapping;
|
||||
@ -1,49 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getSettings](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getSettings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetSettings(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetSettings;
|
||||
@ -1,45 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getTemplate](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getTemplate
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetTemplate(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + url.name + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least name');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetTemplate;
|
||||
@ -1,71 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.getWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.getWarmer
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetWarmer(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetWarmer;
|
||||
95
src/api/indices/get_alias.js
Normal file
95
src/api/indices/get_alias.js
Normal file
@ -0,0 +1,95 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAlias;
|
||||
74
src/api/indices/get_aliases.js
Normal file
74
src/api/indices/get_aliases.js
Normal file
@ -0,0 +1,74 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_aliases';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAliases;
|
||||
84
src/api/indices/get_mapping.js
Normal file
84
src/api/indices/get_mapping.js
Normal file
@ -0,0 +1,84 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mapping';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetMapping;
|
||||
64
src/api/indices/get_settings.js
Normal file
64
src/api/indices/get_settings.js
Normal file
@ -0,0 +1,64 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetSettings;
|
||||
53
src/api/indices/get_template.js
Normal file
53
src/api/indices/get_template.js
Normal file
@ -0,0 +1,53 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetTemplate;
|
||||
93
src/api/indices/get_warmer.js
Normal file
93
src/api/indices/get_warmer.js
Normal file
@ -0,0 +1,93 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetWarmer;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,17 +12,20 @@ var _ = require('../../lib/utils');
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesOpen(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesOpen(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -30,10 +34,10 @@ function doIndicesOpen(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_open';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_open';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +64,11 @@ function doIndicesOpen(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesOpen;
|
||||
module.exports = doIndicesOpen;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -18,40 +19,50 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {boolean} params.refresh - Specify whether the index should be refreshed after performing the operation (default: true)
|
||||
* @param {boolean} params.wait_for_merge - Specify whether the request should block until the merge process is finished (default: true)
|
||||
*/
|
||||
function doIndicesOptimize(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesOptimize(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_optimize';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_optimize';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_optimize';
|
||||
}
|
||||
|
||||
@ -122,7 +133,11 @@ function doIndicesOptimize(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesOptimize;
|
||||
module.exports = doIndicesOptimize;
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.putSettings](http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.putSettings
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutSettings;
|
||||
@ -1,77 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.putWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.putWarmer
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_warmer/' + url.name + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, name');
|
||||
}
|
||||
|
||||
|
||||
// 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutWarmer;
|
||||
@ -1,34 +1,38 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.putAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
* Perform an elasticsearch [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.putAlias
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesPutAlias(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'PUT';
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
@ -37,15 +41,15 @@ function doIndicesPutAlias(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + url.index + '/_alias/' + url.name + '';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + url.name + '';
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_alias';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_alias';
|
||||
}
|
||||
|
||||
@ -73,7 +77,11 @@ function doIndicesPutAlias(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutAlias;
|
||||
module.exports = doIndicesPutAlias;
|
||||
@ -1,45 +1,56 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.putMapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/) request
|
||||
* Perform an elasticsearch [indices.put_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.putMapping
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesPutMapping(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
request.method = 'put';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -48,10 +59,10 @@ function doIndicesPutMapping(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_mapping';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +99,11 @@ function doIndicesPutMapping(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutMapping;
|
||||
module.exports = doIndicesPutMapping;
|
||||
75
src/api/indices/put_settings.js
Normal file
75
src/api/indices/put_settings.js
Normal file
@ -0,0 +1,75 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutSettings;
|
||||
@ -1,37 +1,41 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.putTemplate](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
* Perform an elasticsearch [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.putTemplate
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesPutTemplate(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'PUT' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
throw new TypeError('Invalid method: should be one of put, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'PUT';
|
||||
request.method = 'put';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.name !== 'object' && typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
@ -40,10 +44,10 @@ function doIndicesPutTemplate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + url.name + '';
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least name');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +82,11 @@ function doIndicesPutTemplate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutTemplate;
|
||||
module.exports = doIndicesPutTemplate;
|
||||
99
src/api/indices/put_warmer.js
Normal file
99
src/api/indices/put_warmer.js
Normal file
@ -0,0 +1,99 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url 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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutWarmer;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -13,40 +14,50 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesRefresh(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesRefresh(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_refresh';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_refresh';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_refresh';
|
||||
}
|
||||
|
||||
@ -69,7 +80,11 @@ function doIndicesRefresh(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesRefresh;
|
||||
module.exports = doIndicesRefresh;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -13,32 +14,42 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesSegments(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesSegments(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_segments';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_segments';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_segments';
|
||||
}
|
||||
|
||||
@ -61,7 +72,11 @@ function doIndicesSegments(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesSegments;
|
||||
module.exports = doIndicesSegments;
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
var _ = require('../../lib/utils');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.snapshotIndex](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.snapshotIndex
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
params = params || {};
|
||||
|
||||
request.method = 'POST';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_gateway/snapshot';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSnapshotIndex;
|
||||
77
src/api/indices/snapshot_index.js
Normal file
77
src/api/indices/snapshot_index.js
Normal file
@ -0,0 +1,77 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
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, callback) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_gateway/snapshot';
|
||||
}
|
||||
else {
|
||||
request.url = '/_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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesSnapshotIndex;
|
||||
@ -1,7 +1,8 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
var metricFamilyOptions = ['docs', 'fielddata', 'filter_cache', 'flush', 'get', 'groups', 'id_cache', 'ignore_indices', 'indexing', 'merge', 'refresh', 'search', 'store', 'warmer'];
|
||||
var metricFamilyOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'groups', 'id_cache', 'ignore_indices', 'indexing', 'merge', 'refresh', 'search', 'store', 'warmer'];
|
||||
|
||||
|
||||
|
||||
@ -13,9 +14,12 @@ var metricFamilyOptions = ['docs', 'fielddata', 'filter_cache', 'flush', 'get',
|
||||
* @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 {boolean} params.fields - A comma-separated list of fields for `fielddata` metric (supports wildcards)
|
||||
* @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
|
||||
@ -29,43 +33,67 @@ var metricFamilyOptions = ['docs', 'fielddata', 'filter_cache', 'flush', 'get',
|
||||
* @param {boolean} params.store - Return information about the size of the index
|
||||
* @param {boolean} params.warmer - Return information about warmers
|
||||
*/
|
||||
function doIndicesStats(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesStats(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.indexing_types !== 'undefined') {
|
||||
if (typeof params.indexing_types === 'string') {
|
||||
switch (typeof params.indexing_types) {
|
||||
case 'string':
|
||||
url.indexing_types = params.indexing_types;
|
||||
} else if (_.isArray(params.indexing_types)) {
|
||||
url.indexing_types = params.indexing_types.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid indexing_types: ' + params.indexing_types + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.indexing_types)) {
|
||||
url.indexing_types = params.indexing_types.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid indexing_types: ' + params.indexing_types + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.indexing_types = !!params.indexing_types;
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,21 +109,28 @@ function doIndicesStats(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_groups !== 'undefined') {
|
||||
if (typeof params.search_groups === 'string') {
|
||||
switch (typeof params.search_groups) {
|
||||
case 'string':
|
||||
url.search_groups = params.search_groups;
|
||||
} else if (_.isArray(params.search_groups)) {
|
||||
url.search_groups = params.search_groups.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid search_groups: ' + params.search_groups + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_groups)) {
|
||||
url.search_groups = params.search_groups.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid search_groups: ' + params.search_groups + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.search_groups = !!params.search_groups;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_stats';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_stats';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_stats';
|
||||
}
|
||||
|
||||
@ -121,6 +156,33 @@ function doIndicesStats(params) {
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
@ -141,12 +203,36 @@ function doIndicesStats(params) {
|
||||
}
|
||||
}
|
||||
|
||||
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') {
|
||||
if (params.fields.toLowerCase && (params.fields = params.fields.toLowerCase())
|
||||
&& (params.fields === 'no' || params.fields === 'off')
|
||||
) {
|
||||
query.fields = false;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -274,7 +360,11 @@ function doIndicesStats(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesStats;
|
||||
module.exports = doIndicesStats;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -15,32 +16,42 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {boolean} params.recovery - Return information about shard recovery
|
||||
* @param {boolean} params.snapshot - TODO: ?
|
||||
*/
|
||||
function doIndicesStatus(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesStatus(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
request.method = 'GET';
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_status';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_status';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_status';
|
||||
}
|
||||
|
||||
@ -83,7 +94,11 @@ function doIndicesStatus(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesStatus;
|
||||
module.exports = doIndicesStatus;
|
||||
|
||||
@ -1,34 +1,45 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.updateAliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
* Perform an elasticsearch [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.updateAliases
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesUpdateAliases(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +71,11 @@ function doIndicesUpdateAliases(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesUpdateAliases;
|
||||
module.exports = doIndicesUpdateAliases;
|
||||
@ -1,14 +1,15 @@
|
||||
var _ = require('../../lib/utils');
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.validateQuery](http://www.elasticsearch.org/guide/reference/api/validate/) request
|
||||
* Perform an elasticsearch [indices.validate_query](http://www.elasticsearch.org/guide/reference/api/validate/) request
|
||||
*
|
||||
* @for Client
|
||||
* @method indices.validateQuery
|
||||
* @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
|
||||
@ -16,54 +17,71 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.source - The URL-encoded query definition (instead of using the request body)
|
||||
* @param {string} params.q - Query in the Lucene query string syntax
|
||||
*/
|
||||
function doIndicesValidateQuery(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doIndicesValidateQuery(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_validate/query';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_validate/query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_validate/query';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_validate/query';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_validate/query';
|
||||
}
|
||||
|
||||
@ -95,7 +113,7 @@ function doIndicesValidateQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && 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.');
|
||||
@ -103,7 +121,7 @@ function doIndicesValidateQuery(params) {
|
||||
}
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && 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.');
|
||||
@ -112,7 +130,11 @@ function doIndicesValidateQuery(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doIndicesValidateQuery;
|
||||
module.exports = doIndicesValidateQuery;
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -9,21 +10,24 @@ var _ = require('../lib/utils');
|
||||
* @method info
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doInfo(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doInfo(params, callback) {
|
||||
params = params || {};
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'HEAD') {
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'head') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, HEAD');
|
||||
throw new TypeError('Invalid method: should be one of get, head');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'head' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
@ -37,7 +41,11 @@ function doInfo(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doInfo;
|
||||
module.exports = doInfo;
|
||||
|
||||
119
src/api/mget.js
119
src/api/mget.js
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -8,32 +9,38 @@ var _ = require('../lib/utils');
|
||||
* @for Client
|
||||
* @method mget
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {list} params.fields - A comma-separated list of fields to return in the response
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doMget(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
@ -41,7 +48,7 @@ function doMget(params) {
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -51,29 +58,36 @@ function doMget(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_mget';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mget';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_mget';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mget';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_mget';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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' && 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.');
|
||||
@ -100,9 +114,64 @@ function doMget(params) {
|
||||
}
|
||||
}
|
||||
|
||||
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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doMget;
|
||||
module.exports = doMget;
|
||||
|
||||
130
src/api/mlt.js
130
src/api/mlt.js
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -15,51 +16,54 @@ var _ = require('../lib/utils');
|
||||
* @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 {list} params.mlt_fields - Specific fields to perform the query against
|
||||
* @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 {list} params.search_indices - A comma-separated list of indices to perform the query against (default: the index containing the document)
|
||||
* @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 {list} params.search_types - A comma-separated list of types to perform the query against (default: the same type as the document)
|
||||
* @param {list} params.stop_words - A list of stop words to be ignored
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doMlt(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -68,10 +72,10 @@ function doMlt(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '/_mlt';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_mlt';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -133,12 +137,19 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.mlt_fields !== 'undefined') {
|
||||
if (typeof params.mlt_fields === 'string') {
|
||||
switch (typeof params.mlt_fields) {
|
||||
case 'string':
|
||||
query.mlt_fields = params.mlt_fields;
|
||||
} else 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 or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,7 +162,7 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -167,17 +178,24 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_indices !== 'undefined') {
|
||||
if (typeof params.search_indices === 'string') {
|
||||
switch (typeof params.search_indices) {
|
||||
case 'string':
|
||||
query.search_indices = params.search_indices;
|
||||
} else 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 or array.');
|
||||
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' && 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.');
|
||||
@ -185,7 +203,7 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_scroll !== 'undefined') {
|
||||
if (typeof params.search_scroll !== 'object' && 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.');
|
||||
@ -201,7 +219,7 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_source !== 'undefined') {
|
||||
if (typeof params.search_source !== 'object' && 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.');
|
||||
@ -209,7 +227,7 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
if (typeof params.search_type !== 'object' && 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.');
|
||||
@ -217,28 +235,46 @@ function doMlt(params) {
|
||||
}
|
||||
|
||||
if (typeof params.search_types !== 'undefined') {
|
||||
if (typeof params.search_types === 'string') {
|
||||
switch (typeof params.search_types) {
|
||||
case 'string':
|
||||
query.search_types = params.search_types;
|
||||
} else 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 or array.');
|
||||
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') {
|
||||
if (typeof params.stop_words === 'string') {
|
||||
switch (typeof params.stop_words) {
|
||||
case 'string':
|
||||
query.stop_words = params.stop_words;
|
||||
} else 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 or array.');
|
||||
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.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doMlt;
|
||||
module.exports = doMlt;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', 'dfs_query_and_fetch', 'count', 'scan'];
|
||||
|
||||
@ -12,54 +13,71 @@ var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.search_type - Search operation type
|
||||
*/
|
||||
function doMsearch(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doMsearch(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_msearch';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_msearch';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_msearch';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_msearch';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_msearch';
|
||||
}
|
||||
|
||||
@ -78,7 +96,11 @@ function doMsearch(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doMsearch;
|
||||
module.exports = doMsearch;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -10,32 +11,35 @@ var _ = require('../lib/utils');
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doPercolate(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -44,10 +48,10 @@ function doPercolate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_percolate';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_percolate';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +68,11 @@ function doPercolate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doPercolate;
|
||||
module.exports = doPercolate;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
|
||||
@ -11,27 +12,30 @@ var _ = require('../lib/utils');
|
||||
* @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) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doScroll(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && params.scroll_id) {
|
||||
url.scroll_id = '' + params.scroll_id;
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.');
|
||||
@ -41,24 +45,25 @@ function doScroll(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + url.scroll_id + '';
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.scroll_id) + '';
|
||||
delete params.scroll_id;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_search/scroll';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
if (_.isInterval(params.scroll)) {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll: ' + params.scroll + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
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' && 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.');
|
||||
@ -67,7 +72,11 @@ function doScroll(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doScroll;
|
||||
module.exports = doScroll;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
@ -18,21 +19,24 @@ var suggestModeOptions = ['missing', 'popular', 'always'];
|
||||
* @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 {list} params.fields - A comma-separated list of fields to return 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 {list} params.indices_boost - Comma-separated list of index boosts
|
||||
* @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 {list} params.routing - A comma-separated list of specific routing values
|
||||
* @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 {list} params.sort - A comma-separated list of <field>:<direction> pairs
|
||||
* @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 {list} params.stats - Specific 'tag' of the request for logging and statistical purposes
|
||||
* @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
|
||||
@ -40,61 +44,75 @@ var suggestModeOptions = ['missing', 'popular', 'always'];
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.version - Specify whether to return document version as part of a hit
|
||||
*/
|
||||
function doSearch(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doSearch(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'GET' || params.method === 'POST') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
throw new TypeError('Invalid method: should be one of get, post');
|
||||
}
|
||||
} else {
|
||||
request.method = 'GET';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type === 'string') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
} else if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/_search';
|
||||
if (url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/' + encodeURIComponent(url.type) + '/_search';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_search';
|
||||
}
|
||||
else {
|
||||
request.url = '/_search';
|
||||
else {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/_search';
|
||||
}
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && 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.');
|
||||
@ -123,7 +141,7 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && 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.');
|
||||
@ -141,12 +159,19 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,12 +195,19 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.indices_boost !== 'undefined') {
|
||||
if (typeof params.indices_boost === 'string') {
|
||||
switch (typeof params.indices_boost) {
|
||||
case 'string':
|
||||
query.indices_boost = params.indices_boost;
|
||||
} else 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 or array.');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +232,7 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -208,7 +240,7 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && 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.');
|
||||
@ -216,20 +248,27 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing === 'string') {
|
||||
switch (typeof params.routing) {
|
||||
case 'string':
|
||||
query.routing = params.routing;
|
||||
} else if (_.isArray(params.routing)) {
|
||||
query.routing = params.routing.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a comma seperated list or array.');
|
||||
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 (_.isInterval(params.scroll)) {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
} else {
|
||||
throw new TypeError('Invalid scroll: ' + params.scroll + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
throw new TypeError('Invalid scroll: ' + params.scroll + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,35 +292,100 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.sort !== 'undefined') {
|
||||
if (typeof params.sort === 'string') {
|
||||
switch (typeof params.sort) {
|
||||
case 'string':
|
||||
query.sort = params.sort;
|
||||
} else if (_.isArray(params.sort)) {
|
||||
query.sort = params.sort.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid sort: ' + params.sort + ' should be a comma seperated list or array.');
|
||||
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' && 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') {
|
||||
if (typeof params.stats === 'string') {
|
||||
switch (typeof params.stats) {
|
||||
case 'string':
|
||||
query.stats = params.stats;
|
||||
} else if (_.isArray(params.stats)) {
|
||||
query.stats = params.stats.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid stats: ' + params.stats + ' should be a comma seperated list or array.');
|
||||
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' && 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.');
|
||||
@ -308,7 +412,7 @@ function doSearch(params) {
|
||||
}
|
||||
|
||||
if (typeof params.suggest_text !== 'undefined') {
|
||||
if (typeof params.suggest_text !== 'object' && 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.');
|
||||
@ -337,7 +441,11 @@ function doSearch(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doSearch;
|
||||
module.exports = doSearch;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
@ -15,41 +16,51 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded request definition (instead of using request body)
|
||||
*/
|
||||
function doSuggest(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doSuggest(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
if (params.method) {
|
||||
if (params.method === 'POST' || params.method === 'GET') {
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
throw new TypeError('Invalid method: should be one of post, get');
|
||||
}
|
||||
} else {
|
||||
request.method = 'POST';
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index === 'string') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
} else if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list or array.');
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + url.index + '/_suggest';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_suggest';
|
||||
}
|
||||
else {
|
||||
else {
|
||||
request.url = '/_suggest';
|
||||
}
|
||||
|
||||
@ -67,7 +78,7 @@ function doSuggest(params) {
|
||||
}
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && 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.');
|
||||
@ -75,7 +86,7 @@ function doSuggest(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -83,7 +94,7 @@ function doSuggest(params) {
|
||||
}
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && 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.');
|
||||
@ -92,7 +103,11 @@ function doSuggest(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doSuggest;
|
||||
module.exports = doSuggest;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var _ = require('../lib/utils');
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
var consistencyOptions = ['one', 'quorum', 'all'];
|
||||
var replicationOptions = ['sync', 'async'];
|
||||
@ -12,7 +13,7 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @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 {list} params.fields - A comma-separated list of fields to return in the response
|
||||
* @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
|
||||
@ -27,30 +28,33 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {number} params.version_type - Explicit version number for concurrency control
|
||||
*/
|
||||
function doUpdate(params) {
|
||||
var request = {}
|
||||
, url = {}
|
||||
, query = {};
|
||||
|
||||
function doUpdate(params, callback) {
|
||||
params = params || {};
|
||||
request.body = params.body || null;
|
||||
|
||||
request.method = 'POST';
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
if (typeof params.id !== 'object' && typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + params.id;
|
||||
} else {
|
||||
throw new TypeError('Invalid id: ' + params.id + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.index !== 'object' && typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
if (typeof params.type !== 'object' && typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
@ -59,10 +63,10 @@ function doUpdate(params) {
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + url.index + '/' + url.type + '/' + url.id + '/_update';
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_update';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least index, type, id');
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
}
|
||||
|
||||
|
||||
@ -79,17 +83,24 @@ function doUpdate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
if (typeof params.fields === 'string') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
query.fields = params.fields;
|
||||
} else if (_.isArray(params.fields)) {
|
||||
query.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list or array.');
|
||||
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' && 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.');
|
||||
@ -97,7 +108,7 @@ function doUpdate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && 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.');
|
||||
@ -105,7 +116,7 @@ function doUpdate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.percolate !== 'undefined') {
|
||||
if (typeof params.percolate !== 'object' && 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.');
|
||||
@ -142,7 +153,7 @@ function doUpdate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && 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.');
|
||||
@ -174,10 +185,10 @@ function doUpdate(params) {
|
||||
}
|
||||
|
||||
if (typeof params.ttl !== 'undefined') {
|
||||
if (_.isInterval(params.ttl)) {
|
||||
if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) {
|
||||
query.ttl = params.ttl;
|
||||
} else {
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +210,11 @@ function doUpdate(params) {
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
return this.client.request(request);
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
|
||||
module.exports = doUpdate;
|
||||
module.exports = doUpdate;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
var _ = require('./utils')
|
||||
, transports = _.requireDir(module, './transports')
|
||||
, api = _.requireDir(module, '../api')
|
||||
var _ = require('./toolbelt')
|
||||
, transports = _.requireClasses(module, './transports')
|
||||
, serializers = _.requireClasses(module, './serializers')
|
||||
, Log = require('./log')
|
||||
, Q = require('q');
|
||||
, api = _.reKey(_.requireDir(module, '../api'), _.camelCase);
|
||||
|
||||
// Many API commands are namespaced, like cluster.node_stats. The names of these namespaces will be
|
||||
// tracked here and the namespace objects will be instantiated by reading the values from this
|
||||
@ -44,17 +44,11 @@ function Client(config) {
|
||||
this[namespaces[i]] = new this[namespaces[i]](this);
|
||||
}
|
||||
|
||||
this.hosts = config.hosts || ['http://localhost:9200'];
|
||||
|
||||
// this.transport = this.options.transport || new transports.NodeHttp(this.options);
|
||||
this.log = new Log(config && config.log);
|
||||
// this.serializer = this.options.serializer || new es.Serializer.json();
|
||||
this.log = new Log(config && config.log, this);
|
||||
this.serializer = new serializers.Json(this);
|
||||
this.transport = new transports.NodeHttp(config.hosts || ['//localhost:9200'], this);
|
||||
}
|
||||
|
||||
Client.prototype.sniff = function () {
|
||||
|
||||
};
|
||||
|
||||
Client.prototype.ping = function () {
|
||||
return this.request({
|
||||
url: '/',
|
||||
@ -74,29 +68,29 @@ Client.prototype.ping = function () {
|
||||
* @return {Promise} - A promise that will be resolved with the response
|
||||
*/
|
||||
Client.prototype.request = function (params) {
|
||||
var deferred = Q.defer();
|
||||
setTimeout(_.bind(function () {
|
||||
var response = {
|
||||
status: 200,
|
||||
body: {
|
||||
not: 'a real response'
|
||||
}
|
||||
};
|
||||
|
||||
this.log.trace(
|
||||
params.method,
|
||||
'http://' + this.hosts[Math.floor(Math.random() * this.hosts.length)] + params.url,
|
||||
params.body,
|
||||
response.status,
|
||||
JSON.stringify(response.body)
|
||||
);
|
||||
deferred.resolve();
|
||||
}, this), 3);
|
||||
return deferred.promise;
|
||||
// serialize the body
|
||||
params.body = this.serializer.serialize(params.body);
|
||||
|
||||
// ensure that ignore is an array
|
||||
if (params.ignore && !_.isArray(params.ignore)) {
|
||||
params.ignore = [params.ignore];
|
||||
}
|
||||
|
||||
// return the request's promise
|
||||
return this.transport.request(params);
|
||||
};
|
||||
|
||||
// creates a namespace, who's prototype offers the actions within that namespace and this context
|
||||
// provides the API actions a link back to the client they were intended to operate on.
|
||||
/**
|
||||
* These namespaces will be instanciated
|
||||
* @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.
|
||||
*/
|
||||
function makeNamespaceConstructor(actions) {
|
||||
|
||||
function Namespace(client) {
|
||||
@ -119,4 +113,4 @@ _.extend(Client.prototype, _.map(api, function (action, name) {
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = Client;
|
||||
module.exports = Client;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var _ = require('./utils')
|
||||
var _ = require('./toolbelt')
|
||||
, TransportAbstract = require('./transports/TransportAbstract');
|
||||
|
||||
function Interface(methods, properties) {
|
||||
@ -39,4 +39,4 @@ var Client = new Interface(
|
||||
module.exports = {
|
||||
Transport: Transport,
|
||||
Client: Client
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
var _ = require('./utils'),
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
var _ = require('./toolbelt')
|
||||
, url = require('url')
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
|
||||
@ -9,12 +10,13 @@ var _ = require('./utils'),
|
||||
* @class Log
|
||||
* @uses Loggers.Stdio
|
||||
* @constructor
|
||||
* @param {string|Object|ArrayOfStrings|ArrayOfObjects} output - Either the level to setup a single logger, a
|
||||
* full config object for alogger, or an array of config objects to use for creating log outputs.
|
||||
* @param {string|Object|ArrayOfStrings|ArrayOfObjects} output - Either the level
|
||||
* to setup a single logger, a full config object for alogger, or an array of
|
||||
* config objects to use for creating log outputs.
|
||||
* @param {string} output.level - One of the keys in Log.levels (error, warning, etc.)
|
||||
* @param {string} output.type - The name of the logger to use for this output
|
||||
*/
|
||||
function Log(output) {
|
||||
function Log(output, client) {
|
||||
var i;
|
||||
|
||||
output = output || 2;
|
||||
@ -63,34 +65,34 @@ Log.levels = [
|
||||
*/
|
||||
'error'
|
||||
/**
|
||||
* Event fired for "warning" level log entries, which usually represent things like
|
||||
* correctly formatted error responses from ES (400, ...) and recoverable errors
|
||||
* (one node unresponsive)
|
||||
* Event fired for "warning" level log entries, which usually represent things
|
||||
* like correctly formatted error responses from ES (400, ...) and recoverable
|
||||
* errors (one node unresponsive)
|
||||
*
|
||||
* @event warning
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'warning'
|
||||
/**
|
||||
* Event fired for "info" level log entries, which usually describe what a client is doing
|
||||
* (sniffing etc)
|
||||
* Event fired for "info" level log entries, which usually describe what a
|
||||
* client is doing (sniffing etc)
|
||||
*
|
||||
* @event info
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'info'
|
||||
/**
|
||||
* Event fired for "debug" level log entries, which will describe requests sent, including their
|
||||
* url (no data, response codes, or exec times)
|
||||
* Event fired for "debug" level log entries, which will describe requests sent,
|
||||
* including their url (no data, response codes, or exec times)
|
||||
*
|
||||
* @event debug
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'debug'
|
||||
/**
|
||||
* Event fired for "trace" level log entries, which provide detailed information about each request
|
||||
* made from a client, including reponse codes, execution times, and a full curl command that can be
|
||||
* copied and pasted into a terminal
|
||||
* Event fired for "trace" level log entries, which provide detailed information
|
||||
* about each request made from a client, including reponse codes, execution times,
|
||||
* and a full curl command that can be copied and pasted into a terminal
|
||||
*
|
||||
* @event trace
|
||||
* @param {String} method method, , body, responseStatus, responseBody
|
||||
@ -103,17 +105,19 @@ Log.levels = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Converts a log config value (string or array) to an array of level names which it represents
|
||||
* Converts a log config value (string or array) to an array of level names which
|
||||
* it represents
|
||||
*
|
||||
* @method parseLevels
|
||||
* @static
|
||||
* @private
|
||||
* @param {String|ArrayOfStrings} input - Cound be a string to specify the max level, or an array of exact levels
|
||||
* @param {String|ArrayOfStrings} input - Cound be a string to specify the max
|
||||
* level, or an array of exact levels
|
||||
* @return {Array} -
|
||||
*/
|
||||
Log.parseLevels = function (input) {
|
||||
if (_.isString(input)) {
|
||||
return _.first(Log.levels, _.indexOf(Log.levels, input) + 1);
|
||||
return Log.levels.slice(0, _.indexOf(Log.levels, input) + 1);
|
||||
}
|
||||
else if (_.isArray(input)) {
|
||||
return _.intersection(input, Log.levels);
|
||||
@ -132,7 +136,7 @@ Log.parseLevels = function (input) {
|
||||
Log.join = function (arrayish) {
|
||||
return _.map(arrayish, function (item) {
|
||||
if (_.isPlainObject(item)) {
|
||||
return _.inspect(item, { showHidden: true, depth: null, color: true}) + '\n';
|
||||
return _.inspect(item) + '\n';
|
||||
} else {
|
||||
return item.toString();
|
||||
}
|
||||
@ -144,19 +148,25 @@ Log.join = function (arrayish) {
|
||||
*
|
||||
* @method addOutput
|
||||
* @param {object} config - An object with config options for the logger.
|
||||
* @param {String} [config.type=stdio] - The name of an output/logger. Options can be found in the
|
||||
* `src/loggers` directory.
|
||||
* @param {String|ArrayOfStrings} [config.levels=warning] - The levels to output to this logger, when an
|
||||
* array is specified no levels other than the ones specified will be listened to. When a string is
|
||||
* specified, that and all lower levels will be logged.
|
||||
* @param {String} [config.type=stdio] - The name of an output/logger. Options
|
||||
* can be found in the `src/loggers` directory.
|
||||
* @param {String|ArrayOfStrings} [config.levels=warning] - The levels to output
|
||||
* to this logger, when an array is specified no levels other than the ones
|
||||
* specified will be listened to. When a string is specified, that and all lower
|
||||
* levels will be logged.
|
||||
* @return {Logger}
|
||||
*/
|
||||
Log.prototype.addOutput = function (config) {
|
||||
var levels = Log.parseLevels(config.levels || config.level || 'warning');
|
||||
|
||||
_.defaults(config, {
|
||||
type: 'stdio',
|
||||
levels: Log.parseLevels(config.levels || config.level || 'warning')
|
||||
});
|
||||
|
||||
// force the levels config
|
||||
delete config.level;
|
||||
config.levels = levels;
|
||||
|
||||
var Logger = require('./loggers/' + config.type);
|
||||
return new Logger(config, this);
|
||||
};
|
||||
@ -220,16 +230,23 @@ Log.prototype.debug = function (/* ...msg */) {
|
||||
*
|
||||
* @method trace
|
||||
* @param {String} method - HTTP request method
|
||||
* @param {String} url - URL requested
|
||||
* @param {String|Object} requestUrl - URL requested. If the value is an object,
|
||||
* it is expected to be the return value of Node's url.parse()
|
||||
* @param {String} body - The request's body
|
||||
* @param {Number} responseStatus - The status code returned
|
||||
* @param {String} responseBody - The body of the returned response
|
||||
* @return {Boolean} - True if any outputs accepted the message
|
||||
*/
|
||||
Log.prototype.trace = function (method, url, body, responseStatus, responseBody) {
|
||||
Log.prototype.trace = function (method, requestUrl, body, responseStatus, responseBody) {
|
||||
if (EventEmitter.listenerCount(this, 'trace')) {
|
||||
return this.emit('trace', method, url, body, responseStatus, responseBody);
|
||||
if (typeof requestUrl === 'object') {
|
||||
if (!requestUrl.protocol) {
|
||||
requestUrl.protocol = 'http';
|
||||
}
|
||||
requestUrl = url.format(requestUrl);
|
||||
}
|
||||
return this.emit('trace', method, requestUrl, body, responseStatus, responseBody);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Log;
|
||||
module.exports = Log;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var _ = require('./utils')
|
||||
var _ = require('./toolbelt')
|
||||
, selectors = require('./selector');
|
||||
|
||||
var configDefaults = {
|
||||
@ -56,4 +56,4 @@ function Transport(config) {
|
||||
*/
|
||||
Transport.defaults = function (update) {
|
||||
_.assign(configDefaults, update);
|
||||
};
|
||||
};
|
||||
|
||||
0
src/lib/errors.js
Normal file
0
src/lib/errors.js
Normal file
@ -1,12 +1,106 @@
|
||||
var LogAbstract = require('./log_abstract')
|
||||
, _ = require('../toolbelt')
|
||||
, fs = require('fs');
|
||||
|
||||
function prettyPrint(json) {
|
||||
try {
|
||||
json = JSON.stringify(JSON.parse(json), null, ' ');
|
||||
} catch (e) {}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logger that writes to a file
|
||||
*
|
||||
* @class Loggers.File
|
||||
* @constructor
|
||||
* @param {Object} config - Configuration for the FileLogger object
|
||||
* @see LoggerAbstract
|
||||
* @param {Object} config - The configuration for the Logger (See LoggerAbstract for generic options)
|
||||
* @param {String} config.path - The location to write
|
||||
* @param {Log} bridge - The object that triggers logging events, which we will record
|
||||
*/
|
||||
function File(config) {
|
||||
function File(config, bridge) {
|
||||
this._constructSuper(arguments);
|
||||
|
||||
this.outputPath = config.path;
|
||||
}
|
||||
_.inherits(File, LogAbstract);
|
||||
|
||||
module.exports = File;
|
||||
File.prototype.write = function (label, message) {
|
||||
if (!this.file) {
|
||||
this.file = fs.createWriteStream(this.outputPath, {
|
||||
flags: 'a',
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
|
||||
this.file.write(this.format(label, message), 'utf8');
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "error" event
|
||||
*
|
||||
* @method onError
|
||||
* @private
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onError = function (e) {
|
||||
this.write((e.name === 'Error' ? 'ERROR' : e.name), e.message + '\n\nStack Trace:\n' + e.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "warning" event
|
||||
*
|
||||
* @method onWarning
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onWarning = function (msg) {
|
||||
this.write('WARNING', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "info" event
|
||||
*
|
||||
* @method onInfo
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onInfo = function (msg) {
|
||||
this.write('INFO', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "debug" event
|
||||
*
|
||||
* @method onDebug
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onDebug = function (msg) {
|
||||
this.write('DEBUG', msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for the bridges "trace" event
|
||||
*
|
||||
* @method onTrace
|
||||
* @private
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
File.prototype.onTrace = function (method, url, body, responseStatus, responseBody) {
|
||||
var message = 'curl "' + url.replace(/"/g, '\\"') + '" -X' + method.toUpperCase();
|
||||
if (body) {
|
||||
message += ' -d "' + body.replace(/"/g, '\\"') + '"';
|
||||
}
|
||||
message += '\n<- ' + responseStatus + '\n' + prettyPrint(responseBody);
|
||||
this.write('TRACE', message);
|
||||
};
|
||||
|
||||
module.exports = File;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var clc = require('cli-color')
|
||||
, Log = require('../log')
|
||||
, _ = require('../utils');
|
||||
, LogAbstract = require('./log_abstract')
|
||||
, _ = require('../toolbelt');
|
||||
|
||||
/**
|
||||
* Special version of the Stream logger, which logs errors and warnings to stderr and all other
|
||||
@ -13,54 +13,13 @@ var clc = require('cli-color')
|
||||
* @param {Log} bridge - The object that triggers logging events, which we will record
|
||||
*/
|
||||
function Stdio(config, bridge) {
|
||||
this.bridge = bridge;
|
||||
this._constructSuper(arguments);
|
||||
|
||||
// config/state
|
||||
this.color = _.has(config, 'color') ? !!config.color : true;
|
||||
this.listeningLevels = [];
|
||||
|
||||
// bound copies of the event handlers
|
||||
this.handlers = _.reduce(Log.levels, function (handlers, name) {
|
||||
handlers[name] = _.bindKey(this, 'on' + _.studlyCase(name));
|
||||
return handlers;
|
||||
}, {}, this);
|
||||
|
||||
// then the bridge closes, remove our event listeners
|
||||
this.bridge.on('closing', _.bindKey(this, 'cleanUpListeners'));
|
||||
|
||||
this.setupListeners(config.levels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current event listeners and then re-listen for events based on the level specified
|
||||
*
|
||||
* @method setupListeners
|
||||
* @private
|
||||
* @param {Integer} level - The max log level that this logger should listen to
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.setupListeners = function (levels) {
|
||||
this.cleanUpListeners();
|
||||
|
||||
this.listeningLevels = levels;
|
||||
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.on(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners
|
||||
*
|
||||
* @method cleanUpListeners
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.cleanUpListeners = function () {
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.removeListener(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
_.inherits(Stdio, LogAbstract);
|
||||
|
||||
/**
|
||||
* Sends output to a stream, does some formatting first
|
||||
@ -73,11 +32,11 @@ Stdio.prototype.cleanUpListeners = function () {
|
||||
* @param {*} what - The message to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.write = function (to, label, colorize, what) {
|
||||
Stdio.prototype.write = function (to, label, colorize, message) {
|
||||
if (this.color) {
|
||||
label = colorize(label);
|
||||
}
|
||||
to.write(label + ': ' + what + '\n');
|
||||
to.write(this.format(label, message));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -155,4 +114,4 @@ Stdio.prototype.onTrace = function (method, url, body, responseStatus, responseB
|
||||
this.write(process.stdout, 'TRACE', clc.cyanBright.bold, message + '\n\n');
|
||||
};
|
||||
|
||||
module.exports = Stdio;
|
||||
module.exports = Stdio;
|
||||
|
||||
83
src/lib/loggers/log_abstract.js
Normal file
83
src/lib/loggers/log_abstract.js
Normal file
@ -0,0 +1,83 @@
|
||||
var Log = require('../log')
|
||||
, _ = require('../toolbelt');
|
||||
|
||||
function LogAbstract(config, bridge) {
|
||||
|
||||
this.bridge = bridge;
|
||||
this.listeningLevels = [];
|
||||
|
||||
// bound copies of the event handlers
|
||||
this.handlers = _.reduce(Log.levels, function (handlers, name) {
|
||||
handlers[name] = _.bindKey(this, 'on' + _.studlyCase(name));
|
||||
return handlers;
|
||||
}, {}, this);
|
||||
|
||||
// then the bridge closes, remove our event listeners
|
||||
this.bridge.on('closing', _.bindKey(this, 'cleanUpListeners'));
|
||||
|
||||
this.setupListeners(config.levels);
|
||||
}
|
||||
|
||||
function padNumToTen(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a timestamp string used in the format function. Defers to Log.timestamp if it is defined,
|
||||
* Also, feel free to override this at the logger level.
|
||||
* @return {String} - Timestamp in ISO 8601 UTC
|
||||
*/
|
||||
LogAbstract.prototype.timestamp = function () {
|
||||
var d = new Date();
|
||||
return d.getUTCFullYear() + '-' +
|
||||
padNumToTen(d.getUTCMonth() + 1) + '-' +
|
||||
padNumToTen(d.getUTCDate()) + 'T' +
|
||||
padNumToTen(d.getUTCHours()) + ':' +
|
||||
padNumToTen(d.getUTCMinutes()) + ':' +
|
||||
padNumToTen(d.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
function indent(test, spaces) {
|
||||
var space = _.repeat(' ', spaces || 2);
|
||||
return test.split(/\r?\n/).map(function (line) {
|
||||
return space + line;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
LogAbstract.prototype.format = function (label, message) {
|
||||
return label + ': ' + this.timestamp() + '\n' + indent(message) + '\n\n';
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners and then re-listen for events based on the level specified
|
||||
*
|
||||
* @method setupListeners
|
||||
* @private
|
||||
* @param {Integer} level - The max log level that this logger should listen to
|
||||
* @return {undefined}
|
||||
*/
|
||||
LogAbstract.prototype.setupListeners = function (levels) {
|
||||
this.cleanUpListeners();
|
||||
|
||||
this.listeningLevels = levels;
|
||||
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.on(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the current event listeners
|
||||
*
|
||||
* @method cleanUpListeners
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
LogAbstract.prototype.cleanUpListeners = function () {
|
||||
_.each(this.listeningLevels, function (level) {
|
||||
this.bridge.removeListener(level, this.handlers[level]);
|
||||
}, this);
|
||||
};
|
||||
|
||||
|
||||
module.exports = LogAbstract;
|
||||
18
src/lib/param_helper.js
Normal file
18
src/lib/param_helper.js
Normal file
@ -0,0 +1,18 @@
|
||||
var _ = require('./toolbelt');
|
||||
|
||||
exports.bulkBody = function (val, serializer) {
|
||||
var body = '', i;
|
||||
|
||||
if (_.isArray(val)) {
|
||||
for (i = 0; i < val.length; i++) {
|
||||
body += serializer.serialize(val[i]) + '\n';
|
||||
}
|
||||
} else if (typeof val === 'string') {
|
||||
// make sure the string ends in a new line
|
||||
body = val + (val[val.length - 1] === '\n' ? '' : '\n');
|
||||
} else {
|
||||
throw new TypeError('Bulk body should either be an Array of commands/string, or a String');
|
||||
}
|
||||
|
||||
return body;
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../utils');
|
||||
var _ = require('../toolbelt');
|
||||
|
||||
function RandomSelect(connections) {
|
||||
return _.shuffle(connections).unshift();
|
||||
}
|
||||
|
||||
module.exports = RandomSelect;
|
||||
module.exports = RandomSelect;
|
||||
|
||||
@ -1,11 +1,23 @@
|
||||
/* JSON serializer */
|
||||
|
||||
var _ = require('../utils');
|
||||
var _ = require('../toolbelt');
|
||||
|
||||
function Json() {}
|
||||
function Json(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
Json.prototype.serialize = _.bind(JSON.stringify, JSON);
|
||||
Json.prototype.serialize = function (val, replacer, spaces) {
|
||||
if (val == null) {
|
||||
return null;
|
||||
}
|
||||
else if (typeof val === 'string') {
|
||||
this.client.log.info('body is already a string, not encoding');
|
||||
return val;
|
||||
} else {
|
||||
return JSON.stringify(val, replacer, spaces);
|
||||
}
|
||||
};
|
||||
|
||||
Json.prototype.unserialize = _.bind(JSON.parse, JSON);
|
||||
|
||||
module.exports = Json;
|
||||
module.exports = Json;
|
||||
|
||||
@ -2,7 +2,8 @@ var path = require('path')
|
||||
, _ = require('lodash')
|
||||
, fs = require('fs')
|
||||
, requireDir = require('require-directory')
|
||||
, qs = require('qs');
|
||||
, qs = require('qs')
|
||||
, nodeUtils = require('util');
|
||||
|
||||
/**
|
||||
* Custom utils library, basically a modified version of [lodash](http://lodash.com/docs) +
|
||||
@ -12,7 +13,15 @@ var path = require('path')
|
||||
* @class utils
|
||||
* @static
|
||||
*/
|
||||
var utils = _.extend({}, _, require('util'));
|
||||
var utils = _.extend({}, _, nodeUtils);
|
||||
|
||||
utils.inspect = function (thing, opts) {
|
||||
return nodeUtils.inspect(thing, _.defaults(opts || {}, {
|
||||
showHidden: true,
|
||||
depth: null,
|
||||
color: true
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@ -46,7 +55,7 @@ utils.map = function (obj, mapper, context) {
|
||||
* @method requireDir
|
||||
* @param {Module} module - The module object which will own the required modules.
|
||||
* @param {String} path - Path to the directory which will be traversed (can be relative to module)
|
||||
* @return {Object} - An object with each required file
|
||||
* @return {Object} - An object with each required files
|
||||
*/
|
||||
utils.requireDir = function (module, dirPath) {
|
||||
if (dirPath && dirPath[0] === '.') {
|
||||
@ -55,8 +64,70 @@ utils.requireDir = function (module, dirPath) {
|
||||
return requireDir(module, dirPath);
|
||||
};
|
||||
|
||||
/**
|
||||
* Requires all of the files in a directory, then transforms the filenames into
|
||||
* StudlyCase -- one level deep for now.
|
||||
* @param {Module} module - The module object which will own the required modules.
|
||||
* @param {String} path - Path to the directory which will be traversed (can be relative to module)
|
||||
* @return {Object} - An object with each required files, keys will be the StudlyCase version of the filesnames.
|
||||
*/
|
||||
utils.requireClasses = function (module, dirPath) {
|
||||
return utils.reKey(utils.requireDir(module, dirPath), utils.studlyCase, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Recursively re-key an object, applying "transform" to each key
|
||||
* @param {Object} obj - The object to re-key
|
||||
* @param {Function} transform - The transformation function to apply to each key
|
||||
* @param {Boolean} recursive - Should this act recursively?
|
||||
* @param {Object} out - used primarily for recursion, allows you to specify the object which new keys will be written to
|
||||
* @return {Object}
|
||||
*/
|
||||
utils.reKey = function (obj, transform, recursive) {
|
||||
// defaults
|
||||
if (typeof recursive === 'undefined') { recursive = true; }
|
||||
if (typeof transform !== 'function') { throw new TypeError('invalid transform function'); }
|
||||
|
||||
var out = {};
|
||||
|
||||
_.each(obj, function (prop, name) {
|
||||
if (recursive && typeof prop === 'object') {
|
||||
out[transform(name)] = utils.reKey(prop, transform, recursive);
|
||||
} else {
|
||||
out[transform(name)] = prop;
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* Recursively merge two objects, walking into each object and concating arrays.
|
||||
* If both to and from have a value at a key, but the values' types don't match
|
||||
* to's value is left unmodified. Only Array and Object values are merged - that
|
||||
* it to say values with a typeof "object"
|
||||
* @param {Obejct} to - Object to merge into (no cloning, the original object
|
||||
* is modified)
|
||||
* @param {Object} from - Object to pull changed from
|
||||
* @return {Object} - returns the modified to value
|
||||
*/
|
||||
utils.deepMerge = function (to, from) {
|
||||
Object.keys(from).forEach(function (key) {
|
||||
switch (typeof to[key]) {
|
||||
case 'undefined':
|
||||
to[key] = from[key];
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(to[key]) && _.isArray(from[key])) {
|
||||
to[key] = to[key].concat(from[key]);
|
||||
}
|
||||
else if (_.isPlainObject(to[key]) && _.isPlainObject(from[key])) {
|
||||
utils.deepMerge(to[key], from[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
return to;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if a value is an array and it's contents are of a specific type
|
||||
@ -98,8 +169,8 @@ utils.ucfirst = function (word) {
|
||||
* @return {String}
|
||||
*/
|
||||
utils.studlyCase = function (string) {
|
||||
return string.split(/\b|_/).map(function (word) {
|
||||
return word.match(/^[a-z]+$/i) ? word[0].toUpperCase() + word.substr(1) : '';
|
||||
return _.map(string.split(/\b|_/), function (word, i) {
|
||||
return word.match(/^[a-z]+$/i) ? utils.ucfirst(word) : '';
|
||||
}).join('');
|
||||
};
|
||||
|
||||
@ -114,13 +185,24 @@ utils.studlyCase = function (string) {
|
||||
utils.camelCase = function (string) {
|
||||
return _.map(string.split(/\b|_/), function (word, i) {
|
||||
if (word.match(/^[a-z]+$/i)) {
|
||||
return (i === 0 ? word[0].toLowerCase() : word[0].toUpperCase()) + word.substr(1).toLowerCase();
|
||||
return i === 0 ? word.toLowerCase() : utils.ucfirst(word);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}).join('');
|
||||
};
|
||||
|
||||
utils.toLowerString = function (any) {
|
||||
if (any) {
|
||||
if (typeof any !== 'string') {
|
||||
any = any.toString();
|
||||
}
|
||||
} else {
|
||||
any = '';
|
||||
}
|
||||
return any.toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if a value is "numeric" meaning that it can be transformed into something besides NaN
|
||||
*
|
||||
@ -130,11 +212,11 @@ utils.camelCase = function (string) {
|
||||
* @return {Boolean}
|
||||
*/
|
||||
utils.isNumeric = function (val) {
|
||||
return !isNaN(val * 1);
|
||||
return !isNaN(val === null ? NaN : val * 1);
|
||||
};
|
||||
|
||||
// regexp to test for intervals
|
||||
var intervalRE = /(\d+(?:\.\d+)?)([Mwdhmsy])/;
|
||||
var intervalRE = /^(\d+(?:\.\d+)?)([Mwdhmsy])$/;
|
||||
|
||||
/**
|
||||
* Test if a string represents an interval (eg. 1m, 2Y)
|
||||
@ -145,7 +227,7 @@ var intervalRE = /(\d+(?:\.\d+)?)([Mwdhmsy])/;
|
||||
* @return {Boolean}
|
||||
*/
|
||||
utils.isInterval = function (val) {
|
||||
return val.match && val.match(intervalRE);
|
||||
return !!(val.match && val.match(intervalRE));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -175,4 +257,23 @@ utils.makeQueryString = function (obj, start) {
|
||||
return (start === false || str === '') ? str : '?' + str;
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
utils.inherits = function (constructor, superConstructor) {
|
||||
nodeUtils.inherits(constructor, superConstructor);
|
||||
constructor.prototype._constructSuper = function (args) {
|
||||
constructor.super_.apply(this, _.toArray(args));
|
||||
};
|
||||
};
|
||||
|
||||
utils.collectMatches = function (text, regExp) {
|
||||
var matches = [], match;
|
||||
while (match = regExp.exec(text)) {
|
||||
matches.push(match);
|
||||
if (regExp.global !== true) {
|
||||
// would loop forever if not true
|
||||
break;
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
@ -1,81 +1,109 @@
|
||||
/* elasticsearch-js nodejs transport */
|
||||
var http = require('http')
|
||||
, _ = require('../utils');
|
||||
, _ = require('../toolbelt')
|
||||
, url = require('url')
|
||||
, Q = require('q');
|
||||
|
||||
/**
|
||||
* Http transport to use in Node.js
|
||||
*
|
||||
* @class NodeHttp
|
||||
*/
|
||||
function NodeHttp() {
|
||||
|
||||
// Split hostname:port into its repective parts
|
||||
function splitHost(u) {
|
||||
var s = u.split(':');
|
||||
return {host: s[0], port: s[1]};
|
||||
}
|
||||
|
||||
// Meta function for handling any http request that can have a body (PUT,POST,DELETE)
|
||||
function performRequest(context, method, path, params, body, successcb, errorcb, retries) {
|
||||
|
||||
var
|
||||
//context = context,
|
||||
host = splitHost(context.selector(context.options.hosts)),
|
||||
options = {
|
||||
host: host.host,
|
||||
port: host.port,
|
||||
path: path + '?' + _.toQueryString(params),
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
var request = http.request(options, function (res) {
|
||||
|
||||
var data = '';
|
||||
res.setEncoding('utf8');
|
||||
|
||||
res.on('data', function (d) {
|
||||
data = data + d;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
|
||||
var response = {
|
||||
data : data.charAt(0) === '{' ? JSON.parse(data) : data,
|
||||
headers : res.headers,
|
||||
status : res.statusCode
|
||||
};
|
||||
|
||||
if (successcb != null && response.status < 300) {
|
||||
successcb(response);
|
||||
} else if (errorcb != null) {
|
||||
errorcb(response);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
if (errorcb != null) {
|
||||
request.on('error', errorcb);
|
||||
function NodeHttp(hosts, client) {
|
||||
this.hosts = _.map(hosts, function (host) {
|
||||
if (!~host.indexOf('//')) {
|
||||
host = '//' + host;
|
||||
}
|
||||
|
||||
if (method !== 'GET' && method !== 'HEAD') {
|
||||
request.write(body);
|
||||
}
|
||||
|
||||
request.end();
|
||||
}
|
||||
|
||||
// Public functions
|
||||
return {
|
||||
get : _.bind(performRequest, this, 'PUT'),
|
||||
put : _.bind(performRequest, this, 'POST'),
|
||||
post : _.bind(performRequest, this, 'DELETE'),
|
||||
del : _.bind(performRequest, this, 'GET'),
|
||||
head : _.bind(performRequest, this, 'HEAD')
|
||||
};
|
||||
|
||||
return _.pick(url.parse(host, false, true), ['hostname', 'port']);
|
||||
});
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
module.exports = NodeHttp;
|
||||
NodeHttp.prototype.request = function (params) {
|
||||
var deferred = Q.defer()
|
||||
, req = _.extend(
|
||||
url.parse(params.url, false, false),
|
||||
this.hosts[Math.round(Math.random() * (this.hosts.length - 1))]
|
||||
);
|
||||
|
||||
// we need to have a method
|
||||
req.method = params.method || (params.body ? 'post' : 'get');
|
||||
|
||||
// ensure that get isn't being used with a request body
|
||||
if (params.body && req.method.toLowerCase() === 'get') {
|
||||
deferred.reject(new TypeError('HTTP Method GET can not have a body'));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
var request = http.request(req, function (res) {
|
||||
var response = {
|
||||
data : '',
|
||||
headers : res.headers,
|
||||
status : res.statusCode
|
||||
};
|
||||
|
||||
res.setEncoding('utf8');
|
||||
|
||||
res.on('data', function (d) {
|
||||
response.data += d;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
this.client.log.trace(req.method, req, params.body, response.status, response.data);
|
||||
|
||||
// attempt to parse the response
|
||||
if (response.data) {
|
||||
try {
|
||||
response.data = JSON.parse(response.data);
|
||||
} catch (e) {
|
||||
response.error = new TypeError('Non-valid JSON reponse from Elasticsearch');
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.error && response.status >= 400) {
|
||||
response.error = new Error(errorMessage(response));
|
||||
response.error.status = response.status;
|
||||
}
|
||||
|
||||
if (response.error) {
|
||||
if (_.contains(params.ignore, response.status)) {
|
||||
deferred.resolve(false, response);
|
||||
} else {
|
||||
// reject with error
|
||||
deferred.reject(response.error, response);
|
||||
}
|
||||
} else {
|
||||
// we're done
|
||||
deferred.resolve(req.method === 'head' ? true : response.data, response);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
}.bind(this));
|
||||
|
||||
request.on('error', function (err) {
|
||||
deferred.reject(err);
|
||||
});
|
||||
|
||||
if (params.body) {
|
||||
request.write(params.body);
|
||||
}
|
||||
|
||||
request.end();
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
function errorMessage(response) {
|
||||
if (response.data.error) {
|
||||
return response.data.error;
|
||||
} else {
|
||||
switch (response.status) {
|
||||
case 404:
|
||||
return 'Not Found';
|
||||
default:
|
||||
return response.status + ' - Unkown Error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NodeHttp;
|
||||
|
||||
Reference in New Issue
Block a user