126 lines
4.3 KiB
JavaScript
126 lines
4.3 KiB
JavaScript
// Licensed to Elasticsearch B.V under one or more agreements.
|
|
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
// See the LICENSE file in the project root for more information
|
|
|
|
'use strict'
|
|
|
|
/* eslint camelcase: 0 */
|
|
/* eslint no-unused-vars: 0 */
|
|
|
|
function buildDelete (opts) {
|
|
// eslint-disable-next-line no-unused-vars
|
|
const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts
|
|
/**
|
|
* Perform a [delete](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-delete.html) request
|
|
*
|
|
* @param {string} id - The document ID
|
|
* @param {string} index - The name of the index
|
|
* @param {string} type - The type of the document
|
|
* @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before proceeding with the delete operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)
|
|
* @param {string} parent - ID of parent document
|
|
* @param {enum} refresh - If `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.
|
|
* @param {string} routing - Specific routing value
|
|
* @param {time} timeout - Explicit operation timeout
|
|
* @param {number} version - Explicit version number for concurrency control
|
|
* @param {enum} version_type - Specific version type
|
|
*/
|
|
|
|
const acceptedQuerystring = [
|
|
'wait_for_active_shards',
|
|
'parent',
|
|
'refresh',
|
|
'routing',
|
|
'timeout',
|
|
'version',
|
|
'version_type',
|
|
'pretty',
|
|
'human',
|
|
'error_trace',
|
|
'source',
|
|
'filter_path'
|
|
]
|
|
|
|
const snakeCase = {
|
|
waitForActiveShards: 'wait_for_active_shards',
|
|
versionType: 'version_type',
|
|
errorTrace: 'error_trace',
|
|
filterPath: 'filter_path'
|
|
}
|
|
|
|
return function _delete (params, options, callback) {
|
|
options = options || {}
|
|
if (typeof options === 'function') {
|
|
callback = options
|
|
options = {}
|
|
}
|
|
if (typeof params === 'function' || params == null) {
|
|
callback = params
|
|
params = {}
|
|
options = {}
|
|
}
|
|
|
|
// check required parameters
|
|
if (params['id'] == null) {
|
|
const err = new ConfigurationError('Missing required parameter: id')
|
|
return handleError(err, callback)
|
|
}
|
|
if (params['index'] == null) {
|
|
const err = new ConfigurationError('Missing required parameter: index')
|
|
return handleError(err, callback)
|
|
}
|
|
if (params['type'] == null) {
|
|
const err = new ConfigurationError('Missing required parameter: type')
|
|
return handleError(err, callback)
|
|
}
|
|
if (params.body != null) {
|
|
const err = new ConfigurationError('This API does not require a body')
|
|
return handleError(err, callback)
|
|
}
|
|
|
|
// check required url components
|
|
if (params['id'] != null && (params['type'] == null || params['index'] == null)) {
|
|
const err = new ConfigurationError('Missing required parameter of the url: type, index')
|
|
return handleError(err, callback)
|
|
} else if (params['type'] != null && (params['index'] == null)) {
|
|
const err = new ConfigurationError('Missing required parameter of the url: index')
|
|
return handleError(err, callback)
|
|
}
|
|
|
|
// validate headers object
|
|
if (options.headers != null && typeof options.headers !== 'object') {
|
|
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
|
|
return handleError(err, callback)
|
|
}
|
|
|
|
var warnings = []
|
|
var { method, body, id, index, type, ...querystring } = params
|
|
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings)
|
|
|
|
if (method == null) {
|
|
method = 'DELETE'
|
|
}
|
|
|
|
var ignore = options.ignore
|
|
if (typeof ignore === 'number') {
|
|
options.ignore = [ignore]
|
|
}
|
|
|
|
var path = ''
|
|
|
|
path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + encodeURIComponent(id)
|
|
|
|
// build request object
|
|
const request = {
|
|
method,
|
|
path,
|
|
body: '',
|
|
querystring
|
|
}
|
|
|
|
options.warnings = warnings.length === 0 ? null : warnings
|
|
return makeRequest(request, options, callback)
|
|
}
|
|
}
|
|
|
|
module.exports = buildDelete
|