Files
elasticsearch-js/src/api/indices/delete_template.js

76 lines
2.2 KiB
JavaScript

var _ = require('../../lib/utils'),
errors = require('../../lib/errors'),
q = require('q');
/**
* Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
*
* @for Client
* @method indices.delete_template
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date|Number} params.timeout - Explicit operation timeout
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
*/
function doIndicesDeleteTemplate(params, cb) {
if (typeof params === 'function') {
cb = params;
params = {};
} else {
params = params || {};
cb = typeof cb === 'function' ? cb : _.noop;
}
var request = {
ignore: params.ignore,
method: 'DELETE'
},
parts = {},
query = {},
responseOpts = {};
// find the paths's params
if (typeof params.name !== 'object' && params.name) {
parts.name = '' + params.name;
} else {
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
}
// build the path
if (parts.hasOwnProperty('name')) {
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
}
else {
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
}
// build the query string
if (typeof params.timeout !== 'undefined') {
if (params.timeout instanceof Date) {
query.timeout = params.timeout.getTime();
} else if (_.isNumeric(params.timeout)) {
query.timeout = params.timeout;
} else {
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
}
}
if (typeof params.master_timeout !== 'undefined') {
if (params.master_timeout instanceof Date) {
query.master_timeout = params.master_timeout.getTime();
} else if (_.isNumeric(params.master_timeout)) {
query.master_timeout = params.master_timeout;
} else {
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
}
}
request.path = request.path + _.makeQueryString(query);
this.client.request(request, cb);
}
module.exports = doIndicesDeleteTemplate;