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