API generation
This commit is contained in:
121
api/api/indices.close.js
Normal file
121
api/api/indices.close.js
Normal file
@ -0,0 +1,121 @@
|
||||
'use strict'
|
||||
|
||||
function buildIndicesClose (opts) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { makeRequest, ConfigurationError } = opts
|
||||
/**
|
||||
* Perform a [indices.close](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html) request
|
||||
*
|
||||
* @param {list} index - A comma separated list of indices to close
|
||||
* @param {time} timeout - Explicit operation timeout
|
||||
* @param {time} master_timeout - Specify timeout for connection to master
|
||||
* @param {boolean} ignore_unavailable - Whether specified concrete indices should be ignored when unavailable (missing or closed)
|
||||
* @param {boolean} allow_no_indices - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
|
||||
* @param {enum} expand_wildcards - Whether to expand wildcard expression to concrete indices that are open, closed or both.
|
||||
*/
|
||||
return function indicesClose (params, callback) {
|
||||
if (typeof params === 'function' || params == null) {
|
||||
callback = params
|
||||
params = {}
|
||||
}
|
||||
// promises support
|
||||
if (callback == null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
indicesClose(params, (err, body) => {
|
||||
err ? reject(err) : resolve(body)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// check required parameters
|
||||
if (params['index'] == null) {
|
||||
return callback(
|
||||
new ConfigurationError('Missing required parameter: index'),
|
||||
{ body: null, headers: null, statusCode: null }
|
||||
)
|
||||
}
|
||||
if (params.body != null) {
|
||||
return callback(
|
||||
new ConfigurationError('This API does not require a body'),
|
||||
{ body: null, headers: null, statusCode: null }
|
||||
)
|
||||
}
|
||||
|
||||
// build querystring object
|
||||
const querystring = {}
|
||||
const keys = Object.keys(params)
|
||||
const acceptedQuerystring = [
|
||||
'timeout',
|
||||
'master_timeout',
|
||||
'ignore_unavailable',
|
||||
'allow_no_indices',
|
||||
'expand_wildcards',
|
||||
'pretty',
|
||||
'human',
|
||||
'error_trace',
|
||||
'source',
|
||||
'filter_path'
|
||||
]
|
||||
const acceptedQuerystringCamelCased = [
|
||||
'timeout',
|
||||
'masterTimeout',
|
||||
'ignoreUnavailable',
|
||||
'allowNoIndices',
|
||||
'expandWildcards',
|
||||
'pretty',
|
||||
'human',
|
||||
'errorTrace',
|
||||
'source',
|
||||
'filterPath'
|
||||
]
|
||||
|
||||
for (var i = 0, len = keys.length; i < len; i++) {
|
||||
var key = keys[i]
|
||||
if (acceptedQuerystring.indexOf(key) !== -1) {
|
||||
querystring[key] = params[key]
|
||||
} else {
|
||||
var camelIndex = acceptedQuerystringCamelCased.indexOf(key)
|
||||
if (camelIndex !== -1) {
|
||||
querystring[acceptedQuerystring[camelIndex]] = params[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// configure http method
|
||||
var method = params.method
|
||||
if (method == null) {
|
||||
method = 'POST'
|
||||
}
|
||||
|
||||
// validate headers object
|
||||
if (params.headers != null && typeof params.headers !== 'object') {
|
||||
return callback(
|
||||
new ConfigurationError(`Headers should be an object, instead got: ${typeof params.headers}`),
|
||||
{ body: null, headers: null, statusCode: null }
|
||||
)
|
||||
}
|
||||
|
||||
var ignore = params.ignore || null
|
||||
if (typeof ignore === 'number') {
|
||||
ignore = [ignore]
|
||||
}
|
||||
|
||||
// build request object
|
||||
const parts = [params['index'], '_close']
|
||||
const request = {
|
||||
method,
|
||||
path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'),
|
||||
querystring,
|
||||
body: '',
|
||||
headers: params.headers || null,
|
||||
ignore,
|
||||
requestTimeout: params.requestTimeout || null,
|
||||
agent: null,
|
||||
url: ''
|
||||
}
|
||||
|
||||
return makeRequest(request, callback)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = buildIndicesClose
|
||||
Reference in New Issue
Block a user