Files
elasticsearch-js/api/api/indices.upgrade.js
2018-11-05 19:17:55 +01:00

116 lines
3.6 KiB
JavaScript

'use strict'
function buildIndicesUpgrade (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, result } = opts
/**
* Perform a [indices.upgrade](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html) request
*
* @param {list} index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @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.
* @param {boolean} ignore_unavailable - Whether specified concrete indices should be ignored when unavailable (missing or closed)
* @param {boolean} wait_for_completion - Specify whether the request should block until the all segments are upgraded (default: false)
* @param {boolean} only_ancient_segments - If true, only ancient (an older Lucene major release) segments will be upgraded
*/
return function indicesUpgrade (params, callback) {
if (typeof params === 'function' || params == null) {
callback = params
params = {}
}
// promises support
if (callback == null) {
return new Promise((resolve, reject) => {
indicesUpgrade(params, (err, body) => {
err ? reject(err) : resolve(body)
})
})
}
// check required parameters
if (params.body != null) {
return callback(
new ConfigurationError('This API does not require a body'),
result
)
}
// build querystring object
const querystring = {}
const keys = Object.keys(params)
const acceptedQuerystring = [
'allow_no_indices',
'expand_wildcards',
'ignore_unavailable',
'wait_for_completion',
'only_ancient_segments',
'pretty',
'human',
'error_trace',
'source',
'filter_path'
]
const acceptedQuerystringCamelCased = [
'allowNoIndices',
'expandWildcards',
'ignoreUnavailable',
'waitForCompletion',
'onlyAncientSegments',
'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}`),
result
)
}
var ignore = params.ignore || null
if (typeof ignore === 'number') {
ignore = [ignore]
}
// build request object
const parts = [params['index'], '_upgrade']
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 = buildIndicesUpgrade