From 93648ce8c138310a2b789a98cd35adc9f50a1919 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 22 Apr 2014 11:09:51 -0700 Subject: [PATCH] updated to the latest API, which moves the experimental benchmark API (in the unreleased API versions master and 1.x) and includes a new indices.updateAliases example. Closes #83 --- docs/_examples/indices.updateAliases.asciidoc | 14 ++ docs/api_methods.asciidoc | 15 +- docs/api_methods_0_90.asciidoc | 15 +- docs/api_methods_1_0.asciidoc | 15 +- docs/api_methods_1_x.asciidoc | 171 ++++++++++-------- docs/api_methods_master.asciidoc | 171 ++++++++++-------- src/lib/apis/1_0.js | 17 +- src/lib/apis/1_1.js | 17 +- src/lib/apis/1_x.js | 99 +++++----- src/lib/apis/master.js | 99 +++++----- 10 files changed, 362 insertions(+), 271 deletions(-) create mode 100644 docs/_examples/indices.updateAliases.asciidoc diff --git a/docs/_examples/indices.updateAliases.asciidoc b/docs/_examples/indices.updateAliases.asciidoc new file mode 100644 index 000000000..0e97c7eaf --- /dev/null +++ b/docs/_examples/indices.updateAliases.asciidoc @@ -0,0 +1,14 @@ +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- \ No newline at end of file diff --git a/docs/api_methods.asciidoc b/docs/api_methods.asciidoc index ca9bd470a..7a1b57a75 100644 --- a/docs/api_methods.asciidoc +++ b/docs/api_methods.asciidoc @@ -3666,7 +3666,20 @@ Update specified aliases. The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html[the elasticsearch docs] for more about this method. -// no examples +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- ==== Params diff --git a/docs/api_methods_0_90.asciidoc b/docs/api_methods_0_90.asciidoc index 1b8e5f354..6eb447ec1 100644 --- a/docs/api_methods_0_90.asciidoc +++ b/docs/api_methods_0_90.asciidoc @@ -2915,7 +2915,20 @@ Update specified aliases. The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/indices-aliases.html[the elasticsearch docs] for more about this method. -// no examples +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- ==== Params diff --git a/docs/api_methods_1_0.asciidoc b/docs/api_methods_1_0.asciidoc index 4a86b3e6c..0fde9556f 100644 --- a/docs/api_methods_1_0.asciidoc +++ b/docs/api_methods_1_0.asciidoc @@ -3559,7 +3559,20 @@ Update specified aliases. The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html[the elasticsearch docs] for more about this method. -// no examples +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- ==== Params diff --git a/docs/api_methods_1_x.asciidoc b/docs/api_methods_1_x.asciidoc index 0ba6203f4..74b105142 100644 --- a/docs/api_methods_1_x.asciidoc +++ b/docs/api_methods_1_x.asciidoc @@ -5,6 +5,8 @@ NOTE: At this time, you must opt into the 1.x API by setting the `apiVersion` config parameter. [[js-api-method-index-1-x]] +* <> +* <> * <> * <> * <> @@ -18,6 +20,7 @@ NOTE: At this time, you must opt into the 1.x API by setting the `apiVersion` co * <> * <> * <> +* <> * <> * <> * <> @@ -31,9 +34,6 @@ NOTE: At this time, you must opt into the 1.x API by setting the `apiVersion` co * <> * <> * <> -* <> -* <> -* <> * <> * <> * <> @@ -102,6 +102,56 @@ NOTE: At this time, you must opt into the 1.x API by setting the `apiVersion` co * <> * <> +[[api-abortbenchmark-1-x]] +=== `abortBenchmark` + +[source,js] +-------- +client.abortBenchmark([params, [callback]]) +-------- + +// no description + +The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`name`:: +`String` -- A benchmark name + +link:#[back to top] + +[[api-benchmark-1-x]] +=== `benchmark` + +[source,js] +-------- +client.benchmark([params, [callback]]) +-------- + +// no description + +The default method is `PUT` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`verbose`:: +`Boolean` -- Specify whether to return verbose statistics about each iteration (default: false) +`index`:: +`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices +`type`:: +`String` -- The name of the document type + +link:#[back to top] + [[api-bulk-1-x]] === `bulk` @@ -919,6 +969,31 @@ The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`index`:: +`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices +`type`:: +`String` -- The name of the document type + +link:#[back to top] + [[api-mget-1-x]] === `mget` @@ -1839,81 +1914,6 @@ Options::: link:#[back to top] -[[api-benchmark-abort-1-x]] -=== `benchmark.abort` - -[source,js] --------- -client.benchmark.abort([params, [callback]]) --------- - -// no description - -The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`name`:: -`String` -- A benchmark name - -link:#[back to top] - -[[api-benchmark-list-1-x]] -=== `benchmark.list` - -[source,js] --------- -client.benchmark.list([params, [callback]]) --------- - -// no description - -The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`index`:: -`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices -`type`:: -`String` -- The name of the document type - -link:#[back to top] - -[[api-benchmark-submit-1-x]] -=== `benchmark.submit` - -[source,js] --------- -client.benchmark.submit([params, [callback]]) --------- - -// no description - -The default method is `PUT` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`verbose`:: -`Boolean` -- Specify whether to return verbose statistics about each iteration (default: false) -`index`:: -`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices -`type`:: -`String` -- The name of the document type - -link:#[back to top] - [[api-cat-aliases-1-x]] === `cat.aliases` @@ -3736,7 +3736,20 @@ Update specified aliases. The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html[the elasticsearch docs] for more about this method. -// no examples +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- ==== Params diff --git a/docs/api_methods_master.asciidoc b/docs/api_methods_master.asciidoc index 915a49492..c75751ab4 100644 --- a/docs/api_methods_master.asciidoc +++ b/docs/api_methods_master.asciidoc @@ -5,6 +5,8 @@ NOTE: At this time, you must opt into the master API by setting the `apiVersion` config parameter. [[js-api-method-index-master]] +* <> +* <> * <> * <> * <> @@ -18,6 +20,7 @@ NOTE: At this time, you must opt into the master API by setting the `apiVersion` * <> * <> * <> +* <> * <> * <> * <> @@ -31,9 +34,6 @@ NOTE: At this time, you must opt into the master API by setting the `apiVersion` * <> * <> * <> -* <> -* <> -* <> * <> * <> * <> @@ -102,6 +102,56 @@ NOTE: At this time, you must opt into the master API by setting the `apiVersion` * <> * <> +[[api-abortbenchmark-master]] +=== `abortBenchmark` + +[source,js] +-------- +client.abortBenchmark([params, [callback]]) +-------- + +// no description + +The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`name`:: +`String` -- A benchmark name + +link:#[back to top] + +[[api-benchmark-master]] +=== `benchmark` + +[source,js] +-------- +client.benchmark([params, [callback]]) +-------- + +// no description + +The default method is `PUT` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`verbose`:: +`Boolean` -- Specify whether to return verbose statistics about each iteration (default: false) +`index`:: +`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices +`type`:: +`String` -- The name of the document type + +link:#[back to top] + [[api-bulk-master]] === `bulk` @@ -919,6 +969,31 @@ The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`index`:: +`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices +`type`:: +`String` -- The name of the document type + +link:#[back to top] + [[api-mget-master]] === `mget` @@ -1839,81 +1914,6 @@ Options::: link:#[back to top] -[[api-benchmark-abort-master]] -=== `benchmark.abort` - -[source,js] --------- -client.benchmark.abort([params, [callback]]) --------- - -// no description - -The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`name`:: -`String` -- A benchmark name - -link:#[back to top] - -[[api-benchmark-list-master]] -=== `benchmark.list` - -[source,js] --------- -client.benchmark.list([params, [callback]]) --------- - -// no description - -The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`index`:: -`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices -`type`:: -`String` -- The name of the document type - -link:#[back to top] - -[[api-benchmark-submit-master]] -=== `benchmark.submit` - -[source,js] --------- -client.benchmark.submit([params, [callback]]) --------- - -// no description - -The default method is `PUT` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html[the elasticsearch docs] for more about this method. - -// no examples - - -==== Params - -[horizontal] -`verbose`:: -`Boolean` -- Specify whether to return verbose statistics about each iteration (default: false) -`index`:: -`String, String[], Boolean` -- A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices -`type`:: -`String` -- The name of the document type - -link:#[back to top] - [[api-cat-aliases-master]] === `cat.aliases` @@ -3736,7 +3736,20 @@ Update specified aliases. The default method is `POST` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/indices-aliases.html[the elasticsearch docs] for more about this method. -// no examples +.Perform an atomic alias swap, for a rotating index +[source,js] +--------- +client.indices.updateAliases({ + body: { + actions: [ + { remove: { index: 'logstash-2014.04', alias: 'logstash-current' } }, + { add: { index: 'logstash-2014.05', alias: 'logstash-current' } } + ] + } +}).then(function (response) { + // ... +}, errorHandler); +--------- ==== Params diff --git a/src/lib/apis/1_0.js b/src/lib/apis/1_0.js index 49d9ad9f7..22d20452d 100644 --- a/src/lib/apis/1_0.js +++ b/src/lib/apis/1_0.js @@ -614,14 +614,19 @@ api.cat.prototype.threadPool = ca({ * @param {String, String[], Boolean} params.scrollId - A comma-separated list of scroll IDs to clear */ api.clearScroll = ca({ - url: { - fmt: '/_search/scroll/<%=scrollId%>', - req: { - scrollId: { - type: 'list' + urls: [ + { + fmt: '/_search/scroll/<%=scrollId%>', + req: { + scrollId: { + type: 'list' + } } + }, + { + fmt: '/_search/scroll' } - }, + ], method: 'DELETE' }); diff --git a/src/lib/apis/1_1.js b/src/lib/apis/1_1.js index 80e0ec3ef..1b2b9d29d 100644 --- a/src/lib/apis/1_1.js +++ b/src/lib/apis/1_1.js @@ -646,14 +646,19 @@ api.cat.prototype.threadPool = ca({ * @param {String, String[], Boolean} params.scrollId - A comma-separated list of scroll IDs to clear */ api.clearScroll = ca({ - url: { - fmt: '/_search/scroll/<%=scrollId%>', - req: { - scrollId: { - type: 'list' + urls: [ + { + fmt: '/_search/scroll/<%=scrollId%>', + req: { + scrollId: { + type: 'list' + } } + }, + { + fmt: '/_search/scroll' } - }, + ], method: 'DELETE' }); diff --git a/src/lib/apis/1_x.js b/src/lib/apis/1_x.js index b43469a8e..c4e3f248e 100644 --- a/src/lib/apis/1_x.js +++ b/src/lib/apis/1_x.js @@ -3,19 +3,15 @@ var ca = require('../client_action'); var api = module.exports = {}; -api._namespaces = ['benchmark', 'cat', 'cluster', 'indices', 'nodes', 'snapshot']; - -api.benchmark = function BenchmarkNS(transport) { - this.transport = transport; -}; +api._namespaces = ['cat', 'cluster', 'indices', 'nodes', 'snapshot']; /** - * Perform a [benchmark.abort](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * Perform a [abortBenchmark](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request * * @param {Object} params - An object with parameters used to carry out this action * @param {String} params.name - A benchmark name */ -api.benchmark.prototype.abort = ca({ +api.abortBenchmark = ca({ url: { fmt: '/_bench/abort/<%=name%>', req: { @@ -28,48 +24,14 @@ api.benchmark.prototype.abort = ca({ }); /** - * Perform a [benchmark.list](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request - * - * @param {Object} params - An object with parameters used to carry out this action - * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices - * @param {String} params.type - The name of the document type - */ -api.benchmark.prototype.list = ca({ - urls: [ - { - fmt: '/<%=index%>/<%=type%>/_bench', - req: { - index: { - type: 'list' - }, - type: { - type: 'string' - } - } - }, - { - fmt: '/<%=index%>/_bench', - req: { - index: { - type: 'list' - } - } - }, - { - fmt: '/_bench' - } - ] -}); - -/** - * Perform a [benchmark.submit](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * Perform a [benchmark](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request * * @param {Object} params - An object with parameters used to carry out this action * @param {Boolean} params.verbose - Specify whether to return verbose statistics about each iteration (default: false) * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices * @param {String} params.type - The name of the document type */ -api.benchmark.prototype.submit = ca({ +api.benchmark = ca({ params: { verbose: { type: 'boolean' @@ -743,14 +705,19 @@ api.cat.prototype.threadPool = ca({ * @param {String, String[], Boolean} params.scrollId - A comma-separated list of scroll IDs to clear */ api.clearScroll = ca({ - url: { - fmt: '/_search/scroll/<%=scrollId%>', - req: { - scrollId: { - type: 'list' + urls: [ + { + fmt: '/_search/scroll/<%=scrollId%>', + req: { + scrollId: { + type: 'list' + } } + }, + { + fmt: '/_search/scroll' } - }, + ], method: 'DELETE' }); @@ -3732,6 +3699,40 @@ api.info = ca({ } }); +/** + * Perform a [listBenchmarks](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * @param {String} params.type - The name of the document type + */ +api.listBenchmarks = ca({ + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_bench', + req: { + index: { + type: 'list' + }, + type: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_bench', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_bench' + } + ] +}); + /** * Perform a [mget](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/docs-multi-get.html) request * diff --git a/src/lib/apis/master.js b/src/lib/apis/master.js index a4af5d581..3e88b7fb3 100644 --- a/src/lib/apis/master.js +++ b/src/lib/apis/master.js @@ -3,19 +3,15 @@ var ca = require('../client_action'); var api = module.exports = {}; -api._namespaces = ['benchmark', 'cat', 'cluster', 'indices', 'nodes', 'snapshot']; - -api.benchmark = function BenchmarkNS(transport) { - this.transport = transport; -}; +api._namespaces = ['cat', 'cluster', 'indices', 'nodes', 'snapshot']; /** - * Perform a [benchmark.abort](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * Perform a [abortBenchmark](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request * * @param {Object} params - An object with parameters used to carry out this action * @param {String} params.name - A benchmark name */ -api.benchmark.prototype.abort = ca({ +api.abortBenchmark = ca({ url: { fmt: '/_bench/abort/<%=name%>', req: { @@ -28,48 +24,14 @@ api.benchmark.prototype.abort = ca({ }); /** - * Perform a [benchmark.list](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request - * - * @param {Object} params - An object with parameters used to carry out this action - * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices - * @param {String} params.type - The name of the document type - */ -api.benchmark.prototype.list = ca({ - urls: [ - { - fmt: '/<%=index%>/<%=type%>/_bench', - req: { - index: { - type: 'list' - }, - type: { - type: 'string' - } - } - }, - { - fmt: '/<%=index%>/_bench', - req: { - index: { - type: 'list' - } - } - }, - { - fmt: '/_bench' - } - ] -}); - -/** - * Perform a [benchmark.submit](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * Perform a [benchmark](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request * * @param {Object} params - An object with parameters used to carry out this action * @param {Boolean} params.verbose - Specify whether to return verbose statistics about each iteration (default: false) * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices * @param {String} params.type - The name of the document type */ -api.benchmark.prototype.submit = ca({ +api.benchmark = ca({ params: { verbose: { type: 'boolean' @@ -743,14 +705,19 @@ api.cat.prototype.threadPool = ca({ * @param {String, String[], Boolean} params.scrollId - A comma-separated list of scroll IDs to clear */ api.clearScroll = ca({ - url: { - fmt: '/_search/scroll/<%=scrollId%>', - req: { - scrollId: { - type: 'list' + urls: [ + { + fmt: '/_search/scroll/<%=scrollId%>', + req: { + scrollId: { + type: 'list' + } } + }, + { + fmt: '/_search/scroll' } - }, + ], method: 'DELETE' }); @@ -3732,6 +3699,40 @@ api.info = ca({ } }); +/** + * Perform a [listBenchmarks](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * @param {String} params.type - The name of the document type + */ +api.listBenchmarks = ca({ + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_bench', + req: { + index: { + type: 'list' + }, + type: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_bench', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_bench' + } + ] +}); + /** * Perform a [mget](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/docs-multi-get.html) request *