From 55c507c423bddb1d570a7901ad14635c6ff8b64c Mon Sep 17 00:00:00 2001 From: delvedor Date: Tue, 30 Oct 2018 17:26:22 +0100 Subject: [PATCH] API generation --- api/api/bulk.js | 140 ++++++++++ api/api/cat.aliases.js | 121 ++++++++ api/api/cat.allocation.js | 124 +++++++++ api/api/cat.count.js | 121 ++++++++ api/api/cat.fielddata.js | 127 +++++++++ api/api/cat.health.js | 123 +++++++++ api/api/cat.help.js | 105 +++++++ api/api/cat.indices.js | 130 +++++++++ api/api/cat.master.js | 120 ++++++++ api/api/cat.nodeattrs.js | 120 ++++++++ api/api/cat.nodes.js | 123 +++++++++ api/api/cat.pending_tasks.js | 120 ++++++++ api/api/cat.plugins.js | 120 ++++++++ api/api/cat.recovery.js | 121 ++++++++ api/api/cat.repositories.js | 120 ++++++++ api/api/cat.segments.js | 118 ++++++++ api/api/cat.shards.js | 124 +++++++++ api/api/cat.snapshots.js | 121 ++++++++ api/api/cat.tasks.js | 126 +++++++++ api/api/cat.templates.js | 121 ++++++++ api/api/cat.thread_pool.js | 124 +++++++++ api/api/clear_scroll.js | 93 +++++++ api/api/cluster.allocation_explain.js | 98 +++++++ api/api/cluster.get_settings.js | 111 ++++++++ api/api/cluster.health.js | 130 +++++++++ api/api/cluster.pending_tasks.js | 105 +++++++ api/api/cluster.put_settings.js | 109 ++++++++ api/api/cluster.remote_info.js | 99 +++++++ api/api/cluster.reroute.js | 110 ++++++++ api/api/cluster.state.js | 127 +++++++++ api/api/cluster.stats.js | 108 ++++++++ api/api/count.js | 141 ++++++++++ api/api/create.js | 158 +++++++++++ api/api/delete.js | 154 +++++++++++ api/api/delete_by_query.js | 212 ++++++++++++++ api/api/delete_script.js | 112 ++++++++ api/api/exists.js | 166 +++++++++++ api/api/exists_source.js | 163 +++++++++++ api/api/explain.js | 167 ++++++++++++ api/api/field_caps.js | 105 +++++++ api/api/get.js | 166 +++++++++++ api/api/get_script.js | 109 ++++++++ api/api/get_source.js | 163 +++++++++++ api/api/index.js | 155 +++++++++++ api/api/indices.analyze.js | 96 +++++++ api/api/indices.clear_cache.js | 130 +++++++++ api/api/indices.close.js | 121 ++++++++ api/api/indices.create.js | 113 ++++++++ api/api/indices.delete.js | 121 ++++++++ api/api/indices.delete_alias.js | 129 +++++++++ api/api/indices.delete_template.js | 112 ++++++++ api/api/indices.exists.js | 124 +++++++++ api/api/indices.exists_alias.js | 119 ++++++++ api/api/indices.exists_template.js | 115 ++++++++ api/api/indices.exists_type.js | 133 +++++++++ api/api/indices.flush.js | 115 ++++++++ api/api/indices.flush_synced.js | 109 ++++++++ api/api/indices.forcemerge.js | 118 ++++++++ api/api/indices.get.js | 127 +++++++++ api/api/indices.get_alias.js | 113 ++++++++ api/api/indices.get_field_mapping.js | 123 +++++++++ api/api/indices.get_mapping.js | 116 ++++++++ api/api/indices.get_settings.js | 122 +++++++++ api/api/indices.get_template.js | 109 ++++++++ api/api/indices.get_upgrade.js | 109 ++++++++ api/api/indices.open.js | 124 +++++++++ api/api/indices.put_alias.js | 124 +++++++++ api/api/indices.put_mapping.js | 126 +++++++++ api/api/indices.put_settings.js | 122 +++++++++ api/api/indices.put_template.js | 122 +++++++++ api/api/indices.recovery.js | 106 +++++++ api/api/indices.refresh.js | 109 ++++++++ api/api/indices.rollover.js | 122 +++++++++ api/api/indices.segments.js | 112 ++++++++ api/api/indices.shard_stores.js | 112 ++++++++ api/api/indices.shrink.js | 128 +++++++++ api/api/indices.split.js | 128 +++++++++ api/api/indices.stats.js | 122 +++++++++ api/api/indices.update_aliases.js | 106 +++++++ api/api/indices.upgrade.js | 115 ++++++++ api/api/indices.validate_query.js | 138 ++++++++++ api/api/info.js | 99 +++++++ api/api/ingest.delete_pipeline.js | 112 ++++++++ api/api/ingest.get_pipeline.js | 103 +++++++ api/api/ingest.processor_grok.js | 99 +++++++ api/api/ingest.put_pipeline.js | 113 ++++++++ api/api/ingest.simulate.js | 104 +++++++ api/api/mget.js | 134 +++++++++ api/api/msearch.js | 122 +++++++++ api/api/msearch_template.js | 119 ++++++++ api/api/mtermvectors.js | 141 ++++++++++ api/api/nodes.hot_threads.js | 120 ++++++++ api/api/nodes.info.js | 107 ++++++++ api/api/nodes.stats.js | 126 +++++++++ api/api/nodes.usage.js | 104 +++++++ api/api/ping.js | 99 +++++++ api/api/put_script.js | 125 +++++++++ api/api/rank_eval.js | 110 ++++++++ api/api/reindex.js | 118 ++++++++ api/api/reindex_rethrottle.js | 117 ++++++++ api/api/render_search_template.js | 93 +++++++ api/api/scripts_painless_execute.js | 92 +++++++ api/api/scroll.js | 99 +++++++ api/api/search.js | 216 +++++++++++++++ api/api/search_shards.js | 118 ++++++++ api/api/search_template.js | 140 ++++++++++ api/api/snapshot.create.js | 122 +++++++++ api/api/snapshot.create_repository.js | 116 ++++++++ api/api/snapshot.delete.js | 124 +++++++++ api/api/snapshot.delete_repository.js | 112 ++++++++ api/api/snapshot.get.js | 130 +++++++++ api/api/snapshot.get_repository.js | 106 +++++++ api/api/snapshot.restore.js | 122 +++++++++ api/api/snapshot.status.js | 115 ++++++++ api/api/snapshot.verify_repository.js | 112 ++++++++ api/api/tasks.cancel.js | 109 ++++++++ api/api/tasks.get.js | 112 ++++++++ api/api/tasks.list.js | 120 ++++++++ api/api/termvectors.js | 158 +++++++++++ api/api/update.js | 173 ++++++++++++ api/api/update_by_query.js | 212 ++++++++++++++ api/index.js | 379 ++++++++++++++++++++++++++ index.js | 16 +- 123 files changed, 15280 insertions(+), 8 deletions(-) create mode 100644 api/api/bulk.js create mode 100644 api/api/cat.aliases.js create mode 100644 api/api/cat.allocation.js create mode 100644 api/api/cat.count.js create mode 100644 api/api/cat.fielddata.js create mode 100644 api/api/cat.health.js create mode 100644 api/api/cat.help.js create mode 100644 api/api/cat.indices.js create mode 100644 api/api/cat.master.js create mode 100644 api/api/cat.nodeattrs.js create mode 100644 api/api/cat.nodes.js create mode 100644 api/api/cat.pending_tasks.js create mode 100644 api/api/cat.plugins.js create mode 100644 api/api/cat.recovery.js create mode 100644 api/api/cat.repositories.js create mode 100644 api/api/cat.segments.js create mode 100644 api/api/cat.shards.js create mode 100644 api/api/cat.snapshots.js create mode 100644 api/api/cat.tasks.js create mode 100644 api/api/cat.templates.js create mode 100644 api/api/cat.thread_pool.js create mode 100644 api/api/clear_scroll.js create mode 100644 api/api/cluster.allocation_explain.js create mode 100644 api/api/cluster.get_settings.js create mode 100644 api/api/cluster.health.js create mode 100644 api/api/cluster.pending_tasks.js create mode 100644 api/api/cluster.put_settings.js create mode 100644 api/api/cluster.remote_info.js create mode 100644 api/api/cluster.reroute.js create mode 100644 api/api/cluster.state.js create mode 100644 api/api/cluster.stats.js create mode 100644 api/api/count.js create mode 100644 api/api/create.js create mode 100644 api/api/delete.js create mode 100644 api/api/delete_by_query.js create mode 100644 api/api/delete_script.js create mode 100644 api/api/exists.js create mode 100644 api/api/exists_source.js create mode 100644 api/api/explain.js create mode 100644 api/api/field_caps.js create mode 100644 api/api/get.js create mode 100644 api/api/get_script.js create mode 100644 api/api/get_source.js create mode 100644 api/api/index.js create mode 100644 api/api/indices.analyze.js create mode 100644 api/api/indices.clear_cache.js create mode 100644 api/api/indices.close.js create mode 100644 api/api/indices.create.js create mode 100644 api/api/indices.delete.js create mode 100644 api/api/indices.delete_alias.js create mode 100644 api/api/indices.delete_template.js create mode 100644 api/api/indices.exists.js create mode 100644 api/api/indices.exists_alias.js create mode 100644 api/api/indices.exists_template.js create mode 100644 api/api/indices.exists_type.js create mode 100644 api/api/indices.flush.js create mode 100644 api/api/indices.flush_synced.js create mode 100644 api/api/indices.forcemerge.js create mode 100644 api/api/indices.get.js create mode 100644 api/api/indices.get_alias.js create mode 100644 api/api/indices.get_field_mapping.js create mode 100644 api/api/indices.get_mapping.js create mode 100644 api/api/indices.get_settings.js create mode 100644 api/api/indices.get_template.js create mode 100644 api/api/indices.get_upgrade.js create mode 100644 api/api/indices.open.js create mode 100644 api/api/indices.put_alias.js create mode 100644 api/api/indices.put_mapping.js create mode 100644 api/api/indices.put_settings.js create mode 100644 api/api/indices.put_template.js create mode 100644 api/api/indices.recovery.js create mode 100644 api/api/indices.refresh.js create mode 100644 api/api/indices.rollover.js create mode 100644 api/api/indices.segments.js create mode 100644 api/api/indices.shard_stores.js create mode 100644 api/api/indices.shrink.js create mode 100644 api/api/indices.split.js create mode 100644 api/api/indices.stats.js create mode 100644 api/api/indices.update_aliases.js create mode 100644 api/api/indices.upgrade.js create mode 100644 api/api/indices.validate_query.js create mode 100644 api/api/info.js create mode 100644 api/api/ingest.delete_pipeline.js create mode 100644 api/api/ingest.get_pipeline.js create mode 100644 api/api/ingest.processor_grok.js create mode 100644 api/api/ingest.put_pipeline.js create mode 100644 api/api/ingest.simulate.js create mode 100644 api/api/mget.js create mode 100644 api/api/msearch.js create mode 100644 api/api/msearch_template.js create mode 100644 api/api/mtermvectors.js create mode 100644 api/api/nodes.hot_threads.js create mode 100644 api/api/nodes.info.js create mode 100644 api/api/nodes.stats.js create mode 100644 api/api/nodes.usage.js create mode 100644 api/api/ping.js create mode 100644 api/api/put_script.js create mode 100644 api/api/rank_eval.js create mode 100644 api/api/reindex.js create mode 100644 api/api/reindex_rethrottle.js create mode 100644 api/api/render_search_template.js create mode 100644 api/api/scripts_painless_execute.js create mode 100644 api/api/scroll.js create mode 100644 api/api/search.js create mode 100644 api/api/search_shards.js create mode 100644 api/api/search_template.js create mode 100644 api/api/snapshot.create.js create mode 100644 api/api/snapshot.create_repository.js create mode 100644 api/api/snapshot.delete.js create mode 100644 api/api/snapshot.delete_repository.js create mode 100644 api/api/snapshot.get.js create mode 100644 api/api/snapshot.get_repository.js create mode 100644 api/api/snapshot.restore.js create mode 100644 api/api/snapshot.status.js create mode 100644 api/api/snapshot.verify_repository.js create mode 100644 api/api/tasks.cancel.js create mode 100644 api/api/tasks.get.js create mode 100644 api/api/tasks.list.js create mode 100644 api/api/termvectors.js create mode 100644 api/api/update.js create mode 100644 api/api/update_by_query.js create mode 100644 api/index.js diff --git a/api/api/bulk.js b/api/api/bulk.js new file mode 100644 index 000000000..bba62c2bd --- /dev/null +++ b/api/api/bulk.js @@ -0,0 +1,140 @@ +'use strict' + +function buildBulk (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [bulk](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html) request + * + * @param {string} index - Default index for items which don't provide one + * @param {string} type - Default document type for items which don't provide one + * @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before proceeding with the bulk 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 {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 {string} type - Default document type for items which don't provide one + * @param {list} fields - Default comma-separated list of fields to return in the response for updates, can be overridden on each sub-request + * @param {list} _source - True or false to return the _source field or not, or default list of fields to return, can be overridden on each sub-request + * @param {list} _source_exclude - Default list of fields to exclude from the returned _source field, can be overridden on each sub-request + * @param {list} _source_include - Default list of fields to extract and return from the _source field, can be overridden on each sub-request + * @param {string} pipeline - The pipeline id to preprocess incoming documents with + * @param {object} body - The operation definition and data (action-data pairs), separated by newlines + */ + return function bulk (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + bulk(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'refresh', + 'routing', + 'timeout', + 'type', + 'fields', + '_source', + '_source_exclude', + '_source_include', + 'pipeline', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'refresh', + 'routing', + 'timeout', + 'type', + 'fields', + '_source', + '_sourceExclude', + '_sourceInclude', + 'pipeline', + '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'], params['type'], '_bulk'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + bulkBody: params.body, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildBulk diff --git a/api/api/cat.aliases.js b/api/api/cat.aliases.js new file mode 100644 index 000000000..24e48fa8c --- /dev/null +++ b/api/api/cat.aliases.js @@ -0,0 +1,121 @@ +'use strict' + +function buildCatAliases (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.aliases](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html) request + * + * @param {list} name - A comma-separated list of alias names to return + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catAliases (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catAliases(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'aliases', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatAliases diff --git a/api/api/cat.allocation.js b/api/api/cat.allocation.js new file mode 100644 index 000000000..1abd0c58b --- /dev/null +++ b/api/api/cat.allocation.js @@ -0,0 +1,124 @@ +'use strict' + +function buildCatAllocation (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.allocation](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html) request + * + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catAllocation (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catAllocation(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'allocation', params['node_id'] || params['nodeId']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatAllocation diff --git a/api/api/cat.count.js b/api/api/cat.count.js new file mode 100644 index 000000000..87136212c --- /dev/null +++ b/api/api/cat.count.js @@ -0,0 +1,121 @@ +'use strict' + +function buildCatCount (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.count](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html) request + * + * @param {list} index - A comma-separated list of index names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catCount (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catCount(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'count', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatCount diff --git a/api/api/cat.fielddata.js b/api/api/cat.fielddata.js new file mode 100644 index 000000000..3c1476ba2 --- /dev/null +++ b/api/api/cat.fielddata.js @@ -0,0 +1,127 @@ +'use strict' + +function buildCatFielddata (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.fielddata](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html) request + * + * @param {list} fields - A comma-separated list of fields to return the fielddata size + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + * @param {list} fields - A comma-separated list of fields to return in the output + */ + return function catFielddata (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catFielddata(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'fields', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + 'fields', + '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 = 'GET' + } + + // 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 = ['_cat', 'fielddata', params['fields']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatFielddata diff --git a/api/api/cat.health.js b/api/api/cat.health.js new file mode 100644 index 000000000..738895a6a --- /dev/null +++ b/api/api/cat.health.js @@ -0,0 +1,123 @@ +'use strict' + +function buildCatHealth (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} ts - Set to false to disable timestamping + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catHealth (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catHealth(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'ts', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'ts', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'health'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatHealth diff --git a/api/api/cat.help.js b/api/api/cat.help.js new file mode 100644 index 000000000..3c25f7b00 --- /dev/null +++ b/api/api/cat.help.js @@ -0,0 +1,105 @@ +'use strict' + +function buildCatHelp (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.help](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html) request + * + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + */ + return function catHelp (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catHelp(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'help', + 's', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'help', + 's', + '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 = 'GET' + } + + // 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 = ['_cat'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatHelp diff --git a/api/api/cat.indices.js b/api/api/cat.indices.js new file mode 100644 index 000000000..0d3bcfea0 --- /dev/null +++ b/api/api/cat.indices.js @@ -0,0 +1,130 @@ +'use strict' + +function buildCatIndices (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.indices](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html) request + * + * @param {list} index - A comma-separated list of index names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {enum} health - A health status ("green", "yellow", or "red" to filter only indices matching the specified health status + * @param {boolean} help - Return help information + * @param {boolean} pri - Set to true to return stats only for primary shards + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catIndices (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catIndices(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'local', + 'master_timeout', + 'h', + 'health', + 'help', + 'pri', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'local', + 'masterTimeout', + 'h', + 'health', + 'help', + 'pri', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'indices', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatIndices diff --git a/api/api/cat.master.js b/api/api/cat.master.js new file mode 100644 index 000000000..184bd06ca --- /dev/null +++ b/api/api/cat.master.js @@ -0,0 +1,120 @@ +'use strict' + +function buildCatMaster (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.master](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catMaster (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catMaster(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'master'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatMaster diff --git a/api/api/cat.nodeattrs.js b/api/api/cat.nodeattrs.js new file mode 100644 index 000000000..bca45c397 --- /dev/null +++ b/api/api/cat.nodeattrs.js @@ -0,0 +1,120 @@ +'use strict' + +function buildCatNodeattrs (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.nodeattrs](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catNodeattrs (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catNodeattrs(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'nodeattrs'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatNodeattrs diff --git a/api/api/cat.nodes.js b/api/api/cat.nodes.js new file mode 100644 index 000000000..4a45dd5f5 --- /dev/null +++ b/api/api/cat.nodes.js @@ -0,0 +1,123 @@ +'use strict' + +function buildCatNodes (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.nodes](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} full_id - Return the full node ID instead of the shortened version (default: false) + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catNodes (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catNodes(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'full_id', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'fullId', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'nodes'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatNodes diff --git a/api/api/cat.pending_tasks.js b/api/api/cat.pending_tasks.js new file mode 100644 index 000000000..8b9caa342 --- /dev/null +++ b/api/api/cat.pending_tasks.js @@ -0,0 +1,120 @@ +'use strict' + +function buildCatPendingTasks (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.pending_tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catPendingTasks (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catPendingTasks(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'pending_tasks'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatPendingTasks diff --git a/api/api/cat.plugins.js b/api/api/cat.plugins.js new file mode 100644 index 000000000..2b9d3a336 --- /dev/null +++ b/api/api/cat.plugins.js @@ -0,0 +1,120 @@ +'use strict' + +function buildCatPlugins (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.plugins](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catPlugins (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catPlugins(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'plugins'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatPlugins diff --git a/api/api/cat.recovery.js b/api/api/cat.recovery.js new file mode 100644 index 000000000..11850a0d5 --- /dev/null +++ b/api/api/cat.recovery.js @@ -0,0 +1,121 @@ +'use strict' + +function buildCatRecovery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.recovery](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html) request + * + * @param {list} index - A comma-separated list of index names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catRecovery (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catRecovery(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'recovery', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatRecovery diff --git a/api/api/cat.repositories.js b/api/api/cat.repositories.js new file mode 100644 index 000000000..a736f6380 --- /dev/null +++ b/api/api/cat.repositories.js @@ -0,0 +1,120 @@ +'use strict' + +function buildCatRepositories (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.repositories](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catRepositories (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catRepositories(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'repositories'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatRepositories diff --git a/api/api/cat.segments.js b/api/api/cat.segments.js new file mode 100644 index 000000000..b7e6eecbb --- /dev/null +++ b/api/api/cat.segments.js @@ -0,0 +1,118 @@ +'use strict' + +function buildCatSegments (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.segments](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html) request + * + * @param {list} index - A comma-separated list of index names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catSegments (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catSegments(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'segments', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatSegments diff --git a/api/api/cat.shards.js b/api/api/cat.shards.js new file mode 100644 index 000000000..3313d3d50 --- /dev/null +++ b/api/api/cat.shards.js @@ -0,0 +1,124 @@ +'use strict' + +function buildCatShards (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.shards](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html) request + * + * @param {list} index - A comma-separated list of index names to limit the returned information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} bytes - The unit in which to display byte values + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catShards (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catShards(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'bytes', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'bytes', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'shards', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatShards diff --git a/api/api/cat.snapshots.js b/api/api/cat.snapshots.js new file mode 100644 index 000000000..455a0488e --- /dev/null +++ b/api/api/cat.snapshots.js @@ -0,0 +1,121 @@ +'use strict' + +function buildCatSnapshots (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.snapshots](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html) request + * + * @param {list} repository - Name of repository from which to fetch the snapshot information + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} ignore_unavailable - Set to true to ignore unavailable snapshots + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catSnapshots (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catSnapshots(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'ignore_unavailable', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'ignoreUnavailable', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'snapshots', params['repository']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatSnapshots diff --git a/api/api/cat.tasks.js b/api/api/cat.tasks.js new file mode 100644 index 000000000..bed6b98b8 --- /dev/null +++ b/api/api/cat.tasks.js @@ -0,0 +1,126 @@ +'use strict' + +function buildCatTasks (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {list} actions - A comma-separated list of actions that should be returned. Leave empty to return all. + * @param {boolean} detailed - Return detailed task information (default: false) + * @param {number} parent_task - Return tasks with specified parent task id. Set to -1 to return all. + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catTasks (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catTasks(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'node_id', + 'actions', + 'detailed', + 'parent_task', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'nodeId', + 'actions', + 'detailed', + 'parentTask', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'tasks'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatTasks diff --git a/api/api/cat.templates.js b/api/api/cat.templates.js new file mode 100644 index 000000000..c49f9901e --- /dev/null +++ b/api/api/cat.templates.js @@ -0,0 +1,121 @@ +'use strict' + +function buildCatTemplates (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.templates](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-templates.html) request + * + * @param {string} name - A pattern that returned template names must match + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catTemplates (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catTemplates(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'templates', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatTemplates diff --git a/api/api/cat.thread_pool.js b/api/api/cat.thread_pool.js new file mode 100644 index 000000000..a37473d5d --- /dev/null +++ b/api/api/cat.thread_pool.js @@ -0,0 +1,124 @@ +'use strict' + +function buildCatThreadPool (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cat.thread_pool](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html) request + * + * @param {list} thread_pool_patterns - A comma-separated list of regular-expressions to filter the thread pools in the output + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {enum} size - The multiplier in which to display values + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {list} h - Comma-separated list of column names to display + * @param {boolean} help - Return help information + * @param {list} s - Comma-separated list of column names or column aliases to sort by + * @param {boolean} v - Verbose mode. Display column headers + */ + return function catThreadPool (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + catThreadPool(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'format', + 'size', + 'local', + 'master_timeout', + 'h', + 'help', + 's', + 'v', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'format', + 'size', + 'local', + 'masterTimeout', + 'h', + 'help', + 's', + 'v', + '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 = 'GET' + } + + // 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 = ['_cat', 'thread_pool', params['thread_pool_patterns'] || params['threadPoolPatterns']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCatThreadPool diff --git a/api/api/clear_scroll.js b/api/api/clear_scroll.js new file mode 100644 index 000000000..51668e8da --- /dev/null +++ b/api/api/clear_scroll.js @@ -0,0 +1,93 @@ +'use strict' + +function buildClearScroll (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [clear_scroll](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html) request + * + * @param {list} scroll_id - A comma-separated list of scroll IDs to clear + * @param {object} body - A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter + */ + return function clearScroll (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clearScroll(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'DELETE' + } + + // 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 = ['_search', 'scroll', params['scroll_id'] || params['scrollId']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClearScroll diff --git a/api/api/cluster.allocation_explain.js b/api/api/cluster.allocation_explain.js new file mode 100644 index 000000000..2a2e9a541 --- /dev/null +++ b/api/api/cluster.allocation_explain.js @@ -0,0 +1,98 @@ +'use strict' + +function buildClusterAllocationExplain (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.allocation_explain](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html) request + * + * @param {boolean} include_yes_decisions - Return 'YES' decisions in explanation (default: false) + * @param {boolean} include_disk_info - Return information about disk usage and shard sizes (default: false) + * @param {object} body - The index, shard, and primary flag to explain. Empty means 'explain the first unassigned shard' + */ + return function clusterAllocationExplain (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterAllocationExplain(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'include_yes_decisions', + 'include_disk_info', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'includeYesDecisions', + 'includeDiskInfo', + '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 = params.body == null ? 'GET' : '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 = ['_cluster', 'allocation', 'explain'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterAllocationExplain diff --git a/api/api/cluster.get_settings.js b/api/api/cluster.get_settings.js new file mode 100644 index 000000000..b99e539c9 --- /dev/null +++ b/api/api/cluster.get_settings.js @@ -0,0 +1,111 @@ +'use strict' + +function buildClusterGetSettings (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.get_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html) request + * + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {boolean} include_defaults - Whether to return all default clusters setting. + */ + return function clusterGetSettings (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterGetSettings(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flat_settings', + 'master_timeout', + 'timeout', + 'include_defaults', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'masterTimeout', + 'timeout', + 'includeDefaults', + '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 = 'GET' + } + + // 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 = ['_cluster', 'settings'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterGetSettings diff --git a/api/api/cluster.health.js b/api/api/cluster.health.js new file mode 100644 index 000000000..a318a1a53 --- /dev/null +++ b/api/api/cluster.health.js @@ -0,0 +1,130 @@ +'use strict' + +function buildClusterHealth (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html) request + * + * @param {list} index - Limit the information returned to a specific index + * @param {enum} level - Specify the level of detail for returned information + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {string} wait_for_active_shards - Wait until the specified number of shards is active + * @param {string} wait_for_nodes - Wait until the specified number of nodes is available + * @param {enum} wait_for_events - Wait until all currently queued events with the given priority are processed + * @param {boolean} wait_for_no_relocating_shards - Whether to wait until there are no relocating shards in the cluster + * @param {boolean} wait_for_no_initializing_shards - Whether to wait until there are no initializing shards in the cluster + * @param {enum} wait_for_status - Wait until cluster is in a specific state + */ + return function clusterHealth (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterHealth(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'level', + 'local', + 'master_timeout', + 'timeout', + 'wait_for_active_shards', + 'wait_for_nodes', + 'wait_for_events', + 'wait_for_no_relocating_shards', + 'wait_for_no_initializing_shards', + 'wait_for_status', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'level', + 'local', + 'masterTimeout', + 'timeout', + 'waitForActiveShards', + 'waitForNodes', + 'waitForEvents', + 'waitForNoRelocatingShards', + 'waitForNoInitializingShards', + 'waitForStatus', + '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 = 'GET' + } + + // 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 = ['_cluster', 'health', params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterHealth diff --git a/api/api/cluster.pending_tasks.js b/api/api/cluster.pending_tasks.js new file mode 100644 index 000000000..e9ff7e10f --- /dev/null +++ b/api/api/cluster.pending_tasks.js @@ -0,0 +1,105 @@ +'use strict' + +function buildClusterPendingTasks (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.pending_tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html) request + * + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function clusterPendingTasks (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterPendingTasks(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'local', + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'local', + 'masterTimeout', + '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 = 'GET' + } + + // 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 = ['_cluster', 'pending_tasks'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterPendingTasks diff --git a/api/api/cluster.put_settings.js b/api/api/cluster.put_settings.js new file mode 100644 index 000000000..d161d20d1 --- /dev/null +++ b/api/api/cluster.put_settings.js @@ -0,0 +1,109 @@ +'use strict' + +function buildClusterPutSettings (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.put_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html) request + * + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {object} body - The settings to be updated. Can be either `transient` or `persistent` (survives cluster restart). + */ + return function clusterPutSettings (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterPutSettings(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flat_settings', + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'masterTimeout', + 'timeout', + '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 = 'PUT' + } + + // 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 = ['_cluster', 'settings'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterPutSettings diff --git a/api/api/cluster.remote_info.js b/api/api/cluster.remote_info.js new file mode 100644 index 000000000..6626f0530 --- /dev/null +++ b/api/api/cluster.remote_info.js @@ -0,0 +1,99 @@ +'use strict' + +function buildClusterRemoteInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.remote_info](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html) request + * + */ + return function clusterRemoteInfo (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterRemoteInfo(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'GET' + } + + // 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 = ['_remote', 'info'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterRemoteInfo diff --git a/api/api/cluster.reroute.js b/api/api/cluster.reroute.js new file mode 100644 index 000000000..04e7d39a9 --- /dev/null +++ b/api/api/cluster.reroute.js @@ -0,0 +1,110 @@ +'use strict' + +function buildClusterReroute (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.reroute](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html) request + * + * @param {boolean} dry_run - Simulate the operation only and return the resulting state + * @param {boolean} explain - Return an explanation of why the commands can or cannot be executed + * @param {boolean} retry_failed - Retries allocation of shards that are blocked due to too many subsequent allocation failures + * @param {list} metric - Limit the information returned to the specified metrics. Defaults to all but metadata + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {object} body - The definition of `commands` to perform (`move`, `cancel`, `allocate`) + */ + return function clusterReroute (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterReroute(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'dry_run', + 'explain', + 'retry_failed', + 'metric', + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'dryRun', + 'explain', + 'retryFailed', + 'metric', + 'masterTimeout', + 'timeout', + '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 = ['_cluster', 'reroute'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterReroute diff --git a/api/api/cluster.state.js b/api/api/cluster.state.js new file mode 100644 index 000000000..1a47ce670 --- /dev/null +++ b/api/api/cluster.state.js @@ -0,0 +1,127 @@ +'use strict' + +function buildClusterState (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.state](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.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 {list} metric - Limit the information returned to the specified metrics + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {time} master_timeout - Specify timeout for connection to master + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @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 clusterState (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterState(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['index'] != null && (params['metric'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: metric'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'local', + 'master_timeout', + 'flat_settings', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'local', + 'masterTimeout', + 'flatSettings', + '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 = 'GET' + } + + // 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 = ['_cluster', 'state', params['metric'], params['index']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterState diff --git a/api/api/cluster.stats.js b/api/api/cluster.stats.js new file mode 100644 index 000000000..efc361d97 --- /dev/null +++ b/api/api/cluster.stats.js @@ -0,0 +1,108 @@ +'use strict' + +function buildClusterStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [cluster.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html) request + * + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} timeout - Explicit operation timeout + */ + return function clusterStats (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + clusterStats(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flat_settings', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'timeout', + '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 = 'GET' + } + + // 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 = ['_cluster', 'stats', 'nodes', params['node_id'] || params['nodeId']] + const request = { + method, + path: (params['node_id'] || params['nodeId']) != null + ? '/' + parts.filter(Boolean).join('/') + : '/_cluster/stats', + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildClusterStats diff --git a/api/api/count.js b/api/api/count.js new file mode 100644 index 000000000..d955bdd0b --- /dev/null +++ b/api/api/count.js @@ -0,0 +1,141 @@ +'use strict' + +function buildCount (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [count](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html) request + * + * @param {list} index - A comma-separated list of indices to restrict the results + * @param {list} type - A comma-separated list of types to restrict the results + * @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. + * @param {number} min_score - Include only documents with a specific `_score` value in the result + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {list} routing - A comma-separated list of specific routing values + * @param {string} q - Query in the Lucene query string syntax + * @param {string} analyzer - The analyzer to use for the query string + * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The field to use as default where no field prefix is given in the query string + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {number} terminate_after - The maximum count for each shard, upon reaching which the query execution will terminate early + * @param {object} body - A query to restrict the results specified with the Query DSL (optional) + */ + return function count (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + count(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'min_score', + 'preference', + 'routing', + 'q', + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'lenient', + 'terminate_after', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'minScore', + 'preference', + 'routing', + 'q', + 'analyzer', + 'analyzeWildcard', + 'defaultOperator', + 'df', + 'lenient', + 'terminateAfter', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_count'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCount diff --git a/api/api/create.js b/api/api/create.js new file mode 100644 index 000000000..034243834 --- /dev/null +++ b/api/api/create.js @@ -0,0 +1,158 @@ +'use strict' + +function buildCreate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [create](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html) request + * + * @param {string} id - 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 index 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 the parent document + * @param {enum} refresh - If `true` then refresh the affected 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 + * @param {string} pipeline - The pipeline id to preprocess incoming documents with + * @param {object} body - The document + */ + return function create (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + create(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'pipeline', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'versionType', + 'pipeline', + '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 = 'PUT' + } + + // 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'], params['type'], params['id'], '_create'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildCreate diff --git a/api/api/delete.js b/api/api/delete.js new file mode 100644 index 000000000..884a213f6 --- /dev/null +++ b/api/api/delete.js @@ -0,0 +1,154 @@ +'use strict' + +function buildDelete (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/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 + */ + return function _delete (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + _delete(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'versionType', + '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 = 'DELETE' + } + + // 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'], params['type'], params['id']] + 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 = buildDelete diff --git a/api/api/delete_by_query.js b/api/api/delete_by_query.js new file mode 100644 index 000000000..65796dcfe --- /dev/null +++ b/api/api/delete_by_query.js @@ -0,0 +1,212 @@ +'use strict' + +function buildDeleteByQuery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [delete_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to search; leave empty to perform the operation on all types + * @param {string} analyzer - The analyzer to use for the query string + * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The field to use as default where no field prefix is given in the query string + * @param {number} from - Starting offset (default: 0) + * @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} conflicts - What to do when the delete by query hits version conflicts? + * @param {enum} expand_wildcards - Whether to expand wildcard expression to concrete indices that are open, closed or both. + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {string} q - Query in the Lucene query string syntax + * @param {list} routing - A comma-separated list of specific routing values + * @param {time} scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {enum} search_type - Search operation type + * @param {time} search_timeout - Explicit timeout for each search request. Defaults to no timeout. + * @param {number} size - Number of hits to return (default: 10) + * @param {list} sort - A comma-separated list of : pairs + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} terminate_after - The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * @param {list} stats - Specific 'tag' of the request for logging and statistical purposes + * @param {boolean} version - Specify whether to return document version as part of a hit + * @param {boolean} request_cache - Specify if request cache should be used for this request or not, defaults to index level setting + * @param {boolean} refresh - Should the effected indexes be refreshed? + * @param {time} timeout - Time each individual bulk request should wait for shards that are unavailable. + * @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before proceeding with the delete by query 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 {number} scroll_size - Size on the scroll request powering the delete by query + * @param {boolean} wait_for_completion - Should the request should block until the delete by query is complete. + * @param {number} requests_per_second - The throttle for this request in sub-requests per second. -1 means no throttle. + * @param {number} slices - The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. + * @param {object} body - The search definition using the Query DSL + */ + return function deleteByQuery (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + deleteByQuery(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('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'from', + 'ignore_unavailable', + 'allow_no_indices', + 'conflicts', + 'expand_wildcards', + 'lenient', + 'preference', + 'q', + 'routing', + 'scroll', + 'search_type', + 'search_timeout', + 'size', + 'sort', + '_source', + '_source_exclude', + '_source_include', + 'terminate_after', + 'stats', + 'version', + 'request_cache', + 'refresh', + 'timeout', + 'wait_for_active_shards', + 'scroll_size', + 'wait_for_completion', + 'requests_per_second', + 'slices', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'analyzer', + 'analyzeWildcard', + 'defaultOperator', + 'df', + 'from', + 'ignoreUnavailable', + 'allowNoIndices', + 'conflicts', + 'expandWildcards', + 'lenient', + 'preference', + 'q', + 'routing', + 'scroll', + 'searchType', + 'searchTimeout', + 'size', + 'sort', + '_source', + '_sourceExclude', + '_sourceInclude', + 'terminateAfter', + 'stats', + 'version', + 'requestCache', + 'refresh', + 'timeout', + 'waitForActiveShards', + 'scrollSize', + 'waitForCompletion', + 'requestsPerSecond', + 'slices', + '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'], params['type'], '_delete_by_query'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildDeleteByQuery diff --git a/api/api/delete_script.js b/api/api/delete_script.js new file mode 100644 index 000000000..f1945790c --- /dev/null +++ b/api/api/delete_script.js @@ -0,0 +1,112 @@ +'use strict' + +function buildDeleteScript (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [delete_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request + * + * @param {string} id - Script ID + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function deleteScript (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + deleteScript(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { 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', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + '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 = 'DELETE' + } + + // 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 = ['_scripts', params['id']] + 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 = buildDeleteScript diff --git a/api/api/exists.js b/api/api/exists.js new file mode 100644 index 000000000..f2e229dc2 --- /dev/null +++ b/api/api/exists.js @@ -0,0 +1,166 @@ +'use strict' + +function buildExists (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [exists](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request + * + * @param {string} id - The document ID + * @param {string} index - The name of the index + * @param {string} type - The type of the document (use `_all` to fetch the first document matching the ID across all types) + * @param {list} stored_fields - A comma-separated list of stored fields to return in the response + * @param {string} parent - The ID of the parent document + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {boolean} realtime - Specify whether to perform the operation in realtime or search mode + * @param {boolean} refresh - Refresh the shard containing the document before performing the operation + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + */ + return function exists (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + exists(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'stored_fields', + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'storedFields', + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + 'version', + 'versionType', + '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 = 'HEAD' + } + + // 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'], params['type'], params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildExists diff --git a/api/api/exists_source.js b/api/api/exists_source.js new file mode 100644 index 000000000..1d17db7be --- /dev/null +++ b/api/api/exists_source.js @@ -0,0 +1,163 @@ +'use strict' + +function buildExistsSource (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [exists_source](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request + * + * @param {string} id - The document ID + * @param {string} index - The name of the index + * @param {string} type - The type of the document; use `_all` to fetch the first document matching the ID across all types + * @param {string} parent - The ID of the parent document + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {boolean} realtime - Specify whether to perform the operation in realtime or search mode + * @param {boolean} refresh - Refresh the shard containing the document before performing the operation + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + */ + return function existsSource (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + existsSource(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + 'version', + 'versionType', + '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 = 'HEAD' + } + + // 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'], params['type'], params['id'], '_source'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildExistsSource diff --git a/api/api/explain.js b/api/api/explain.js new file mode 100644 index 000000000..1f342b291 --- /dev/null +++ b/api/api/explain.js @@ -0,0 +1,167 @@ +'use strict' + +function buildExplain (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [explain](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.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 {boolean} analyze_wildcard - Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false) + * @param {string} analyzer - The analyzer for the query string query + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The default field for query string query (default: _all) + * @param {list} stored_fields - A comma-separated list of stored fields to return in the response + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {string} parent - The ID of the parent document + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {string} q - Query in the Lucene query string syntax + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {object} body - The query definition using the Query DSL + */ + return function explain (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + explain(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'analyze_wildcard', + 'analyzer', + 'default_operator', + 'df', + 'stored_fields', + 'lenient', + 'parent', + 'preference', + 'q', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'analyzeWildcard', + 'analyzer', + 'defaultOperator', + 'df', + 'storedFields', + 'lenient', + 'parent', + 'preference', + 'q', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + '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 = params.body == null ? 'GET' : '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'], params['type'], params['id'], '_explain'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildExplain diff --git a/api/api/field_caps.js b/api/api/field_caps.js new file mode 100644 index 000000000..d415fb509 --- /dev/null +++ b/api/api/field_caps.js @@ -0,0 +1,105 @@ +'use strict' + +function buildFieldCaps (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [field_caps](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.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 {list} fields - A comma-separated list of field names + * @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. + * @param {object} body - Field json objects containing an array of field names + */ + return function fieldCaps (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + fieldCaps(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'fields', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'fields', + '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 = params.body == null ? 'GET' : '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'], '_field_caps'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildFieldCaps diff --git a/api/api/get.js b/api/api/get.js new file mode 100644 index 000000000..d234e65df --- /dev/null +++ b/api/api/get.js @@ -0,0 +1,166 @@ +'use strict' + +function buildGet (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [get](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request + * + * @param {string} id - The document ID + * @param {string} index - The name of the index + * @param {string} type - The type of the document (use `_all` to fetch the first document matching the ID across all types) + * @param {list} stored_fields - A comma-separated list of stored fields to return in the response + * @param {string} parent - The ID of the parent document + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {boolean} realtime - Specify whether to perform the operation in realtime or search mode + * @param {boolean} refresh - Refresh the shard containing the document before performing the operation + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + */ + return function get (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + get(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'stored_fields', + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'storedFields', + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + 'version', + 'versionType', + '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 = 'GET' + } + + // 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'], params['type'], params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildGet diff --git a/api/api/get_script.js b/api/api/get_script.js new file mode 100644 index 000000000..bebd680bc --- /dev/null +++ b/api/api/get_script.js @@ -0,0 +1,109 @@ +'use strict' + +function buildGetScript (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [get_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request + * + * @param {string} id - Script ID + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function getScript (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + getScript(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { 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 = [ + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + '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 = 'GET' + } + + // 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 = ['_scripts', params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildGetScript diff --git a/api/api/get_source.js b/api/api/get_source.js new file mode 100644 index 000000000..6a4fc5d55 --- /dev/null +++ b/api/api/get_source.js @@ -0,0 +1,163 @@ +'use strict' + +function buildGetSource (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [get_source](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request + * + * @param {string} id - The document ID + * @param {string} index - The name of the index + * @param {string} type - The type of the document; use `_all` to fetch the first document matching the ID across all types + * @param {string} parent - The ID of the parent document + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {boolean} realtime - Specify whether to perform the operation in realtime or search mode + * @param {boolean} refresh - Refresh the shard containing the document before performing the operation + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + */ + return function getSource (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + getSource(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'parent', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + 'version', + 'versionType', + '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 = 'GET' + } + + // 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'], params['type'], params['id'], '_source'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildGetSource diff --git a/api/api/index.js b/api/api/index.js new file mode 100644 index 000000000..f9a4835f8 --- /dev/null +++ b/api/api/index.js @@ -0,0 +1,155 @@ +'use strict' + +function buildIndex (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [index](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html) request + * + * @param {string} id - 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 index 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 {enum} op_type - Explicit operation type + * @param {string} parent - ID of the parent document + * @param {enum} refresh - If `true` then refresh the affected 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 + * @param {string} pipeline - The pipeline id to preprocess incoming documents with + * @param {object} body - The document + */ + return function index (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + index(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['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'op_type', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'pipeline', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'opType', + 'parent', + 'refresh', + 'routing', + 'timeout', + 'version', + 'versionType', + 'pipeline', + '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'], params['type'], params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndex diff --git a/api/api/indices.analyze.js b/api/api/indices.analyze.js new file mode 100644 index 000000000..d8068bbfa --- /dev/null +++ b/api/api/indices.analyze.js @@ -0,0 +1,96 @@ +'use strict' + +function buildIndicesAnalyze (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.analyze](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html) request + * + * @param {string} index - The name of the index to scope the operation + * @param {string} index - The name of the index to scope the operation + * @param {object} body - Define analyzer/tokenizer parameters and the text on which the analysis should be performed + */ + return function indicesAnalyze (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesAnalyze(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'index', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'index', + '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 = params.body == null ? 'GET' : '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'], '_analyze'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesAnalyze diff --git a/api/api/indices.clear_cache.js b/api/api/indices.clear_cache.js new file mode 100644 index 000000000..cc38b7ecd --- /dev/null +++ b/api/api/indices.clear_cache.js @@ -0,0 +1,130 @@ +'use strict' + +function buildIndicesClearCache (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.clear_cache](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html) request + * + * @param {list} index - A comma-separated list of index name to limit the operation + * @param {boolean} field_data - Clear field data. This is deprecated. Prefer `fielddata`. + * @param {boolean} fielddata - Clear field data + * @param {list} fields - A comma-separated list of fields to clear when using the `fielddata` parameter (default: all) + * @param {boolean} query - Clear query caches + * @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. + * @param {list} index - A comma-separated list of index name to limit the operation + * @param {boolean} request_cache - Clear request cache + * @param {boolean} request - Clear request cache + */ + return function indicesClearCache (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesClearCache(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'field_data', + 'fielddata', + 'fields', + 'query', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'index', + 'request_cache', + 'request', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'fieldData', + 'fielddata', + 'fields', + 'query', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'index', + 'requestCache', + 'request', + '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 = params.body == null ? 'GET' : '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'], '_cache', 'clear'] + 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 = buildIndicesClearCache diff --git a/api/api/indices.close.js b/api/api/indices.close.js new file mode 100644 index 000000000..a33e70dec --- /dev/null +++ b/api/api/indices.close.js @@ -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 diff --git a/api/api/indices.create.js b/api/api/indices.create.js new file mode 100644 index 000000000..c6868d0ea --- /dev/null +++ b/api/api/indices.create.js @@ -0,0 +1,113 @@ +'use strict' + +function buildIndicesCreate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.create](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html) request + * + * @param {string} index - The name of the index + * @param {string} wait_for_active_shards - Set the number of active shards to wait for before the operation returns. + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {boolean} update_all_types - Whether to update the mapping for all fields with the same name across all types or not + * @param {object} body - The configuration for the index (`settings` and `mappings`) + */ + return function indicesCreate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesCreate(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 } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'timeout', + 'master_timeout', + 'update_all_types', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'timeout', + 'masterTimeout', + 'updateAllTypes', + '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 = 'PUT' + } + + // 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']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesCreate diff --git a/api/api/indices.delete.js b/api/api/indices.delete.js new file mode 100644 index 000000000..ffa02d65d --- /dev/null +++ b/api/api/indices.delete.js @@ -0,0 +1,121 @@ +'use strict' + +function buildIndicesDelete (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html) request + * + * @param {list} index - A comma-separated list of indices to delete; use `_all` or `*` string to delete all indices + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {boolean} ignore_unavailable - Ignore unavailable indexes (default: false) + * @param {boolean} allow_no_indices - Ignore if a wildcard expression resolves to no concrete indices (default: false) + * @param {enum} expand_wildcards - Whether wildcard expressions should get expanded to open or closed indices (default: open) + */ + return function indicesDelete (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesDelete(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 = 'DELETE' + } + + // 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']] + 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 = buildIndicesDelete diff --git a/api/api/indices.delete_alias.js b/api/api/indices.delete_alias.js new file mode 100644 index 000000000..7da283f68 --- /dev/null +++ b/api/api/indices.delete_alias.js @@ -0,0 +1,129 @@ +'use strict' + +function buildIndicesDeleteAlias (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.delete_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request + * + * @param {list} index - A comma-separated list of index names (supports wildcards); use `_all` for all indices + * @param {list} name - A comma-separated list of aliases to delete (supports wildcards); use `_all` to delete all aliases for the specified indices. + * @param {time} timeout - Explicit timestamp for the document + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function indicesDeleteAlias (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesDeleteAlias(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['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { 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 } + ) + } + + // check required url components + if (params['name'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + '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 = 'DELETE' + } + + // 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'], '_aliases', params['name']] + const request = { + method, + path: params['index'] != null && params['name'] != null + ? '/' + parts.filter(Boolean).join('/') + : '/{index}/_alias/{name}', + querystring, + body: '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesDeleteAlias diff --git a/api/api/indices.delete_template.js b/api/api/indices.delete_template.js new file mode 100644 index 000000000..3259a896f --- /dev/null +++ b/api/api/indices.delete_template.js @@ -0,0 +1,112 @@ +'use strict' + +function buildIndicesDeleteTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.delete_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request + * + * @param {string} name - The name of the template + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function indicesDeleteTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesDeleteTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { 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', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + '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 = 'DELETE' + } + + // 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 = ['_template', params['name']] + 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 = buildIndicesDeleteTemplate diff --git a/api/api/indices.exists.js b/api/api/indices.exists.js new file mode 100644 index 000000000..436c1656e --- /dev/null +++ b/api/api/indices.exists.js @@ -0,0 +1,124 @@ +'use strict' + +function buildIndicesExists (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.exists](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html) request + * + * @param {list} index - A comma-separated list of index names + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {boolean} ignore_unavailable - Ignore unavailable indexes (default: false) + * @param {boolean} allow_no_indices - Ignore if a wildcard expression resolves to no concrete indices (default: false) + * @param {enum} expand_wildcards - Whether wildcard expressions should get expanded to open or closed indices (default: open) + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {boolean} include_defaults - Whether to return all default setting for each of the indices. + */ + return function indicesExists (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesExists(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 = [ + 'local', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'include_defaults', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'local', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'flatSettings', + 'includeDefaults', + '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 = 'HEAD' + } + + // 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']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesExists diff --git a/api/api/indices.exists_alias.js b/api/api/indices.exists_alias.js new file mode 100644 index 000000000..a076c8fcb --- /dev/null +++ b/api/api/indices.exists_alias.js @@ -0,0 +1,119 @@ +'use strict' + +function buildIndicesExistsAlias (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.exists_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request + * + * @param {list} index - A comma-separated list of index names to filter aliases + * @param {list} name - A comma-separated list of alias names to return + * @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. + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesExistsAlias (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesExistsAlias(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { 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 = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'local', + '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 = 'HEAD' + } + + // 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'], '_alias', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesExistsAlias diff --git a/api/api/indices.exists_template.js b/api/api/indices.exists_template.js new file mode 100644 index 000000000..b2c459c43 --- /dev/null +++ b/api/api/indices.exists_template.js @@ -0,0 +1,115 @@ +'use strict' + +function buildIndicesExistsTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.exists_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request + * + * @param {list} name - The comma separated names of the index templates + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesExistsTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesExistsTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { 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 = [ + 'flat_settings', + 'master_timeout', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'masterTimeout', + 'local', + '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 = 'HEAD' + } + + // 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 = ['_template', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesExistsTemplate diff --git a/api/api/indices.exists_type.js b/api/api/indices.exists_type.js new file mode 100644 index 000000000..7e104eefb --- /dev/null +++ b/api/api/indices.exists_type.js @@ -0,0 +1,133 @@ +'use strict' + +function buildIndicesExistsType (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.exists_type](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html) request + * + * @param {list} index - A comma-separated list of index names; use `_all` to check the types across all indices + * @param {list} type - A comma-separated list of document types to check + * @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. + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesExistsType (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesExistsType(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['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { 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 } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'local', + '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 = 'HEAD' + } + + // 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'], '_mapping', params['type']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesExistsType diff --git a/api/api/indices.flush.js b/api/api/indices.flush.js new file mode 100644 index 000000000..54834a222 --- /dev/null +++ b/api/api/indices.flush.js @@ -0,0 +1,115 @@ +'use strict' + +function buildIndicesFlush (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.flush](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html) request + * + * @param {list} index - A comma-separated list of index names; use `_all` or empty string for all indices + * @param {boolean} force - Whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. This is useful if transaction log IDs should be incremented even if no uncommitted changes are present. (This setting can be considered as internal) + * @param {boolean} wait_if_ongoing - If set to true the flush operation will block until the flush can be executed if another flush operation is already executing. The default is true. If set to false the flush will be skipped iff if another flush operation is already running. + * @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 indicesFlush (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesFlush(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'force', + 'wait_if_ongoing', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'force', + 'waitIfOngoing', + '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 = params.body == null ? 'GET' : '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'], '_flush'] + 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 = buildIndicesFlush diff --git a/api/api/indices.flush_synced.js b/api/api/indices.flush_synced.js new file mode 100644 index 000000000..1c76858f7 --- /dev/null +++ b/api/api/indices.flush_synced.js @@ -0,0 +1,109 @@ +'use strict' + +function buildIndicesFlushSynced (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.flush_synced](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html) request + * + * @param {list} index - A comma-separated list of index names; use `_all` or empty string for all indices + * @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 indicesFlushSynced (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesFlushSynced(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = params.body == null ? 'GET' : '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'], '_flush', 'synced'] + 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 = buildIndicesFlushSynced diff --git a/api/api/indices.forcemerge.js b/api/api/indices.forcemerge.js new file mode 100644 index 000000000..5cf5a3e06 --- /dev/null +++ b/api/api/indices.forcemerge.js @@ -0,0 +1,118 @@ +'use strict' + +function buildIndicesForcemerge (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.forcemerge](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.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} flush - Specify whether the index should be flushed after performing the operation (default: true) + * @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. + * @param {number} max_num_segments - The number of segments the index should be merged into (default: dynamic) + * @param {boolean} only_expunge_deletes - Specify whether the operation should only expunge deleted documents + */ + return function indicesForcemerge (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesForcemerge(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flush', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'max_num_segments', + 'only_expunge_deletes', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flush', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'maxNumSegments', + 'onlyExpungeDeletes', + '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'], '_forcemerge'] + 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 = buildIndicesForcemerge diff --git a/api/api/indices.get.js b/api/api/indices.get.js new file mode 100644 index 000000000..d6bcafa73 --- /dev/null +++ b/api/api/indices.get.js @@ -0,0 +1,127 @@ +'use strict' + +function buildIndicesGet (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html) request + * + * @param {list} index - A comma-separated list of index names + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {boolean} ignore_unavailable - Ignore unavailable indexes (default: false) + * @param {boolean} allow_no_indices - Ignore if a wildcard expression resolves to no concrete indices (default: false) + * @param {enum} expand_wildcards - Whether wildcard expressions should get expanded to open or closed indices (default: open) + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {boolean} include_defaults - Whether to return all default setting for each of the indices. + * @param {time} master_timeout - Specify timeout for connection to master + */ + return function indicesGet (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGet(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 = [ + 'local', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'include_defaults', + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'local', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'flatSettings', + 'includeDefaults', + 'masterTimeout', + '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 = 'GET' + } + + // 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']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGet diff --git a/api/api/indices.get_alias.js b/api/api/indices.get_alias.js new file mode 100644 index 000000000..7925d5238 --- /dev/null +++ b/api/api/indices.get_alias.js @@ -0,0 +1,113 @@ +'use strict' + +function buildIndicesGetAlias (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request + * + * @param {list} index - A comma-separated list of index names to filter aliases + * @param {list} name - A comma-separated list of alias names to return + * @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. + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesGetAlias (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetAlias(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'local', + '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 = 'GET' + } + + // 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'], '_alias', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetAlias diff --git a/api/api/indices.get_field_mapping.js b/api/api/indices.get_field_mapping.js new file mode 100644 index 000000000..3af4964ab --- /dev/null +++ b/api/api/indices.get_field_mapping.js @@ -0,0 +1,123 @@ +'use strict' + +function buildIndicesGetFieldMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_field_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html) request + * + * @param {list} index - A comma-separated list of index names + * @param {list} type - A comma-separated list of document types + * @param {list} fields - A comma-separated list of fields + * @param {boolean} include_defaults - Whether the default mapping values should be returned as well + * @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. + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesGetFieldMapping (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetFieldMapping(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['fields'] == null) { + return callback( + new ConfigurationError('Missing required parameter: fields'), + { 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 = [ + 'include_defaults', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'includeDefaults', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'local', + '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 = 'GET' + } + + // 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'], '_mapping', params['type'], 'field', params['fields']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetFieldMapping diff --git a/api/api/indices.get_mapping.js b/api/api/indices.get_mapping.js new file mode 100644 index 000000000..de130c8ab --- /dev/null +++ b/api/api/indices.get_mapping.js @@ -0,0 +1,116 @@ +'use strict' + +function buildIndicesGetMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html) request + * + * @param {list} index - A comma-separated list of index names + * @param {list} type - A comma-separated list of document types + * @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. + * @param {time} master_timeout - Specify timeout for connection to master + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesGetMapping (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetMapping(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'master_timeout', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'masterTimeout', + 'local', + '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 = 'GET' + } + + // 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'], '_mapping', params['type']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetMapping diff --git a/api/api/indices.get_settings.js b/api/api/indices.get_settings.js new file mode 100644 index 000000000..c53e859fd --- /dev/null +++ b/api/api/indices.get_settings.js @@ -0,0 +1,122 @@ +'use strict' + +function buildIndicesGetSettings (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.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 {list} name - The name of the settings that should be included + * @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. + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @param {boolean} include_defaults - Whether to return all default setting for each of the indices. + */ + return function indicesGetSettings (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetSettings(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'local', + 'include_defaults', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'flatSettings', + 'local', + 'includeDefaults', + '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 = 'GET' + } + + // 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'], '_settings', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetSettings diff --git a/api/api/indices.get_template.js b/api/api/indices.get_template.js new file mode 100644 index 000000000..55beaa599 --- /dev/null +++ b/api/api/indices.get_template.js @@ -0,0 +1,109 @@ +'use strict' + +function buildIndicesGetTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request + * + * @param {list} name - The comma separated names of the index templates + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function indicesGetTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetTemplate(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flat_settings', + 'master_timeout', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'masterTimeout', + 'local', + '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 = 'GET' + } + + // 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 = ['_template', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetTemplate diff --git a/api/api/indices.get_upgrade.js b/api/api/indices.get_upgrade.js new file mode 100644 index 000000000..8bffcf0e5 --- /dev/null +++ b/api/api/indices.get_upgrade.js @@ -0,0 +1,109 @@ +'use strict' + +function buildIndicesGetUpgrade (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.get_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} 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 indicesGetUpgrade (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesGetUpgrade(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'GET' + } + + // 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'], '_upgrade'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesGetUpgrade diff --git a/api/api/indices.open.js b/api/api/indices.open.js new file mode 100644 index 000000000..2cb459eee --- /dev/null +++ b/api/api/indices.open.js @@ -0,0 +1,124 @@ +'use strict' + +function buildIndicesOpen (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.open](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html) request + * + * @param {list} index - A comma separated list of indices to open + * @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. + * @param {string} wait_for_active_shards - Sets the number of active shards to wait for before the operation returns. + */ + return function indicesOpen (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesOpen(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', + 'wait_for_active_shards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'waitForActiveShards', + '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'], '_open'] + 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 = buildIndicesOpen diff --git a/api/api/indices.put_alias.js b/api/api/indices.put_alias.js new file mode 100644 index 000000000..fce99f4cb --- /dev/null +++ b/api/api/indices.put_alias.js @@ -0,0 +1,124 @@ +'use strict' + +function buildIndicesPutAlias (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.put_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request + * + * @param {list} index - A comma-separated list of index names the alias should point to (supports wildcards); use `_all` to perform the operation on all indices. + * @param {string} name - The name of the alias to be created or updated + * @param {time} timeout - Explicit timestamp for the document + * @param {time} master_timeout - Specify timeout for connection to master + * @param {object} body - The settings for the alias, such as `routing` or `filter` + */ + return function indicesPutAlias (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesPutAlias(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['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['name'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + '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 = 'PUT' + } + + // 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'], '_aliases', params['name']] + const request = { + method, + path: params['index'] != null && params['name'] != null + ? '/' + parts.filter(Boolean).join('/') + : '/{index}/_alias/{name}', + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesPutAlias diff --git a/api/api/indices.put_mapping.js b/api/api/indices.put_mapping.js new file mode 100644 index 000000000..bf403dc7a --- /dev/null +++ b/api/api/indices.put_mapping.js @@ -0,0 +1,126 @@ +'use strict' + +function buildIndicesPutMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.put_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html) request + * + * @param {list} index - A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices. + * @param {string} type - The name of the document type + * @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. + * @param {boolean} update_all_types - Whether to update the mapping for all fields with the same name across all types or not + * @param {object} body - The mapping definition + */ + return function indicesPutMapping (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesPutMapping(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: 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', + 'update_all_types', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'updateAllTypes', + '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 = 'PUT' + } + + // 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'], '_mappings', params['type']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesPutMapping diff --git a/api/api/indices.put_settings.js b/api/api/indices.put_settings.js new file mode 100644 index 000000000..c9eb3b0e4 --- /dev/null +++ b/api/api/indices.put_settings.js @@ -0,0 +1,122 @@ +'use strict' + +function buildIndicesPutSettings (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.put_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.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 {time} master_timeout - Specify timeout for connection to master + * @param {time} timeout - Explicit operation timeout + * @param {boolean} preserve_existing - Whether to update existing settings. If set to `true` existing settings on an index remain unchanged, the default is `false` + * @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. + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {object} body - The index settings to be updated + */ + return function indicesPutSettings (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesPutSettings(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'timeout', + 'preserve_existing', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + 'preserveExisting', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'flatSettings', + '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 = 'PUT' + } + + // 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'], '_settings'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesPutSettings diff --git a/api/api/indices.put_template.js b/api/api/indices.put_template.js new file mode 100644 index 000000000..c67845977 --- /dev/null +++ b/api/api/indices.put_template.js @@ -0,0 +1,122 @@ +'use strict' + +function buildIndicesPutTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.put_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request + * + * @param {string} name - The name of the template + * @param {number} order - The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers) + * @param {boolean} create - Whether the index template should only be added if new or can also replace an existing one + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {object} body - The template definition + */ + return function indicesPutTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesPutTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['name'] == null) { + return callback( + new ConfigurationError('Missing required parameter: name'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'order', + 'create', + 'timeout', + 'master_timeout', + 'flat_settings', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'order', + 'create', + 'timeout', + 'masterTimeout', + 'flatSettings', + '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 = 'PUT' + } + + // 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 = ['_template', params['name']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesPutTemplate diff --git a/api/api/indices.recovery.js b/api/api/indices.recovery.js new file mode 100644 index 000000000..4b28d9914 --- /dev/null +++ b/api/api/indices.recovery.js @@ -0,0 +1,106 @@ +'use strict' + +function buildIndicesRecovery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.recovery](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.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} detailed - Whether to display detailed information about shard recovery + * @param {boolean} active_only - Display only those recoveries that are currently on-going + */ + return function indicesRecovery (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesRecovery(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'detailed', + 'active_only', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'detailed', + 'activeOnly', + '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 = 'GET' + } + + // 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'], '_recovery'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesRecovery diff --git a/api/api/indices.refresh.js b/api/api/indices.refresh.js new file mode 100644 index 000000000..aeb999575 --- /dev/null +++ b/api/api/indices.refresh.js @@ -0,0 +1,109 @@ +'use strict' + +function buildIndicesRefresh (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.refresh](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.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} 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 indicesRefresh (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesRefresh(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = params.body == null ? 'GET' : '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'], '_refresh'] + 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 = buildIndicesRefresh diff --git a/api/api/indices.rollover.js b/api/api/indices.rollover.js new file mode 100644 index 000000000..47a9af22f --- /dev/null +++ b/api/api/indices.rollover.js @@ -0,0 +1,122 @@ +'use strict' + +function buildIndicesRollover (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.rollover](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html) request + * + * @param {string} alias - The name of the alias to rollover + * @param {string} new_index - The name of the rollover index + * @param {time} timeout - Explicit operation timeout + * @param {boolean} dry_run - If set to true the rollover action will only be validated but not actually performed even if a condition matches. The default is false + * @param {time} master_timeout - Specify timeout for connection to master + * @param {string} wait_for_active_shards - Set the number of active shards to wait for on the newly created rollover index before the operation returns. + * @param {object} body - The conditions that needs to be met for executing rollover + */ + return function indicesRollover (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesRollover(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['alias'] == null) { + return callback( + new ConfigurationError('Missing required parameter: alias'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if ((params['new_index'] != null || params['newIndex'] != null) && (params['alias'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: alias'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'dry_run', + 'master_timeout', + 'wait_for_active_shards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'dryRun', + 'masterTimeout', + 'waitForActiveShards', + '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['alias'], '_rollover', params['new_index'] || params['newIndex']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesRollover diff --git a/api/api/indices.segments.js b/api/api/indices.segments.js new file mode 100644 index 000000000..7d719c375 --- /dev/null +++ b/api/api/indices.segments.js @@ -0,0 +1,112 @@ +'use strict' + +function buildIndicesSegments (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.segments](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.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} 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. + * @param {boolean} verbose - Includes detailed memory usage by Lucene. + */ + return function indicesSegments (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesSegments(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'verbose', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'verbose', + '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 = 'GET' + } + + // 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'], '_segments'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesSegments diff --git a/api/api/indices.shard_stores.js b/api/api/indices.shard_stores.js new file mode 100644 index 000000000..4cc39dea4 --- /dev/null +++ b/api/api/indices.shard_stores.js @@ -0,0 +1,112 @@ +'use strict' + +function buildIndicesShardStores (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.shard_stores](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.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 {list} status - A comma-separated list of statuses used to filter on shards to get store information for + * @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 indicesShardStores (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesShardStores(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'status', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'status', + '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 = 'GET' + } + + // 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'], '_shard_stores'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesShardStores diff --git a/api/api/indices.shrink.js b/api/api/indices.shrink.js new file mode 100644 index 000000000..9981a1eec --- /dev/null +++ b/api/api/indices.shrink.js @@ -0,0 +1,128 @@ +'use strict' + +function buildIndicesShrink (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.shrink](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html) request + * + * @param {string} index - The name of the source index to shrink + * @param {string} target - The name of the target index to shrink into + * @param {boolean} copy_settings - whether or not to copy settings from the source index (defaults to false) + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {string} wait_for_active_shards - Set the number of active shards to wait for on the shrunken index before the operation returns. + * @param {object} body - The configuration for the target index (`settings` and `aliases`) + */ + return function indicesShrink (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesShrink(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['target'] == null) { + return callback( + new ConfigurationError('Missing required parameter: target'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['target'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'copy_settings', + 'timeout', + 'master_timeout', + 'wait_for_active_shards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'copySettings', + 'timeout', + 'masterTimeout', + 'waitForActiveShards', + '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 = 'PUT' + } + + // 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'], '_shrink', params['target']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesShrink diff --git a/api/api/indices.split.js b/api/api/indices.split.js new file mode 100644 index 000000000..a40db9b25 --- /dev/null +++ b/api/api/indices.split.js @@ -0,0 +1,128 @@ +'use strict' + +function buildIndicesSplit (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.split](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-split-index.html) request + * + * @param {string} index - The name of the source index to split + * @param {string} target - The name of the target index to split into + * @param {boolean} copy_settings - whether or not to copy settings from the source index (defaults to false) + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {string} wait_for_active_shards - Set the number of active shards to wait for on the shrunken index before the operation returns. + * @param {object} body - The configuration for the target index (`settings` and `aliases`) + */ + return function indicesSplit (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesSplit(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['target'] == null) { + return callback( + new ConfigurationError('Missing required parameter: target'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['target'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'copy_settings', + 'timeout', + 'master_timeout', + 'wait_for_active_shards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'copySettings', + 'timeout', + 'masterTimeout', + 'waitForActiveShards', + '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 = 'PUT' + } + + // 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'], '_split', params['target']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesSplit diff --git a/api/api/indices.stats.js b/api/api/indices.stats.js new file mode 100644 index 000000000..00f43b6ad --- /dev/null +++ b/api/api/indices.stats.js @@ -0,0 +1,122 @@ +'use strict' + +function buildIndicesStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.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 {list} metric - Limit the information returned the specific metrics. + * @param {list} completion_fields - A comma-separated list of fields for `fielddata` and `suggest` index metric (supports wildcards) + * @param {list} fielddata_fields - A comma-separated list of fields for `fielddata` index metric (supports wildcards) + * @param {list} fields - A comma-separated list of fields for `fielddata` and `completion` index metric (supports wildcards) + * @param {list} groups - A comma-separated list of search groups for `search` index metric + * @param {enum} level - Return stats aggregated at cluster, index or shard level + * @param {list} types - A comma-separated list of document types for the `indexing` index metric + * @param {boolean} include_segment_file_sizes - Whether to report the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested) + */ + return function indicesStats (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesStats(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'completion_fields', + 'fielddata_fields', + 'fields', + 'groups', + 'level', + 'types', + 'include_segment_file_sizes', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'completionFields', + 'fielddataFields', + 'fields', + 'groups', + 'level', + 'types', + 'includeSegmentFileSizes', + '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 = 'GET' + } + + // 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'], '_stats', params['metric']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesStats diff --git a/api/api/indices.update_aliases.js b/api/api/indices.update_aliases.js new file mode 100644 index 000000000..7ec44ccdb --- /dev/null +++ b/api/api/indices.update_aliases.js @@ -0,0 +1,106 @@ +'use strict' + +function buildIndicesUpdateAliases (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.update_aliases](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request + * + * @param {time} timeout - Request timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {object} body - The definition of `actions` to perform + */ + return function indicesUpdateAliases (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesUpdateAliases(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + '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 = ['_aliases'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesUpdateAliases diff --git a/api/api/indices.upgrade.js b/api/api/indices.upgrade.js new file mode 100644 index 000000000..1259ee440 --- /dev/null +++ b/api/api/indices.upgrade.js @@ -0,0 +1,115 @@ +'use strict' + +function buildIndicesUpgrade (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = 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'), + { body: null, headers: null, statusCode: null } + ) + } + + // 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}`), + { body: null, headers: null, statusCode: null } + ) + } + + 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 diff --git a/api/api/indices.validate_query.js b/api/api/indices.validate_query.js new file mode 100644 index 000000000..ca27a5990 --- /dev/null +++ b/api/api/indices.validate_query.js @@ -0,0 +1,138 @@ +'use strict' + +function buildIndicesValidateQuery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [indices.validate_query](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html) request + * + * @param {list} index - A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types + * @param {boolean} explain - Return detailed information about the error + * @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. + * @param {string} q - Query in the Lucene query string syntax + * @param {string} analyzer - The analyzer to use for the query string + * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The field to use as default where no field prefix is given in the query string + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {boolean} rewrite - Provide a more detailed explanation showing the actual Lucene query that will be executed. + * @param {boolean} all_shards - Execute validation on all shards instead of one random shard per index + * @param {object} body - The query definition specified with the Query DSL + */ + return function indicesValidateQuery (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + indicesValidateQuery(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'explain', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'q', + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'lenient', + 'rewrite', + 'all_shards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'explain', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'q', + 'analyzer', + 'analyzeWildcard', + 'defaultOperator', + 'df', + 'lenient', + 'rewrite', + 'allShards', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_validate', 'query'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIndicesValidateQuery diff --git a/api/api/info.js b/api/api/info.js new file mode 100644 index 000000000..59cb80341 --- /dev/null +++ b/api/api/info.js @@ -0,0 +1,99 @@ +'use strict' + +function buildInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [info](http://www.elastic.co/guide/) request + * + */ + return function info (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + info(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'GET' + } + + // 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 = [] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildInfo diff --git a/api/api/ingest.delete_pipeline.js b/api/api/ingest.delete_pipeline.js new file mode 100644 index 000000000..ace43057e --- /dev/null +++ b/api/api/ingest.delete_pipeline.js @@ -0,0 +1,112 @@ +'use strict' + +function buildIngestDeletePipeline (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ingest.delete_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request + * + * @param {string} id - Pipeline ID + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + */ + return function ingestDeletePipeline (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ingestDeletePipeline(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { 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 = [ + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + '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 = 'DELETE' + } + + // 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 = ['_ingest', 'pipeline', params['id']] + 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 = buildIngestDeletePipeline diff --git a/api/api/ingest.get_pipeline.js b/api/api/ingest.get_pipeline.js new file mode 100644 index 000000000..176a24abe --- /dev/null +++ b/api/api/ingest.get_pipeline.js @@ -0,0 +1,103 @@ +'use strict' + +function buildIngestGetPipeline (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ingest.get_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request + * + * @param {string} id - Comma separated list of pipeline ids. Wildcards supported + * @param {time} master_timeout - Explicit operation timeout for connection to master node + */ + return function ingestGetPipeline (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ingestGetPipeline(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + '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 = 'GET' + } + + // 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 = ['_ingest', 'pipeline', params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIngestGetPipeline diff --git a/api/api/ingest.processor_grok.js b/api/api/ingest.processor_grok.js new file mode 100644 index 000000000..a8b93a6cd --- /dev/null +++ b/api/api/ingest.processor_grok.js @@ -0,0 +1,99 @@ +'use strict' + +function buildIngestProcessorGrok (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ingest.processor_grok](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request + * + */ + return function ingestProcessorGrok (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ingestProcessorGrok(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'GET' + } + + // 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 = ['_ingest', 'processor', 'grok'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIngestProcessorGrok diff --git a/api/api/ingest.put_pipeline.js b/api/api/ingest.put_pipeline.js new file mode 100644 index 000000000..02e6841c3 --- /dev/null +++ b/api/api/ingest.put_pipeline.js @@ -0,0 +1,113 @@ +'use strict' + +function buildIngestPutPipeline (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ingest.put_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request + * + * @param {string} id - Pipeline ID + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {object} body - The ingest definition + */ + return function ingestPutPipeline (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ingestPutPipeline(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + '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 = 'PUT' + } + + // 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 = ['_ingest', 'pipeline', params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIngestPutPipeline diff --git a/api/api/ingest.simulate.js b/api/api/ingest.simulate.js new file mode 100644 index 000000000..14ff6c3c9 --- /dev/null +++ b/api/api/ingest.simulate.js @@ -0,0 +1,104 @@ +'use strict' + +function buildIngestSimulate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ingest.simulate](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request + * + * @param {string} id - Pipeline ID + * @param {boolean} verbose - Verbose mode. Display data output for each processor in executed pipeline + * @param {object} body - The simulate definition + */ + return function ingestSimulate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ingestSimulate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'verbose', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'verbose', + '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 = params.body == null ? 'GET' : '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 = ['_ingest', 'pipeline', params['id'], '_simulate'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildIngestSimulate diff --git a/api/api/mget.js b/api/api/mget.js new file mode 100644 index 000000000..54890e994 --- /dev/null +++ b/api/api/mget.js @@ -0,0 +1,134 @@ +'use strict' + +function buildMget (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [mget](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html) request + * + * @param {string} index - The name of the index + * @param {string} type - The type of the document + * @param {list} stored_fields - A comma-separated list of stored fields to return in the response + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {boolean} realtime - Specify whether to perform the operation in realtime or search mode + * @param {boolean} refresh - Refresh the shard containing the document before performing the operation + * @param {string} routing - Specific routing value + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {object} body - Document identifiers; can be either `docs` (containing full document information) or `ids` (when index and type is provided in the URL. + */ + return function mget (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + mget(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'stored_fields', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_exclude', + '_source_include', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'storedFields', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_sourceExclude', + '_sourceInclude', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_mget'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildMget diff --git a/api/api/msearch.js b/api/api/msearch.js new file mode 100644 index 000000000..1319b246a --- /dev/null +++ b/api/api/msearch.js @@ -0,0 +1,122 @@ +'use strict' + +function buildMsearch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [msearch](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html) request + * + * @param {list} index - A comma-separated list of index names to use as default + * @param {list} type - A comma-separated list of document types to use as default + * @param {enum} search_type - Search operation type + * @param {number} max_concurrent_searches - Controls the maximum number of concurrent searches the multi search api will execute + * @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * @param {number} pre_filter_shard_size - A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. + * @param {object} body - The request definitions (metadata-search request definition pairs), separated by newlines + */ + return function msearch (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + msearch(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'search_type', + 'max_concurrent_searches', + 'typed_keys', + 'pre_filter_shard_size', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'searchType', + 'maxConcurrentSearches', + 'typedKeys', + 'preFilterShardSize', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_msearch'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + bulkBody: params.body, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildMsearch diff --git a/api/api/msearch_template.js b/api/api/msearch_template.js new file mode 100644 index 000000000..62f0a6754 --- /dev/null +++ b/api/api/msearch_template.js @@ -0,0 +1,119 @@ +'use strict' + +function buildMsearchTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [msearch_template](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) request + * + * @param {list} index - A comma-separated list of index names to use as default + * @param {list} type - A comma-separated list of document types to use as default + * @param {enum} search_type - Search operation type + * @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * @param {number} max_concurrent_searches - Controls the maximum number of concurrent searches the multi search api will execute + * @param {object} body - The request definitions (metadata-search request definition pairs), separated by newlines + */ + return function msearchTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + msearchTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'search_type', + 'typed_keys', + 'max_concurrent_searches', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'searchType', + 'typedKeys', + 'maxConcurrentSearches', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_msearch', 'template'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + bulkBody: params.body, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildMsearchTemplate diff --git a/api/api/mtermvectors.js b/api/api/mtermvectors.js new file mode 100644 index 000000000..1cceaa317 --- /dev/null +++ b/api/api/mtermvectors.js @@ -0,0 +1,141 @@ +'use strict' + +function buildMtermvectors (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [mtermvectors](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html) request + * + * @param {string} index - The index in which the document resides. + * @param {string} type - The type of the document. + * @param {list} ids - A comma-separated list of documents ids. You must define ids as parameter or set "ids" or "docs" in the request body + * @param {boolean} term_statistics - Specifies if total term frequency and document frequency should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {boolean} field_statistics - Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {list} fields - A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {boolean} offsets - Specifies if term offsets should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {boolean} positions - Specifies if term positions should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {boolean} payloads - Specifies if term payloads should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) .Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {string} routing - Specific routing value. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {string} parent - Parent id of documents. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * @param {boolean} realtime - Specifies if requests are real-time as opposed to near-real-time (default: true). + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + * @param {object} body - Define ids, documents, parameters or a list of parameters per document here. You must at least provide a list of document ids. See documentation. + */ + return function mtermvectors (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + mtermvectors(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ids', + 'term_statistics', + 'field_statistics', + 'fields', + 'offsets', + 'positions', + 'payloads', + 'preference', + 'routing', + 'parent', + 'realtime', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ids', + 'termStatistics', + 'fieldStatistics', + 'fields', + 'offsets', + 'positions', + 'payloads', + 'preference', + 'routing', + 'parent', + 'realtime', + 'version', + 'versionType', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_mtermvectors'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildMtermvectors diff --git a/api/api/nodes.hot_threads.js b/api/api/nodes.hot_threads.js new file mode 100644 index 000000000..6dcf89610 --- /dev/null +++ b/api/api/nodes.hot_threads.js @@ -0,0 +1,120 @@ +'use strict' + +function buildNodesHotThreads (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [nodes.hot_threads](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html) request + * + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {time} interval - The interval for the second sampling of threads + * @param {number} snapshots - Number of samples of thread stacktrace (default: 10) + * @param {number} threads - Specify the number of threads to provide information for (default: 3) + * @param {boolean} ignore_idle_threads - Don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true) + * @param {enum} type - The type to sample (default: cpu) + * @param {time} timeout - Explicit operation timeout + */ + return function nodesHotThreads (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + nodesHotThreads(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'interval', + 'snapshots', + 'threads', + 'ignore_idle_threads', + 'type', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'interval', + 'snapshots', + 'threads', + 'ignoreIdleThreads', + 'type', + 'timeout', + '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 = 'GET' + } + + // 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 = ['_cluster', 'nodes', params['node_id'] || params['nodeId'], 'hot_threads'] + const request = { + method, + path: (params['node_id'] || params['nodeId']) != null + ? '/' + parts.filter(Boolean).join('/') + : '/_nodes/hot_threads', + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildNodesHotThreads diff --git a/api/api/nodes.info.js b/api/api/nodes.info.js new file mode 100644 index 000000000..c48200a32 --- /dev/null +++ b/api/api/nodes.info.js @@ -0,0 +1,107 @@ +'use strict' + +function buildNodesInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [nodes.info](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html) request + * + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {list} metric - A comma-separated list of metrics you wish returned. Leave empty to return all. + * @param {boolean} flat_settings - Return settings in flat format (default: false) + * @param {time} timeout - Explicit operation timeout + */ + return function nodesInfo (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + nodesInfo(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'flat_settings', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'flatSettings', + 'timeout', + '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 = 'GET' + } + + // 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 = ['_nodes', params['node_id'] || params['nodeId'], params['metric']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildNodesInfo diff --git a/api/api/nodes.stats.js b/api/api/nodes.stats.js new file mode 100644 index 000000000..176556a83 --- /dev/null +++ b/api/api/nodes.stats.js @@ -0,0 +1,126 @@ +'use strict' + +function buildNodesStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [nodes.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html) request + * + * @param {list} metric - Limit the information returned to the specified metrics + * @param {list} index_metric - Limit the information returned for `indices` metric to the specific index metrics. Isn't used if `indices` (or `all`) metric isn't specified. + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {list} completion_fields - A comma-separated list of fields for `fielddata` and `suggest` index metric (supports wildcards) + * @param {list} fielddata_fields - A comma-separated list of fields for `fielddata` index metric (supports wildcards) + * @param {list} fields - A comma-separated list of fields for `fielddata` and `completion` index metric (supports wildcards) + * @param {boolean} groups - A comma-separated list of search groups for `search` index metric + * @param {enum} level - Return indices stats aggregated at index, node or shard level + * @param {list} types - A comma-separated list of document types for the `indexing` index metric + * @param {time} timeout - Explicit operation timeout + * @param {boolean} include_segment_file_sizes - Whether to report the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested) + */ + return function nodesStats (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + nodesStats(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'completion_fields', + 'fielddata_fields', + 'fields', + 'groups', + 'level', + 'types', + 'timeout', + 'include_segment_file_sizes', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'completionFields', + 'fielddataFields', + 'fields', + 'groups', + 'level', + 'types', + 'timeout', + 'includeSegmentFileSizes', + '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 = 'GET' + } + + // 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 = ['_nodes', params['node_id'] || params['nodeId'], 'stats', params['metric'], params['index_metric'] || params['indexMetric']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildNodesStats diff --git a/api/api/nodes.usage.js b/api/api/nodes.usage.js new file mode 100644 index 000000000..11a4055ee --- /dev/null +++ b/api/api/nodes.usage.js @@ -0,0 +1,104 @@ +'use strict' + +function buildNodesUsage (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [nodes.usage](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html) request + * + * @param {list} metric - Limit the information returned to the specified metrics + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {time} timeout - Explicit operation timeout + */ + return function nodesUsage (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + nodesUsage(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + '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 = 'GET' + } + + // 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 = ['_nodes', params['node_id'] || params['nodeId'], 'usage', params['metric']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildNodesUsage diff --git a/api/api/ping.js b/api/api/ping.js new file mode 100644 index 000000000..8dc4f43ad --- /dev/null +++ b/api/api/ping.js @@ -0,0 +1,99 @@ +'use strict' + +function buildPing (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [ping](http://www.elastic.co/guide/) request + * + */ + return function ping (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + ping(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = 'HEAD' + } + + // 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 = [] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildPing diff --git a/api/api/put_script.js b/api/api/put_script.js new file mode 100644 index 000000000..ce07d3210 --- /dev/null +++ b/api/api/put_script.js @@ -0,0 +1,125 @@ +'use strict' + +function buildPutScript (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [put_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request + * + * @param {string} id - Script ID + * @param {string} context - Script context + * @param {time} timeout - Explicit operation timeout + * @param {time} master_timeout - Specify timeout for connection to master + * @param {string} context - Context name to compile script against + * @param {object} body - The document + */ + return function putScript (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + putScript(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['context'] != null && (params['id'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: id'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'timeout', + 'master_timeout', + 'context', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'timeout', + 'masterTimeout', + 'context', + '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 = 'PUT' + } + + // 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 = ['_scripts', params['id'], params['context']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildPutScript diff --git a/api/api/rank_eval.js b/api/api/rank_eval.js new file mode 100644 index 000000000..8b22dad2b --- /dev/null +++ b/api/api/rank_eval.js @@ -0,0 +1,110 @@ +'use strict' + +function buildRankEval (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [rank_eval](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @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. + * @param {object} body - The ranking evaluation search definition, including search requests, document ratings and ranking metric definition. + */ + return function rankEval (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + rankEval(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = params.body == null ? 'GET' : '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'], '_rank_eval'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildRankEval diff --git a/api/api/reindex.js b/api/api/reindex.js new file mode 100644 index 000000000..6764bb563 --- /dev/null +++ b/api/api/reindex.js @@ -0,0 +1,118 @@ +'use strict' + +function buildReindex (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html) request + * + * @param {boolean} refresh - Should the effected indexes be refreshed? + * @param {time} timeout - Time each individual bulk request should wait for shards that are unavailable. + * @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before proceeding with the reindex 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 {boolean} wait_for_completion - Should the request should block until the reindex is complete. + * @param {number} requests_per_second - The throttle to set on this request in sub-requests per second. -1 means no throttle. + * @param {number} slices - The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. + * @param {object} body - The search definition using the Query DSL and the prototype for the index request. + */ + return function reindex (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + reindex(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'refresh', + 'timeout', + 'wait_for_active_shards', + 'wait_for_completion', + 'requests_per_second', + 'slices', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'refresh', + 'timeout', + 'waitForActiveShards', + 'waitForCompletion', + 'requestsPerSecond', + 'slices', + '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 = ['_reindex'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildReindex diff --git a/api/api/reindex_rethrottle.js b/api/api/reindex_rethrottle.js new file mode 100644 index 000000000..caa50c151 --- /dev/null +++ b/api/api/reindex_rethrottle.js @@ -0,0 +1,117 @@ +'use strict' + +function buildReindexRethrottle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [reindex_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html) request + * + * @param {string} task_id - The task id to rethrottle + * @param {number} requests_per_second - The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + */ + return function reindexRethrottle (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + reindexRethrottle(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['task_id'] == null && params['taskId'] == null) { + return callback( + new ConfigurationError('Missing required parameter: task_id or taskId'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { + return callback( + new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond'), + { 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 = [ + 'requests_per_second', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'requestsPerSecond', + '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 = ['_delete_by_query', params['task_id'] || params['taskId'], '_rethrottle'] + const request = { + method, + path: (params['task_id'] || params['taskId']) != null + ? '/' + parts.filter(Boolean).join('/') + : '/_reindex/{task_id}/_rethrottle', + querystring, + body: '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildReindexRethrottle diff --git a/api/api/render_search_template.js b/api/api/render_search_template.js new file mode 100644 index 000000000..94b6a3c5a --- /dev/null +++ b/api/api/render_search_template.js @@ -0,0 +1,93 @@ +'use strict' + +function buildRenderSearchTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [render_search_template](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html) request + * + * @param {string} id - The id of the stored search template + * @param {object} body - The search definition template and its params + */ + return function renderSearchTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + renderSearchTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = params.body == null ? 'GET' : '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 = ['_render', 'template', params['id']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildRenderSearchTemplate diff --git a/api/api/scripts_painless_execute.js b/api/api/scripts_painless_execute.js new file mode 100644 index 000000000..7a08082c2 --- /dev/null +++ b/api/api/scripts_painless_execute.js @@ -0,0 +1,92 @@ +'use strict' + +function buildScriptsPainlessExecute (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [scripts_painless_execute](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html) request + * + * @param {object} body - The script to execute + */ + return function scriptsPainlessExecute (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + scriptsPainlessExecute(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + '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 = params.body == null ? 'GET' : '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 = ['_scripts', 'painless', '_execute'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildScriptsPainlessExecute diff --git a/api/api/scroll.js b/api/api/scroll.js new file mode 100644 index 000000000..f5f5bf575 --- /dev/null +++ b/api/api/scroll.js @@ -0,0 +1,99 @@ +'use strict' + +function buildScroll (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [scroll](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html) request + * + * @param {string} scroll_id - The scroll ID + * @param {time} scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {string} scroll_id - The scroll ID for scrolled search + * @param {object} body - The scroll ID if not passed by URL or query parameter. + */ + return function scroll (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + scroll(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'scroll', + 'scroll_id', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'scroll', + 'scrollId', + '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 = params.body == null ? 'GET' : '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 = ['_search', 'scroll', params['scroll_id'] || params['scrollId']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildScroll diff --git a/api/api/search.js b/api/api/search.js new file mode 100644 index 000000000..1a29f8427 --- /dev/null +++ b/api/api/search.js @@ -0,0 +1,216 @@ +'use strict' + +function buildSearch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [search](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to search; leave empty to perform the operation on all types + * @param {string} analyzer - The analyzer to use for the query string + * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The field to use as default where no field prefix is given in the query string + * @param {boolean} explain - Specify whether to return detailed information about score computation as part of a hit + * @param {list} stored_fields - A comma-separated list of stored fields to return as part of a hit + * @param {list} docvalue_fields - A comma-separated list of fields to return as the docvalue representation of a field for each hit + * @param {number} from - Starting offset (default: 0) + * @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. + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {string} q - Query in the Lucene query string syntax + * @param {list} routing - A comma-separated list of specific routing values + * @param {time} scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {enum} search_type - Search operation type + * @param {number} size - Number of hits to return (default: 10) + * @param {list} sort - A comma-separated list of : pairs + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} terminate_after - The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * @param {list} stats - Specific 'tag' of the request for logging and statistical purposes + * @param {string} suggest_field - Specify which field to use for suggestions + * @param {enum} suggest_mode - Specify suggest mode + * @param {number} suggest_size - How many suggestions to return in response + * @param {string} suggest_text - The source text for which the suggestions should be returned + * @param {time} timeout - Explicit operation timeout + * @param {boolean} track_scores - Whether to calculate and return scores even if they are not used for sorting + * @param {boolean} track_total_hits - Indicate if the number of documents that match the query should be tracked + * @param {boolean} allow_partial_search_results - Indicate if an error should be returned if there is a partial search failure or timeout + * @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * @param {boolean} version - Specify whether to return document version as part of a hit + * @param {boolean} request_cache - Specify if request cache should be used for this request or not, defaults to index level setting + * @param {number} batched_reduce_size - The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. + * @param {number} max_concurrent_shard_requests - The number of concurrent shard requests this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests + * @param {number} pre_filter_shard_size - A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. + * @param {object} body - The search definition using the Query DSL + */ + return function search (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + search(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'explain', + 'stored_fields', + 'docvalue_fields', + 'from', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'lenient', + 'preference', + 'q', + 'routing', + 'scroll', + 'search_type', + 'size', + 'sort', + '_source', + '_source_exclude', + '_source_include', + 'terminate_after', + 'stats', + 'suggest_field', + 'suggest_mode', + 'suggest_size', + 'suggest_text', + 'timeout', + 'track_scores', + 'track_total_hits', + 'allow_partial_search_results', + 'typed_keys', + 'version', + 'request_cache', + 'batched_reduce_size', + 'max_concurrent_shard_requests', + 'pre_filter_shard_size', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'analyzer', + 'analyzeWildcard', + 'defaultOperator', + 'df', + 'explain', + 'storedFields', + 'docvalueFields', + 'from', + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'lenient', + 'preference', + 'q', + 'routing', + 'scroll', + 'searchType', + 'size', + 'sort', + '_source', + '_sourceExclude', + '_sourceInclude', + 'terminateAfter', + 'stats', + 'suggestField', + 'suggestMode', + 'suggestSize', + 'suggestText', + 'timeout', + 'trackScores', + 'trackTotalHits', + 'allowPartialSearchResults', + 'typedKeys', + 'version', + 'requestCache', + 'batchedReduceSize', + 'maxConcurrentShardRequests', + 'preFilterShardSize', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_search'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSearch diff --git a/api/api/search_shards.js b/api/api/search_shards.js new file mode 100644 index 000000000..62a2fa783 --- /dev/null +++ b/api/api/search_shards.js @@ -0,0 +1,118 @@ +'use strict' + +function buildSearchShards (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [search_shards](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {string} routing - Specific routing value + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + * @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 searchShards (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + searchShards(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'preference', + 'routing', + 'local', + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'preference', + 'routing', + 'local', + '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 = params.body == null ? 'GET' : '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'], '_search_shards'] + 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 = buildSearchShards diff --git a/api/api/search_template.js b/api/api/search_template.js new file mode 100644 index 000000000..7d42e6b62 --- /dev/null +++ b/api/api/search_template.js @@ -0,0 +1,140 @@ +'use strict' + +function buildSearchTemplate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [search_template](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to search; leave empty to perform the operation on all types + * @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. + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {list} routing - A comma-separated list of specific routing values + * @param {time} scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {enum} search_type - Search operation type + * @param {boolean} explain - Specify whether to return detailed information about score computation as part of a hit + * @param {boolean} profile - Specify whether to profile the query execution + * @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * @param {object} body - The search definition template and its params + */ + return function searchTemplate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + searchTemplate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'ignore_unavailable', + 'allow_no_indices', + 'expand_wildcards', + 'preference', + 'routing', + 'scroll', + 'search_type', + 'explain', + 'profile', + 'typed_keys', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'ignoreUnavailable', + 'allowNoIndices', + 'expandWildcards', + 'preference', + 'routing', + 'scroll', + 'searchType', + 'explain', + 'profile', + 'typedKeys', + '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 = params.body == null ? 'GET' : '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'], params['type'], '_search', 'template'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSearchTemplate diff --git a/api/api/snapshot.create.js b/api/api/snapshot.create.js new file mode 100644 index 000000000..18dc40192 --- /dev/null +++ b/api/api/snapshot.create.js @@ -0,0 +1,122 @@ +'use strict' + +function buildSnapshotCreate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.create](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {string} snapshot - A snapshot name + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} wait_for_completion - Should this request wait until the operation has completed before returning + * @param {object} body - The snapshot definition + */ + return function snapshotCreate (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotCreate(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['snapshot'] == null) { + return callback( + new ConfigurationError('Missing required parameter: snapshot'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['snapshot'] != null && (params['repository'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: repository'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'wait_for_completion', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'waitForCompletion', + '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 = 'PUT' + } + + // 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 = ['_snapshot', params['repository'], params['snapshot']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotCreate diff --git a/api/api/snapshot.create_repository.js b/api/api/snapshot.create_repository.js new file mode 100644 index 000000000..7458bea79 --- /dev/null +++ b/api/api/snapshot.create_repository.js @@ -0,0 +1,116 @@ +'use strict' + +function buildSnapshotCreateRepository (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.create_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + * @param {boolean} verify - Whether to verify the repository after creation + * @param {object} body - The repository definition + */ + return function snapshotCreateRepository (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotCreateRepository(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'timeout', + 'verify', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + 'verify', + '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 = 'PUT' + } + + // 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 = ['_snapshot', params['repository']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotCreateRepository diff --git a/api/api/snapshot.delete.js b/api/api/snapshot.delete.js new file mode 100644 index 000000000..949f4d2e6 --- /dev/null +++ b/api/api/snapshot.delete.js @@ -0,0 +1,124 @@ +'use strict' + +function buildSnapshotDelete (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {string} snapshot - A snapshot name + * @param {time} master_timeout - Explicit operation timeout for connection to master node + */ + return function snapshotDelete (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotDelete(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['snapshot'] == null) { + return callback( + new ConfigurationError('Missing required parameter: snapshot'), + { 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 } + ) + } + + // check required url components + if (params['snapshot'] != null && (params['repository'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: repository'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + '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 = 'DELETE' + } + + // 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 = ['_snapshot', params['repository'], params['snapshot']] + 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 = buildSnapshotDelete diff --git a/api/api/snapshot.delete_repository.js b/api/api/snapshot.delete_repository.js new file mode 100644 index 000000000..d42bc2113 --- /dev/null +++ b/api/api/snapshot.delete_repository.js @@ -0,0 +1,112 @@ +'use strict' + +function buildSnapshotDeleteRepository (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.delete_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {list} repository - A comma-separated list of repository names + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + */ + return function snapshotDeleteRepository (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotDeleteRepository(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { 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 = [ + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + '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 = 'DELETE' + } + + // 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 = ['_snapshot', params['repository']] + 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 = buildSnapshotDeleteRepository diff --git a/api/api/snapshot.get.js b/api/api/snapshot.get.js new file mode 100644 index 000000000..91b54005f --- /dev/null +++ b/api/api/snapshot.get.js @@ -0,0 +1,130 @@ +'use strict' + +function buildSnapshotGet (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {list} snapshot - A comma-separated list of snapshot names + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} ignore_unavailable - Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown + * @param {boolean} verbose - Whether to show verbose snapshot info or only show the basic info found in the repository index blob + */ + return function snapshotGet (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotGet(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['snapshot'] == null) { + return callback( + new ConfigurationError('Missing required parameter: snapshot'), + { 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 } + ) + } + + // check required url components + if (params['snapshot'] != null && (params['repository'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: repository'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'ignore_unavailable', + 'verbose', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'ignoreUnavailable', + 'verbose', + '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 = 'GET' + } + + // 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 = ['_snapshot', params['repository'], params['snapshot']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotGet diff --git a/api/api/snapshot.get_repository.js b/api/api/snapshot.get_repository.js new file mode 100644 index 000000000..0c91cf26d --- /dev/null +++ b/api/api/snapshot.get_repository.js @@ -0,0 +1,106 @@ +'use strict' + +function buildSnapshotGetRepository (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.get_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {list} repository - A comma-separated list of repository names + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + return function snapshotGetRepository (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotGetRepository(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'local', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'local', + '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 = 'GET' + } + + // 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 = ['_snapshot', params['repository']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotGetRepository diff --git a/api/api/snapshot.restore.js b/api/api/snapshot.restore.js new file mode 100644 index 000000000..d5f2e445d --- /dev/null +++ b/api/api/snapshot.restore.js @@ -0,0 +1,122 @@ +'use strict' + +function buildSnapshotRestore (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.restore](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {string} snapshot - A snapshot name + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} wait_for_completion - Should this request wait until the operation has completed before returning + * @param {object} body - Details of what to restore + */ + return function snapshotRestore (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotRestore(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['snapshot'] == null) { + return callback( + new ConfigurationError('Missing required parameter: snapshot'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['snapshot'] != null && (params['repository'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: repository'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'wait_for_completion', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'waitForCompletion', + '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 = ['_snapshot', params['repository'], params['snapshot'], '_restore'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotRestore diff --git a/api/api/snapshot.status.js b/api/api/snapshot.status.js new file mode 100644 index 000000000..50959dd95 --- /dev/null +++ b/api/api/snapshot.status.js @@ -0,0 +1,115 @@ +'use strict' + +function buildSnapshotStatus (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.status](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {list} snapshot - A comma-separated list of snapshot names + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {boolean} ignore_unavailable - Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown + */ + return function snapshotStatus (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotStatus(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['snapshot'] != null && (params['repository'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: repository'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'master_timeout', + 'ignore_unavailable', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'ignoreUnavailable', + '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 = 'GET' + } + + // 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 = ['_snapshot', params['repository'], params['snapshot'], '_status'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildSnapshotStatus diff --git a/api/api/snapshot.verify_repository.js b/api/api/snapshot.verify_repository.js new file mode 100644 index 000000000..ff605606c --- /dev/null +++ b/api/api/snapshot.verify_repository.js @@ -0,0 +1,112 @@ +'use strict' + +function buildSnapshotVerifyRepository (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [snapshot.verify_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request + * + * @param {string} repository - A repository name + * @param {time} master_timeout - Explicit operation timeout for connection to master node + * @param {time} timeout - Explicit operation timeout + */ + return function snapshotVerifyRepository (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + snapshotVerifyRepository(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['repository'] == null) { + return callback( + new ConfigurationError('Missing required parameter: repository'), + { 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 = [ + 'master_timeout', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'masterTimeout', + 'timeout', + '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 = ['_snapshot', params['repository'], '_verify'] + 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 = buildSnapshotVerifyRepository diff --git a/api/api/tasks.cancel.js b/api/api/tasks.cancel.js new file mode 100644 index 000000000..5b53505e0 --- /dev/null +++ b/api/api/tasks.cancel.js @@ -0,0 +1,109 @@ +'use strict' + +function buildTasksCancel (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [tasks.cancel](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request + * + * @param {string} task_id - Cancel the task with specified task id (node_id:task_number) + * @param {list} nodes - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {list} actions - A comma-separated list of actions that should be cancelled. Leave empty to cancel all. + * @param {string} parent_task_id - Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all. + */ + return function tasksCancel (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + tasksCancel(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'nodes', + 'actions', + 'parent_task_id', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'nodes', + 'actions', + 'parentTaskId', + '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 = ['_tasks', params['task_id'] || params['taskId'], '_cancel'] + 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 = buildTasksCancel diff --git a/api/api/tasks.get.js b/api/api/tasks.get.js new file mode 100644 index 000000000..f3d574b0e --- /dev/null +++ b/api/api/tasks.get.js @@ -0,0 +1,112 @@ +'use strict' + +function buildTasksGet (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [tasks.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request + * + * @param {string} task_id - Return the task with specified id (node_id:task_number) + * @param {boolean} wait_for_completion - Wait for the matching tasks to complete (default: false) + * @param {time} timeout - Explicit operation timeout + */ + return function tasksGet (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + tasksGet(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['task_id'] == null && params['taskId'] == null) { + return callback( + new ConfigurationError('Missing required parameter: task_id or taskId'), + { 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 = [ + 'wait_for_completion', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForCompletion', + 'timeout', + '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 = 'GET' + } + + // 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 = ['_tasks', params['task_id'] || params['taskId']] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildTasksGet diff --git a/api/api/tasks.list.js b/api/api/tasks.list.js new file mode 100644 index 000000000..a9d70eb49 --- /dev/null +++ b/api/api/tasks.list.js @@ -0,0 +1,120 @@ +'use strict' + +function buildTasksList (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [tasks.list](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request + * + * @param {list} nodes - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {list} actions - A comma-separated list of actions that should be returned. Leave empty to return all. + * @param {boolean} detailed - Return detailed task information (default: false) + * @param {string} parent_task_id - Return tasks with specified parent task id (node_id:task_number). Set to -1 to return all. + * @param {boolean} wait_for_completion - Wait for the matching tasks to complete (default: false) + * @param {enum} group_by - Group tasks by nodes or parent/child relationships + * @param {time} timeout - Explicit operation timeout + */ + return function tasksList (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + tasksList(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'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'nodes', + 'actions', + 'detailed', + 'parent_task_id', + 'wait_for_completion', + 'group_by', + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'nodes', + 'actions', + 'detailed', + 'parentTaskId', + 'waitForCompletion', + 'groupBy', + 'timeout', + '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 = 'GET' + } + + // 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 = ['_tasks'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: null, + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildTasksList diff --git a/api/api/termvectors.js b/api/api/termvectors.js new file mode 100644 index 000000000..6caf19bf2 --- /dev/null +++ b/api/api/termvectors.js @@ -0,0 +1,158 @@ +'use strict' + +function buildTermvectors (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [termvectors](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html) request + * + * @param {string} index - The index in which the document resides. + * @param {string} type - The type of the document. + * @param {string} id - The id of the document, when not specified a doc param should be supplied. + * @param {boolean} term_statistics - Specifies if total term frequency and document frequency should be returned. + * @param {boolean} field_statistics - Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. + * @param {list} fields - A comma-separated list of fields to return. + * @param {boolean} offsets - Specifies if term offsets should be returned. + * @param {boolean} positions - Specifies if term positions should be returned. + * @param {boolean} payloads - Specifies if term payloads should be returned. + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random). + * @param {string} routing - Specific routing value. + * @param {string} parent - Parent id of documents. + * @param {boolean} realtime - Specifies if request is real-time as opposed to near-real-time (default: true). + * @param {number} version - Explicit version number for concurrency control + * @param {enum} version_type - Specific version type + * @param {object} body - Define parameters and or supply a document to get termvectors for. See documentation. + */ + return function termvectors (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + termvectors(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['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'term_statistics', + 'field_statistics', + 'fields', + 'offsets', + 'positions', + 'payloads', + 'preference', + 'routing', + 'parent', + 'realtime', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'termStatistics', + 'fieldStatistics', + 'fields', + 'offsets', + 'positions', + 'payloads', + 'preference', + 'routing', + 'parent', + 'realtime', + 'version', + 'versionType', + '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 = params.body == null ? 'GET' : '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'], params['type'], params['id'], '_termvectors'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildTermvectors diff --git a/api/api/update.js b/api/api/update.js new file mode 100644 index 000000000..0c65b4ada --- /dev/null +++ b/api/api/update.js @@ -0,0 +1,173 @@ +'use strict' + +function buildUpdate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [update](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html) request + * + * @param {string} id - 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 update 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 {list} fields - A comma-separated list of fields to return in the response + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {string} lang - The script language (default: painless) + * @param {string} parent - ID of the parent document. Is is only used for routing and when for the upsert request + * @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 {number} retry_on_conflict - Specify how many times should the operation be retried when a conflict occurs (default: 0) + * @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 + * @param {object} body - The request definition requires either `script` or partial `doc` + */ + return function update (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + update(params, (err, body) => { + err ? reject(err) : resolve(body) + }) + }) + } + + // check required parameters + if (params['id'] == null) { + return callback( + new ConfigurationError('Missing required parameter: id'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['index'] == null) { + return callback( + new ConfigurationError('Missing required parameter: index'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['type'] == null) { + return callback( + new ConfigurationError('Missing required parameter: type'), + { body: null, headers: null, statusCode: null } + ) + } + if (params['body'] == null) { + return callback( + new ConfigurationError('Missing required parameter: body'), + { body: null, headers: null, statusCode: null } + ) + } + + // check required url components + if (params['id'] != null && (params['type'] == null || params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: type, index'), + { body: null, headers: null, statusCode: null } + ) + } else if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'wait_for_active_shards', + 'fields', + '_source', + '_source_exclude', + '_source_include', + 'lang', + 'parent', + 'refresh', + 'retry_on_conflict', + 'routing', + 'timeout', + 'version', + 'version_type', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'waitForActiveShards', + 'fields', + '_source', + '_sourceExclude', + '_sourceInclude', + 'lang', + 'parent', + 'refresh', + 'retryOnConflict', + 'routing', + 'timeout', + 'version', + 'versionType', + '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'], params['type'], params['id'], '_update'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildUpdate diff --git a/api/api/update_by_query.js b/api/api/update_by_query.js new file mode 100644 index 000000000..7e3a2ec1c --- /dev/null +++ b/api/api/update_by_query.js @@ -0,0 +1,212 @@ +'use strict' + +function buildUpdateByQuery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError } = opts + /** + * Perform a [update_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to search; leave empty to perform the operation on all types + * @param {string} analyzer - The analyzer to use for the query string + * @param {boolean} analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) + * @param {enum} default_operator - The default operator for query string query (AND or OR) + * @param {string} df - The field to use as default where no field prefix is given in the query string + * @param {number} from - Starting offset (default: 0) + * @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} conflicts - What to do when the update by query hits version conflicts? + * @param {enum} expand_wildcards - Whether to expand wildcard expression to concrete indices that are open, closed or both. + * @param {boolean} lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * @param {string} pipeline - Ingest pipeline to set on index requests made by this action. (default: none) + * @param {string} preference - Specify the node or shard the operation should be performed on (default: random) + * @param {string} q - Query in the Lucene query string syntax + * @param {list} routing - A comma-separated list of specific routing values + * @param {time} scroll - Specify how long a consistent view of the index should be maintained for scrolled search + * @param {enum} search_type - Search operation type + * @param {time} search_timeout - Explicit timeout for each search request. Defaults to no timeout. + * @param {number} size - Number of hits to return (default: 10) + * @param {list} sort - A comma-separated list of : pairs + * @param {list} _source - True or false to return the _source field or not, or a list of fields to return + * @param {list} _source_exclude - A list of fields to exclude from the returned _source field + * @param {list} _source_include - A list of fields to extract and return from the _source field + * @param {number} terminate_after - The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * @param {list} stats - Specific 'tag' of the request for logging and statistical purposes + * @param {boolean} version - Specify whether to return document version as part of a hit + * @param {boolean} version_type - Should the document increment the version number (internal) on hit or not (reindex) + * @param {boolean} request_cache - Specify if request cache should be used for this request or not, defaults to index level setting + * @param {boolean} refresh - Should the effected indexes be refreshed? + * @param {time} timeout - Time each individual bulk request should wait for shards that are unavailable. + * @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before proceeding with the update by query 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 {number} scroll_size - Size on the scroll request powering the update by query + * @param {boolean} wait_for_completion - Should the request should block until the update by query operation is complete. + * @param {number} requests_per_second - The throttle to set on this request in sub-requests per second. -1 means no throttle. + * @param {number} slices - The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. + * @param {object} body - The search definition using the Query DSL + */ + return function updateByQuery (params, callback) { + if (typeof params === 'function' || params == null) { + callback = params + params = {} + } + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + updateByQuery(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 } + ) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + return callback( + new ConfigurationError('Missing required parameter of the url: index'), + { body: null, headers: null, statusCode: null } + ) + } + + // build querystring object + const querystring = {} + const keys = Object.keys(params) + const acceptedQuerystring = [ + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'from', + 'ignore_unavailable', + 'allow_no_indices', + 'conflicts', + 'expand_wildcards', + 'lenient', + 'pipeline', + 'preference', + 'q', + 'routing', + 'scroll', + 'search_type', + 'search_timeout', + 'size', + 'sort', + '_source', + '_source_exclude', + '_source_include', + 'terminate_after', + 'stats', + 'version', + 'version_type', + 'request_cache', + 'refresh', + 'timeout', + 'wait_for_active_shards', + 'scroll_size', + 'wait_for_completion', + 'requests_per_second', + 'slices', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + const acceptedQuerystringCamelCased = [ + 'analyzer', + 'analyzeWildcard', + 'defaultOperator', + 'df', + 'from', + 'ignoreUnavailable', + 'allowNoIndices', + 'conflicts', + 'expandWildcards', + 'lenient', + 'pipeline', + 'preference', + 'q', + 'routing', + 'scroll', + 'searchType', + 'searchTimeout', + 'size', + 'sort', + '_source', + '_sourceExclude', + '_sourceInclude', + 'terminateAfter', + 'stats', + 'version', + 'versionType', + 'requestCache', + 'refresh', + 'timeout', + 'waitForActiveShards', + 'scrollSize', + 'waitForCompletion', + 'requestsPerSecond', + 'slices', + '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'], params['type'], '_update_by_query'] + const request = { + method, + path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'), + querystring, + body: params.body || '', + headers: params.headers || null, + ignore, + requestTimeout: params.requestTimeout || null, + agent: null, + url: '' + } + + return makeRequest(request, callback) + } +} + +module.exports = buildUpdateByQuery diff --git a/api/index.js b/api/index.js new file mode 100644 index 000000000..da91b8259 --- /dev/null +++ b/api/index.js @@ -0,0 +1,379 @@ +'use strict' + +const assert = require('assert') + +function ESAPI (opts) { + assert(opts.makeRequest, 'Missing makeRequest function') + assert(opts.ConfigurationError, 'Missing ConfigurationError class') + + const apis = { + bulk: require('./api/bulk.js')(opts), + cat: { + aliases: require('./api/cat.aliases.js')(opts), + allocation: require('./api/cat.allocation.js')(opts), + count: require('./api/cat.count.js')(opts), + fielddata: require('./api/cat.fielddata.js')(opts), + health: require('./api/cat.health.js')(opts), + help: require('./api/cat.help.js')(opts), + indices: require('./api/cat.indices.js')(opts), + master: require('./api/cat.master.js')(opts), + nodeattrs: require('./api/cat.nodeattrs.js')(opts), + nodes: require('./api/cat.nodes.js')(opts), + pending_tasks: require('./api/cat.pending_tasks.js')(opts), + plugins: require('./api/cat.plugins.js')(opts), + recovery: require('./api/cat.recovery.js')(opts), + repositories: require('./api/cat.repositories.js')(opts), + segments: require('./api/cat.segments.js')(opts), + shards: require('./api/cat.shards.js')(opts), + snapshots: require('./api/cat.snapshots.js')(opts), + tasks: require('./api/cat.tasks.js')(opts), + templates: require('./api/cat.templates.js')(opts), + thread_pool: require('./api/cat.thread_pool.js')(opts) + }, + clear_scroll: require('./api/clear_scroll.js')(opts), + cluster: { + allocation_explain: require('./api/cluster.allocation_explain.js')(opts), + get_settings: require('./api/cluster.get_settings.js')(opts), + health: require('./api/cluster.health.js')(opts), + pending_tasks: require('./api/cluster.pending_tasks.js')(opts), + put_settings: require('./api/cluster.put_settings.js')(opts), + remote_info: require('./api/cluster.remote_info.js')(opts), + reroute: require('./api/cluster.reroute.js')(opts), + state: require('./api/cluster.state.js')(opts), + stats: require('./api/cluster.stats.js')(opts) + }, + count: require('./api/count.js')(opts), + create: require('./api/create.js')(opts), + delete: require('./api/delete.js')(opts), + delete_by_query: require('./api/delete_by_query.js')(opts), + delete_script: require('./api/delete_script.js')(opts), + exists: require('./api/exists.js')(opts), + exists_source: require('./api/exists_source.js')(opts), + explain: require('./api/explain.js')(opts), + field_caps: require('./api/field_caps.js')(opts), + get: require('./api/get.js')(opts), + get_script: require('./api/get_script.js')(opts), + get_source: require('./api/get_source.js')(opts), + index: require('./api/index.js')(opts), + indices: { + analyze: require('./api/indices.analyze.js')(opts), + clear_cache: require('./api/indices.clear_cache.js')(opts), + close: require('./api/indices.close.js')(opts), + create: require('./api/indices.create.js')(opts), + delete: require('./api/indices.delete.js')(opts), + delete_alias: require('./api/indices.delete_alias.js')(opts), + delete_template: require('./api/indices.delete_template.js')(opts), + exists: require('./api/indices.exists.js')(opts), + exists_alias: require('./api/indices.exists_alias.js')(opts), + exists_template: require('./api/indices.exists_template.js')(opts), + exists_type: require('./api/indices.exists_type.js')(opts), + flush: require('./api/indices.flush.js')(opts), + flush_synced: require('./api/indices.flush_synced.js')(opts), + forcemerge: require('./api/indices.forcemerge.js')(opts), + get: require('./api/indices.get.js')(opts), + get_alias: require('./api/indices.get_alias.js')(opts), + get_field_mapping: require('./api/indices.get_field_mapping.js')(opts), + get_mapping: require('./api/indices.get_mapping.js')(opts), + get_settings: require('./api/indices.get_settings.js')(opts), + get_template: require('./api/indices.get_template.js')(opts), + get_upgrade: require('./api/indices.get_upgrade.js')(opts), + open: require('./api/indices.open.js')(opts), + put_alias: require('./api/indices.put_alias.js')(opts), + put_mapping: require('./api/indices.put_mapping.js')(opts), + put_settings: require('./api/indices.put_settings.js')(opts), + put_template: require('./api/indices.put_template.js')(opts), + recovery: require('./api/indices.recovery.js')(opts), + refresh: require('./api/indices.refresh.js')(opts), + rollover: require('./api/indices.rollover.js')(opts), + segments: require('./api/indices.segments.js')(opts), + shard_stores: require('./api/indices.shard_stores.js')(opts), + shrink: require('./api/indices.shrink.js')(opts), + split: require('./api/indices.split.js')(opts), + stats: require('./api/indices.stats.js')(opts), + update_aliases: require('./api/indices.update_aliases.js')(opts), + upgrade: require('./api/indices.upgrade.js')(opts), + validate_query: require('./api/indices.validate_query.js')(opts) + }, + info: require('./api/info.js')(opts), + ingest: { + delete_pipeline: require('./api/ingest.delete_pipeline.js')(opts), + get_pipeline: require('./api/ingest.get_pipeline.js')(opts), + processor_grok: require('./api/ingest.processor_grok.js')(opts), + put_pipeline: require('./api/ingest.put_pipeline.js')(opts), + simulate: require('./api/ingest.simulate.js')(opts) + }, + mget: require('./api/mget.js')(opts), + msearch: require('./api/msearch.js')(opts), + msearch_template: require('./api/msearch_template.js')(opts), + mtermvectors: require('./api/mtermvectors.js')(opts), + nodes: { + hot_threads: require('./api/nodes.hot_threads.js')(opts), + info: require('./api/nodes.info.js')(opts), + stats: require('./api/nodes.stats.js')(opts), + usage: require('./api/nodes.usage.js')(opts) + }, + ping: require('./api/ping.js')(opts), + put_script: require('./api/put_script.js')(opts), + rank_eval: require('./api/rank_eval.js')(opts), + reindex: require('./api/reindex.js')(opts), + reindex_rethrottle: require('./api/reindex_rethrottle.js')(opts), + render_search_template: require('./api/render_search_template.js')(opts), + scripts_painless_execute: require('./api/scripts_painless_execute.js')(opts), + scroll: require('./api/scroll.js')(opts), + search: require('./api/search.js')(opts), + search_shards: require('./api/search_shards.js')(opts), + search_template: require('./api/search_template.js')(opts), + snapshot: { + create: require('./api/snapshot.create.js')(opts), + create_repository: require('./api/snapshot.create_repository.js')(opts), + delete: require('./api/snapshot.delete.js')(opts), + delete_repository: require('./api/snapshot.delete_repository.js')(opts), + get: require('./api/snapshot.get.js')(opts), + get_repository: require('./api/snapshot.get_repository.js')(opts), + restore: require('./api/snapshot.restore.js')(opts), + status: require('./api/snapshot.status.js')(opts), + verify_repository: require('./api/snapshot.verify_repository.js')(opts) + }, + tasks: { + cancel: require('./api/tasks.cancel.js')(opts), + get: require('./api/tasks.get.js')(opts), + list: require('./api/tasks.list.js')(opts) + }, + termvectors: require('./api/termvectors.js')(opts), + update: require('./api/update.js')(opts), + update_by_query: require('./api/update_by_query.js')(opts) + } + + Object.defineProperties(apis.cat, { + pendingTasks: { + get: function () { return this.pending_tasks }, + enumerable: true + }, + threadPool: { + get: function () { return this.thread_pool }, + enumerable: true + } + }) + + Object.defineProperties(apis, { + clearScroll: { + get: function () { return this.clear_scroll }, + enumerable: true + }, + deleteByQuery: { + get: function () { return this.delete_by_query }, + enumerable: true + }, + deleteScript: { + get: function () { return this.delete_script }, + enumerable: true + }, + existsSource: { + get: function () { return this.exists_source }, + enumerable: true + }, + fieldCaps: { + get: function () { return this.field_caps }, + enumerable: true + }, + getScript: { + get: function () { return this.get_script }, + enumerable: true + }, + getSource: { + get: function () { return this.get_source }, + enumerable: true + }, + msearchTemplate: { + get: function () { return this.msearch_template }, + enumerable: true + }, + putScript: { + get: function () { return this.put_script }, + enumerable: true + }, + rankEval: { + get: function () { return this.rank_eval }, + enumerable: true + }, + reindexRethrottle: { + get: function () { return this.reindex_rethrottle }, + enumerable: true + }, + renderSearchTemplate: { + get: function () { return this.render_search_template }, + enumerable: true + }, + scriptsPainlessExecute: { + get: function () { return this.scripts_painless_execute }, + enumerable: true + }, + searchShards: { + get: function () { return this.search_shards }, + enumerable: true + }, + searchTemplate: { + get: function () { return this.search_template }, + enumerable: true + }, + updateByQuery: { + get: function () { return this.update_by_query }, + enumerable: true + } + }) + + Object.defineProperties(apis.cluster, { + allocationExplain: { + get: function () { return this.allocation_explain }, + enumerable: true + }, + getSettings: { + get: function () { return this.get_settings }, + enumerable: true + }, + pendingTasks: { + get: function () { return this.pending_tasks }, + enumerable: true + }, + putSettings: { + get: function () { return this.put_settings }, + enumerable: true + }, + remoteInfo: { + get: function () { return this.remote_info }, + enumerable: true + } + }) + + Object.defineProperties(apis.indices, { + clearCache: { + get: function () { return this.clear_cache }, + enumerable: true + }, + deleteAlias: { + get: function () { return this.delete_alias }, + enumerable: true + }, + deleteTemplate: { + get: function () { return this.delete_template }, + enumerable: true + }, + existsAlias: { + get: function () { return this.exists_alias }, + enumerable: true + }, + existsTemplate: { + get: function () { return this.exists_template }, + enumerable: true + }, + existsType: { + get: function () { return this.exists_type }, + enumerable: true + }, + flushSynced: { + get: function () { return this.flush_synced }, + enumerable: true + }, + getAlias: { + get: function () { return this.get_alias }, + enumerable: true + }, + getFieldMapping: { + get: function () { return this.get_field_mapping }, + enumerable: true + }, + getMapping: { + get: function () { return this.get_mapping }, + enumerable: true + }, + getSettings: { + get: function () { return this.get_settings }, + enumerable: true + }, + getTemplate: { + get: function () { return this.get_template }, + enumerable: true + }, + getUpgrade: { + get: function () { return this.get_upgrade }, + enumerable: true + }, + putAlias: { + get: function () { return this.put_alias }, + enumerable: true + }, + putMapping: { + get: function () { return this.put_mapping }, + enumerable: true + }, + putSettings: { + get: function () { return this.put_settings }, + enumerable: true + }, + putTemplate: { + get: function () { return this.put_template }, + enumerable: true + }, + shardStores: { + get: function () { return this.shard_stores }, + enumerable: true + }, + updateAliases: { + get: function () { return this.update_aliases }, + enumerable: true + }, + validateQuery: { + get: function () { return this.validate_query }, + enumerable: true + } + }) + + Object.defineProperties(apis.ingest, { + deletePipeline: { + get: function () { return this.delete_pipeline }, + enumerable: true + }, + getPipeline: { + get: function () { return this.get_pipeline }, + enumerable: true + }, + processorGrok: { + get: function () { return this.processor_grok }, + enumerable: true + }, + putPipeline: { + get: function () { return this.put_pipeline }, + enumerable: true + } + }) + + Object.defineProperties(apis.nodes, { + hotThreads: { + get: function () { return this.hot_threads }, + enumerable: true + } + }) + + Object.defineProperties(apis.snapshot, { + createRepository: { + get: function () { return this.create_repository }, + enumerable: true + }, + deleteRepository: { + get: function () { return this.delete_repository }, + enumerable: true + }, + getRepository: { + get: function () { return this.get_repository }, + enumerable: true + }, + verifyRepository: { + get: function () { return this.verify_repository }, + enumerable: true + } + }) + + return apis +} + +module.exports = ESAPI diff --git a/index.js b/index.js index 25cf37cff..da531097e 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const selectors = require('./lib/Selectors') const symbols = require('./lib/symbols') const { ConfigurationError } = require('./lib/errors') -// const buildApi = require('../monorepo/packages/es-api-6') +const buildApi = require('./api') const { kTransport, @@ -85,14 +85,14 @@ class Client extends EventEmitter { this.request = this[kTransport].request.bind(this[kTransport]) - // const apis = buildApi({ - // makeRequest: this[kTransport].request.bind(this[kTransport]) - // }) - - // Object.keys(apis).forEach(api => { - // this[api] = apis[api] - // }) + const apis = buildApi({ + makeRequest: this[kTransport].request.bind(this[kTransport]), + ConfigurationError + }) + Object.keys(apis).forEach(api => { + this[api] = apis[api] + }) } }