diff --git a/.DS_Store b/.DS_Store index 908fdb955..4eca301ad 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.jshintrc b/.jshintrc index d6b86007b..b93ee9388 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,6 @@ { "node": true, "white": true, - "bitwise": false, "curly": true, "eqnull": true, @@ -24,5 +23,6 @@ "validthis": true, "sub": true, "maxlen": 140, - "-W084": true + "-W084": true, + "maxerr": 10 } diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..fdc4be762 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "0.11" + - "0.10" + - "0.8" + - "0.6" +services: + - elasticsearch diff --git a/Gruntfile.js b/Gruntfile.js index 8e5f6f8b4..88effd851 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,20 +3,6 @@ module.exports = function (grunt) { - var argv = require('optimist').argv; - - var pre = [ - 'src/pre.js', - 'src/shared.js', - 'src/serializer.js', - 'src/serializer/*', - 'src/selector.js', - 'src/logger/*', - 'src/transport.js' - ]; - - var post = ['src/client.js', 'src/post.js']; - // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), @@ -27,15 +13,6 @@ module.exports = function (grunt) { ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= pkg.license %> */\n\n' }, - concat: { - options: { - banner: '<%= meta.banner %>' - }, - node: { - src: pre.concat(['src/transport/elasticsearch-node.js'], post), - dest: 'dist/elasticsearch-node.js' - } - }, mochaTest: { unit: [ 'test/unit/**/*.test.js' @@ -52,40 +29,80 @@ module.exports = function (grunt) { jshint: { source: { src: [ - 'Gruntfile.js', 'src/**/*.js', - 'test/**/*.js' + 'test/**/*.js', + 'Gruntfile.js' ] }, options: { jshintrc: true } }, - yuidoc: { - compile: { - name: '<%= pkg.name %>', - description: '<%= pkg.description %>', - version: '<%= pkg.version %>', - url: '<%= pkg.homepage %>', - logo: '<%= pkg.logo %>', - options: { - paths: 'src', - themedir: '../yuidoc-bootstrap-theme', - helpers: [ - '../yuidoc-bootstrap-theme/helpers/helpers.js' - ], - outdir: 'docs' - } + watch: { + source: { + files: [ + 'src/**/*', + 'test/**/*', + 'Gruntfile.js' + ], + tasks: [ + 'jshint:source' + ] + }, + options: { + interupt: true } - } + }//, + // docular: { + // groups: [ + // { + // groupTitle: 'Node', + // groupId: 'example', + // groupIcon: 'icon-beer', + // sections: [ + // { + // id: "client", + // title: "Client", + // scripts: [ + // "src/lib/client.js" + // ], + // docs: [], + // rank : {} + // } + // ] + // } + // ], + // } + // , + // yuidoc: { + // compile: { + // name: '<%= pkg.name %>', + // description: '<%= pkg.description %>', + // version: '<%= pkg.version %>', + // url: '<%= pkg.homepage %>', + // logo: '<%= pkg.logo %>', + // options: { + // paths: 'src', + // themedir: '../yuidoc-bootstrap-theme', + // helpers: [ + // '../yuidoc-bootstrap-theme/helpers/helpers.js' + // ], + // outdir: 'docs' + // } + // } + // } }); // load plugins + grunt.loadNpmTasks('grunt-docular'); grunt.loadNpmTasks('grunt-mocha-test'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-yuidoc'); // Default task. + grunt.registerTask('docs', ['docular']); grunt.registerTask('default', ['jshint', 'mochaTest']); + }; diff --git a/README.md b/README.md index f66c1a894..981a47318 100644 --- a/README.md +++ b/README.md @@ -11,152 +11,7 @@ Features - One-to-one mapping with REST API and other language clients - Configurable, automatic discovery of cluster nodes - - Persistent, Keep-Alive connections (within the lifetime of the script) + - Persistent, Keep-Alive connections - Load balancing (with pluggable selection strategy) across all availible nodes. Defaults to round-robin - Pluggable connection pools to offer different connection strategies - Generalized, pluggable architecture - most components can be replaced with your own custom class if specialized behavior is required - - -Documentation --------------- -[Full documentation can be found here.](http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/index.html) Docs are stored within the repo under /docs/, so if you see a typo or problem, please submit a PR to fix it! - -Installation via Composer -------------------------- -The recommended method to install _Elasticsearch-PHP_ is through [Composer](http://getcomposer.org). - -1. Add ``elasticsearch/elasticsearch`` as a dependency in your project's ``composer.json`` file: - -```json - { - "require": { - "elasticsearch/elasticsearch": "~0.4" - } - } -``` - -2. Download and install Composer: - - curl -s http://getcomposer.org/installer | php - -3. Install your dependencies: - - php composer.phar install - -4. Require Composer's autoloader - - Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process: - -```php - 'abc'); - $params['index'] = 'my_index'; - $params['type'] = 'my_type'; - $params['id'] = 'my_id'; - $ret = $client->index($params); -``` - -Get a document ------ - -Let's get the document that we just indexed: - -```php - $getParams = array(); - $getParams['index'] = 'my_index'; - $getParams['type'] = 'my_type'; - $getParams['id'] = 'my_id'; - $retDoc = $client->get($getParams); -``` - -Search for a document ------ - -Searching is a hallmark of elasticsearch (no surprise there!), so let's perform a basic search. We are going to use the Match query as a demonstration: - -```php - $searchParams['index'] = 'my_index'; - $searchParams['type'] = 'my_type'; - $searchParams['body']['query']['match']['testField'] = 'abc'; - $queryResponse = $client->search($searchParams); - - echo $queryResponse['hits']['hits'][0]['_id']; // Outputs 'abc' -``` - -Delete a document ------ - -Alright, let's go ahead and delete the document that we added previously: - -```php - $deleteParams = array(); - $deleteParams['index'] = 'my_index'; - $deleteParams['type'] = 'my_type'; - $deleteParams['id'] = 'my_id'; - $retDelete = $client->delete($deleteParams); -``` - -Delete an index ------ - -Due to the dynamic nature of elasticsearch, the first document we added automatically built an index with some default settings. Let's delete that index because we want to specify our own settings later: - -```php - $deleteParams['index'] = 'my_index'; - $client->indices()->delete($deleteParams); -``` - -Create an index ------ - -Ok, now that we are starting fresh, let's add a new index with some custom settings: -```php - $indexParams['index'] = 'my_index'; - $indexParams['body']['settings']['number_of_shards'] = 2; - $indexParams['body']['settings']['number_of_replicas'] = 0; - $client->indices()->create($indexParams); -``` - -Wrap up -======= - -That was just a crash-course overview of the client and it's syntax. If you are familiar with elasticsearch, you'll notice that the methods are named just like REST endpoints. - -You'll also notice that the client is configured in a manner that facilitates easy discovery via the IDE. All core actions are available under the $client object (indexing, searching, getting, etc). Index and cluster management are located under the $client->indices() and $client->cluster() objects, respectively. - -Check out the rest of the [Documentation](http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/index.html) to see how the entire client works. - - -License -------- - -Copyright 2013 Elasticsearch - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/package.json b/package.json index b2958a665..7e8c70df3 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,20 @@ "moment": "~2.2.1", "should": "~2.0.1", "sinon": "~1.7.3", - "grunt-mocha-test": "~0.7.0" + "grunt-mocha-test": "~0.7.0", + "grunt-contrib-watch": "~0.5.3", + "expect.js": "~0.2.0", + "async": "~0.2.9", + "optimist": "~0.6.0" }, "license": "Apache License", "dependencies": { - "lodash": "~2.0.0", "require-directory": "git://github.com/spenceralger/node-require-directory.git#master", "cli-color": "~0.2.3", "qs": "~0.6.5", - "expect.js": "~0.2.0", - "q": "~0.9.7", - "async": "~0.2.9", - "optimist": "~0.6.0" + "lodash": "~2.2.1" + }, + "scripts": { + "test": "grunt test" } } diff --git a/scripts/generate/js_api/index.js b/scripts/generate/js_api/index.js deleted file mode 100644 index b15041dae..000000000 --- a/scripts/generate/js_api/index.js +++ /dev/null @@ -1,59 +0,0 @@ -var _ = require('../../../src/lib/utils') - , asset = require('assert') - , path = require('path') - , fs = require('fs') - , mkdirp = require('mkdirp') - , docs = _.requireDir(module, '../../../es_api_spec/api') - , outputDir = _.joinPath(__dirname, '../../../src/api/') - , templates = require('./templates') - , notes = require('./notes') - , aliases = require('./aliases'); - -// completely delete the output directory -(function clean(path) { - if (fs.existsSync(path)) { - fs.readdirSync(path).forEach(function (file, index) { - var curPath = path + '/' + file; - if (fs.statSync(curPath).isDirectory()) { // recurse - clean(curPath); - } else { // delete file - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(path); - } -})(outputDir); - -// itterate all of the found docs -_.each(docs, function (doc) { - // and each definition within each doc (should only be one) - _.each(doc, function (def, name) { - - var steps = name.split('.') - , fileName = steps.pop() + '.js' - , dirName = _.joinPath(outputDir, steps.join('/') || './'); - - var spec = { - name: name, - methods: _.map(def.methods, function (m) { return m.toUpperCase(); }), - docUrl: def.documentation, - urlParts: def.url.parts, - params: def.url.params, - urls: _.difference(def.url.paths, aliases[name]), - body: def.body || null, - path2lib: _.repeat('../', steps.length + 1) + 'lib/', - notes: notes[name] - }; - - spec.enumOptions = _.object(_.filter(_.map(_.pairs(_.extend({}, spec.params, spec.urlParts)), function (pair) { - // pair = [name, param]; - if (pair[1].type === 'enum') { - return [_.camelCase(pair[0]), pair[1].options]; - } - }))); - - mkdirp.sync(dirName); - fs.writeFileSync(_.joinPath(dirName, fileName), templates.action(spec)); - - }); -}); diff --git a/scripts/generate/logs/samples/index.js b/scripts/generate/logs/samples/index.js index be6fda1bd..a8410ff4f 100644 --- a/scripts/generate/logs/samples/index.js +++ b/scripts/generate/logs/samples/index.js @@ -87,7 +87,7 @@ exports.make = function (startingMoment, endingMoment) { 'apache': 4 }); - return _.map(sets, function (set, name) { - return _.bindKey(set, 'get'); - }); + return _.transform(sets, function (note, set, name) { + note[name] = _.bindKey(set, 'get'); + }, {}); }; diff --git a/src/api/.jshintrc b/src/api/.jshintrc deleted file mode 100644 index b79722485..000000000 --- a/src/api/.jshintrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../.jshintrc", - "maxlen": 0 -} diff --git a/src/api/bulk.js b/src/api/bulk.js deleted file mode 100644 index 86e995625..000000000 --- a/src/api/bulk.js +++ /dev/null @@ -1,124 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var replicationOptions = ['sync', 'async']; - -/** - * Perform an elasticsearch [bulk](http://elasticsearch.org/guide/reference/api/bulk/) request - * - * @for Client - * @method bulk - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.consistency - Explicit write consistency setting for the operation - * @param {boolean} params.refresh - Refresh the index after performing the operation - * @param {String} [params.replication=sync] - Explicitely set the replication type - * @param {string} params.type - Default document type for items which don't provide one - */ -function doBulk(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: this.client.config.serializer.bulkBody(params.body || null) - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'PUT') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, PUT'); - } - } else { - request.method = 'POST'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_bulk'; - delete params.type; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_bulk'; - } - else { - request.path = '/_bulk'; - } - - - // build the query string - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - query.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doBulk; diff --git a/src/api/clear_scroll.js b/src/api/clear_scroll.js deleted file mode 100644 index 41b9c1f8c..000000000 --- a/src/api/clear_scroll.js +++ /dev/null @@ -1,65 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [clear_scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request - * - * @for Client - * @method clear_scroll - * @param {Object} params - An object with parameters used to carry out this action - */ -function doClearScroll(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.scroll_id !== 'undefined') { - switch (typeof params.scroll_id) { - case 'string': - parts.scroll_id = params.scroll_id; - break; - case 'object': - if (_.isArray(params.scroll_id)) { - parts.scroll_id = params.scroll_id.join(','); - } else { - throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.scroll_id = !!params.scroll_id; - } - } - - - // build the path - if (parts.hasOwnProperty('scroll_id')) { - request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClearScroll; diff --git a/src/api/cluster/get_settings.js b/src/api/cluster/get_settings.js deleted file mode 100644 index 742eb3a85..000000000 --- a/src/api/cluster/get_settings.js +++ /dev/null @@ -1,44 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.get_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request - * - * @for Client - * @method cluster.get_settings - * @param {Object} params - An object with parameters used to carry out this action - */ -function doClusterGetSettings(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - - - // build the path - request.path = '/_cluster/settings'; - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterGetSettings; diff --git a/src/api/cluster/health.js b/src/api/cluster/health.js deleted file mode 100644 index 7c4b30d7c..000000000 --- a/src/api/cluster/health.js +++ /dev/null @@ -1,142 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var levelOptions = ['cluster', 'indices', 'shards']; -var waitForStatusOptions = ['green', 'yellow', 'red']; - -/** - * Perform an elasticsearch [cluster.health](http://elasticsearch.org/guide/reference/api/admin-cluster-health/) request - * - * @for Client - * @method cluster.health - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.level=cluster] - Specify the level of detail for returned information - * @param {boolean} params.local - Return local information, do not retrieve the state from master node (default: false) - * @param {Date|Number} params.master_timeout - Explicit operation timeout for connection to master node - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {number} params.wait_for_active_shards - Wait until the specified number of shards is active - * @param {string} params.wait_for_nodes - Wait until the specified number of nodes is available - * @param {number} params.wait_for_relocating_shards - Wait until the specified number of relocating shards is finished - * @param {String} params.wait_for_status - Wait until cluster is in a specific state - */ -function doClusterHealth(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/_cluster/health/' + encodeURIComponent(parts.index) + ''; - } - else { - request.path = '/_cluster/health'; - } - - - // build the query string - if (typeof params.level !== 'undefined') { - if (_.contains(levelOptions, params.level)) { - query.level = params.level; - } else { - throw new TypeError( - 'Invalid level: ' + params.level + - ' should be one of ' + levelOptions.join(', ') + '.' - ); - } - } - - if (typeof params.local !== 'undefined') { - if (params.local.toLowerCase && (params.local = params.local.toLowerCase()) - && (params.local === 'no' || params.local === 'off') - ) { - query.local = false; - } else { - query.local = !!params.local; - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.wait_for_active_shards !== 'undefined') { - if (_.isNumeric(params.wait_for_active_shards)) { - query.wait_for_active_shards = params.wait_for_active_shards * 1; - } else { - throw new TypeError('Invalid wait_for_active_shards: ' + params.wait_for_active_shards + ' should be a number.'); - } - } - - if (typeof params.wait_for_nodes !== 'undefined') { - if (typeof params.wait_for_nodes !== 'object' && params.wait_for_nodes) { - query.wait_for_nodes = '' + params.wait_for_nodes; - } else { - throw new TypeError('Invalid wait_for_nodes: ' + params.wait_for_nodes + ' should be a string.'); - } - } - - if (typeof params.wait_for_relocating_shards !== 'undefined') { - if (_.isNumeric(params.wait_for_relocating_shards)) { - query.wait_for_relocating_shards = params.wait_for_relocating_shards * 1; - } else { - throw new TypeError('Invalid wait_for_relocating_shards: ' + params.wait_for_relocating_shards + ' should be a number.'); - } - } - - if (typeof params.wait_for_status !== 'undefined') { - if (_.contains(waitForStatusOptions, params.wait_for_status)) { - query.wait_for_status = params.wait_for_status; - } else { - throw new TypeError( - 'Invalid wait_for_status: ' + params.wait_for_status + - ' should be one of ' + waitForStatusOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterHealth; diff --git a/src/api/cluster/node_hot_threads.js b/src/api/cluster/node_hot_threads.js deleted file mode 100644 index 0594379b8..000000000 --- a/src/api/cluster/node_hot_threads.js +++ /dev/null @@ -1,107 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var typeOptions = ['cpu', 'wait', 'block']; - -/** - * Perform an elasticsearch [cluster.node_hot_threads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request - * - * @for Client - * @method cluster.node_hot_threads - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.interval - The interval for the second sampling of threads - * @param {number} params.snapshots - Number of samples of thread stacktrace (default: 10) - * @param {number} params.threads - Specify the number of threads to provide information for (default: 3) - * @param {String} params.type - The type to sample (default: cpu) - */ -function doClusterNodeHotThreads(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.node_id !== 'undefined') { - switch (typeof params.node_id) { - case 'string': - parts.node_id = params.node_id; - break; - case 'object': - if (_.isArray(params.node_id)) { - parts.node_id = params.node_id.join(','); - } else { - throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.node_id = !!params.node_id; - } - } - - - // build the path - if (parts.hasOwnProperty('node_id')) { - request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/hotthreads'; - } - else { - request.path = '/_nodes/hotthreads'; - } - - - // build the query string - if (typeof params.interval !== 'undefined') { - if (params.interval instanceof Date) { - query.interval = params.interval.getTime(); - } else if (_.isNumeric(params.interval)) { - query.interval = params.interval; - } else { - throw new TypeError('Invalid interval: ' + params.interval + ' should be be some sort of time.'); - } - } - - if (typeof params.snapshots !== 'undefined') { - if (_.isNumeric(params.snapshots)) { - query.snapshots = params.snapshots * 1; - } else { - throw new TypeError('Invalid snapshots: ' + params.snapshots + ' should be a number.'); - } - } - - if (typeof params.threads !== 'undefined') { - if (_.isNumeric(params.threads)) { - query.threads = params.threads * 1; - } else { - throw new TypeError('Invalid threads: ' + params.threads + ' should be a number.'); - } - } - - if (typeof params.type !== 'undefined') { - if (_.contains(typeOptions, params.type)) { - query.type = params.type; - } else { - throw new TypeError( - 'Invalid type: ' + params.type + - ' should be one of ' + typeOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterNodeHotThreads; diff --git a/src/api/cluster/node_info.js b/src/api/cluster/node_info.js deleted file mode 100644 index 69f55a8a1..000000000 --- a/src/api/cluster/node_info.js +++ /dev/null @@ -1,196 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request - * - * @for Client - * @method cluster.node_info - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.all - Return all available information - * @param {boolean} params.clear - Reset the default settings - * @param {boolean} params.http - Return information about HTTP - * @param {boolean} params.jvm - Return information about the JVM - * @param {boolean} params.network - Return information about network - * @param {boolean} params.os - Return information about the operating system - * @param {boolean} params.plugin - Return information about plugins - * @param {boolean} params.process - Return information about the Elasticsearch process - * @param {boolean} params.settings - Return information about node settings - * @param {boolean} params.thread_pool - Return information about the thread pool - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {boolean} params.transport - Return information about transport - */ -function doClusterNodeInfo(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.node_id !== 'undefined') { - switch (typeof params.node_id) { - case 'string': - parts.node_id = params.node_id; - break; - case 'object': - if (_.isArray(params.node_id)) { - parts.node_id = params.node_id.join(','); - } else { - throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.node_id = !!params.node_id; - } - } - - - // build the path - if (parts.hasOwnProperty('node_id')) { - request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + ''; - } - else { - request.path = '/_nodes'; - } - - - // build the query string - if (typeof params.all !== 'undefined') { - if (params.all.toLowerCase && (params.all = params.all.toLowerCase()) - && (params.all === 'no' || params.all === 'off') - ) { - query.all = false; - } else { - query.all = !!params.all; - } - } - - if (typeof params.clear !== 'undefined') { - if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase()) - && (params.clear === 'no' || params.clear === 'off') - ) { - query.clear = false; - } else { - query.clear = !!params.clear; - } - } - - if (typeof params.http !== 'undefined') { - if (params.http.toLowerCase && (params.http = params.http.toLowerCase()) - && (params.http === 'no' || params.http === 'off') - ) { - query.http = false; - } else { - query.http = !!params.http; - } - } - - if (typeof params.jvm !== 'undefined') { - if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase()) - && (params.jvm === 'no' || params.jvm === 'off') - ) { - query.jvm = false; - } else { - query.jvm = !!params.jvm; - } - } - - if (typeof params.network !== 'undefined') { - if (params.network.toLowerCase && (params.network = params.network.toLowerCase()) - && (params.network === 'no' || params.network === 'off') - ) { - query.network = false; - } else { - query.network = !!params.network; - } - } - - if (typeof params.os !== 'undefined') { - if (params.os.toLowerCase && (params.os = params.os.toLowerCase()) - && (params.os === 'no' || params.os === 'off') - ) { - query.os = false; - } else { - query.os = !!params.os; - } - } - - if (typeof params.plugin !== 'undefined') { - if (params.plugin.toLowerCase && (params.plugin = params.plugin.toLowerCase()) - && (params.plugin === 'no' || params.plugin === 'off') - ) { - query.plugin = false; - } else { - query.plugin = !!params.plugin; - } - } - - if (typeof params.process !== 'undefined') { - if (params.process.toLowerCase && (params.process = params.process.toLowerCase()) - && (params.process === 'no' || params.process === 'off') - ) { - query.process = false; - } else { - query.process = !!params.process; - } - } - - if (typeof params.settings !== 'undefined') { - if (params.settings.toLowerCase && (params.settings = params.settings.toLowerCase()) - && (params.settings === 'no' || params.settings === 'off') - ) { - query.settings = false; - } else { - query.settings = !!params.settings; - } - } - - if (typeof params.thread_pool !== 'undefined') { - if (params.thread_pool.toLowerCase && (params.thread_pool = params.thread_pool.toLowerCase()) - && (params.thread_pool === 'no' || params.thread_pool === 'off') - ) { - query.thread_pool = false; - } else { - query.thread_pool = !!params.thread_pool; - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.transport !== 'undefined') { - if (params.transport.toLowerCase && (params.transport = params.transport.toLowerCase()) - && (params.transport === 'no' || params.transport === 'off') - ) { - query.transport = false; - } else { - query.transport = !!params.transport; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterNodeInfo; diff --git a/src/api/cluster/node_shutdown.js b/src/api/cluster/node_shutdown.js deleted file mode 100644 index 07a624595..000000000 --- a/src/api/cluster/node_shutdown.js +++ /dev/null @@ -1,86 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request - * - * @for Client - * @method cluster.node_shutdown - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.delay - Set the delay for the operation (default: 1s) - * @param {boolean} params.exit - Exit the JVM as well (default: true) - */ -function doClusterNodeShutdown(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.node_id !== 'undefined') { - switch (typeof params.node_id) { - case 'string': - parts.node_id = params.node_id; - break; - case 'object': - if (_.isArray(params.node_id)) { - parts.node_id = params.node_id.join(','); - } else { - throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.node_id = !!params.node_id; - } - } - - - // build the path - if (parts.hasOwnProperty('node_id')) { - request.path = '/_cluster/nodes/' + encodeURIComponent(parts.node_id) + '/_shutdown'; - } - else { - request.path = '/_shutdown'; - } - - - // build the query string - if (typeof params.delay !== 'undefined') { - if (params.delay instanceof Date) { - query.delay = params.delay.getTime(); - } else if (_.isNumeric(params.delay)) { - query.delay = params.delay; - } else { - throw new TypeError('Invalid delay: ' + params.delay + ' should be be some sort of time.'); - } - } - - if (typeof params.exit !== 'undefined') { - if (params.exit.toLowerCase && (params.exit = params.exit.toLowerCase()) - && (params.exit === 'no' || params.exit === 'off') - ) { - query.exit = false; - } else { - query.exit = !!params.exit; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterNodeShutdown; diff --git a/src/api/cluster/node_stats.js b/src/api/cluster/node_stats.js deleted file mode 100644 index 42c76d64c..000000000 --- a/src/api/cluster/node_stats.js +++ /dev/null @@ -1,245 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var metricFamilyOptions = ['all', 'fs', 'http', 'indices', 'jvm', 'network', 'os', 'process', 'thread_pool', 'transport']; -var metricOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'id_cache', 'indexing', 'merges', 'refresh', 'search', 'store', 'warmer']; - -/** - * Perform an elasticsearch [cluster.node_stats](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/) request - * - * @for Client - * @method cluster.node_stats - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.all - Return all available information - * @param {boolean} params.clear - Reset the default level of detail - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields for `fielddata` metric (supports wildcards) - * @param {boolean} params.fs - Return information about the filesystem - * @param {boolean} params.http - Return information about HTTP - * @param {boolean} params.indices - Return information about indices - * @param {boolean} params.jvm - Return information about the JVM - * @param {boolean} params.network - Return information about network - * @param {boolean} params.os - Return information about the operating system - * @param {boolean} params.process - Return information about the Elasticsearch process - * @param {boolean} params.thread_pool - Return information about the thread pool - * @param {boolean} params.transport - Return information about transport - */ -function doClusterNodeStats(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - parts.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - parts.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.fields = !!params.fields; - } - } - - if (typeof params.metric_family !== 'undefined') { - if (_.contains(metricFamilyOptions, params.metric_family)) { - parts.metric_family = params.metric_family; - } else { - throw new TypeError( - 'Invalid metric_family: ' + params.metric_family + - ' should be one of ' + metricFamilyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.metric !== 'undefined') { - if (_.contains(metricOptions, params.metric)) { - parts.metric = params.metric; - } else { - throw new TypeError( - 'Invalid metric: ' + params.metric + - ' should be one of ' + metricOptions.join(', ') + '.' - ); - } - } - - if (typeof params.node_id !== 'undefined') { - switch (typeof params.node_id) { - case 'string': - parts.node_id = params.node_id; - break; - case 'object': - if (_.isArray(params.node_id)) { - parts.node_id = params.node_id.join(','); - } else { - throw new TypeError('Invalid node_id: ' + params.node_id + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.node_id = !!params.node_id; - } - } - - - // build the path - if (parts.hasOwnProperty('node_id')) { - request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/stats'; - } - else { - request.path = '/_nodes/stats'; - } - - - // build the query string - if (typeof params.all !== 'undefined') { - if (params.all.toLowerCase && (params.all = params.all.toLowerCase()) - && (params.all === 'no' || params.all === 'off') - ) { - query.all = false; - } else { - query.all = !!params.all; - } - } - - if (typeof params.clear !== 'undefined') { - if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase()) - && (params.clear === 'no' || params.clear === 'off') - ) { - query.clear = false; - } else { - query.clear = !!params.clear; - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.fs !== 'undefined') { - if (params.fs.toLowerCase && (params.fs = params.fs.toLowerCase()) - && (params.fs === 'no' || params.fs === 'off') - ) { - query.fs = false; - } else { - query.fs = !!params.fs; - } - } - - if (typeof params.http !== 'undefined') { - if (params.http.toLowerCase && (params.http = params.http.toLowerCase()) - && (params.http === 'no' || params.http === 'off') - ) { - query.http = false; - } else { - query.http = !!params.http; - } - } - - if (typeof params.indices !== 'undefined') { - if (params.indices.toLowerCase && (params.indices = params.indices.toLowerCase()) - && (params.indices === 'no' || params.indices === 'off') - ) { - query.indices = false; - } else { - query.indices = !!params.indices; - } - } - - if (typeof params.jvm !== 'undefined') { - if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase()) - && (params.jvm === 'no' || params.jvm === 'off') - ) { - query.jvm = false; - } else { - query.jvm = !!params.jvm; - } - } - - if (typeof params.network !== 'undefined') { - if (params.network.toLowerCase && (params.network = params.network.toLowerCase()) - && (params.network === 'no' || params.network === 'off') - ) { - query.network = false; - } else { - query.network = !!params.network; - } - } - - if (typeof params.os !== 'undefined') { - if (params.os.toLowerCase && (params.os = params.os.toLowerCase()) - && (params.os === 'no' || params.os === 'off') - ) { - query.os = false; - } else { - query.os = !!params.os; - } - } - - if (typeof params.process !== 'undefined') { - if (params.process.toLowerCase && (params.process = params.process.toLowerCase()) - && (params.process === 'no' || params.process === 'off') - ) { - query.process = false; - } else { - query.process = !!params.process; - } - } - - if (typeof params.thread_pool !== 'undefined') { - if (params.thread_pool.toLowerCase && (params.thread_pool = params.thread_pool.toLowerCase()) - && (params.thread_pool === 'no' || params.thread_pool === 'off') - ) { - query.thread_pool = false; - } else { - query.thread_pool = !!params.thread_pool; - } - } - - if (typeof params.transport !== 'undefined') { - if (params.transport.toLowerCase && (params.transport = params.transport.toLowerCase()) - && (params.transport === 'no' || params.transport === 'off') - ) { - query.transport = false; - } else { - query.transport = !!params.transport; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterNodeStats; diff --git a/src/api/cluster/put_settings.js b/src/api/cluster/put_settings.js deleted file mode 100644 index 530db9dbd..000000000 --- a/src/api/cluster/put_settings.js +++ /dev/null @@ -1,45 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.put_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request - * - * @for Client - * @method cluster.put_settings - * @param {Object} params - An object with parameters used to carry out this action - */ -function doClusterPutSettings(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'PUT' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - - - // build the path - request.path = '/_cluster/settings'; - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterPutSettings; diff --git a/src/api/cluster/reroute.js b/src/api/cluster/reroute.js deleted file mode 100644 index cc45ad2e0..000000000 --- a/src/api/cluster/reroute.js +++ /dev/null @@ -1,66 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.reroute](http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/) request - * - * @for Client - * @method cluster.reroute - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.dry_run - Simulate the operation only and return the resulting state - * @param {boolean} params.filter_metadata - Don't return cluster state metadata (default: false) - */ -function doClusterReroute(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - - - // build the path - request.path = '/_cluster/reroute'; - - - // build the query string - if (typeof params.dry_run !== 'undefined') { - if (params.dry_run.toLowerCase && (params.dry_run = params.dry_run.toLowerCase()) - && (params.dry_run === 'no' || params.dry_run === 'off') - ) { - query.dry_run = false; - } else { - query.dry_run = !!params.dry_run; - } - } - - if (typeof params.filter_metadata !== 'undefined') { - if (params.filter_metadata.toLowerCase && (params.filter_metadata = params.filter_metadata.toLowerCase()) - && (params.filter_metadata === 'no' || params.filter_metadata === 'off') - ) { - query.filter_metadata = false; - } else { - query.filter_metadata = !!params.filter_metadata; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterReroute; diff --git a/src/api/cluster/state.js b/src/api/cluster/state.js deleted file mode 100644 index 3c26e2e17..000000000 --- a/src/api/cluster/state.js +++ /dev/null @@ -1,138 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [cluster.state](http://elasticsearch.org/guide/reference/api/admin-cluster-state/) request - * - * @for Client - * @method cluster.state - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.filter_blocks - Do not return information about blocks - * @param {boolean} params.filter_index_templates - Do not return information about index templates - * @param {String|ArrayOfStrings|Boolean} params.filter_indices - Limit returned metadata information to specific indices - * @param {boolean} params.filter_metadata - Do not return information about indices metadata - * @param {boolean} params.filter_nodes - Do not return information about nodes - * @param {boolean} params.filter_routing_table - Do not return information about shard allocation (`routing_table` and `routing_nodes`) - * @param {boolean} params.local - Return local information, do not retrieve the state from master node (default: false) - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doClusterState(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - - - // build the path - request.path = '/_cluster/state'; - - - // build the query string - if (typeof params.filter_blocks !== 'undefined') { - if (params.filter_blocks.toLowerCase && (params.filter_blocks = params.filter_blocks.toLowerCase()) - && (params.filter_blocks === 'no' || params.filter_blocks === 'off') - ) { - query.filter_blocks = false; - } else { - query.filter_blocks = !!params.filter_blocks; - } - } - - if (typeof params.filter_index_templates !== 'undefined') { - if (params.filter_index_templates.toLowerCase && (params.filter_index_templates = params.filter_index_templates.toLowerCase()) - && (params.filter_index_templates === 'no' || params.filter_index_templates === 'off') - ) { - query.filter_index_templates = false; - } else { - query.filter_index_templates = !!params.filter_index_templates; - } - } - - if (typeof params.filter_indices !== 'undefined') { - switch (typeof params.filter_indices) { - case 'string': - query.filter_indices = params.filter_indices; - break; - case 'object': - if (_.isArray(params.filter_indices)) { - query.filter_indices = params.filter_indices.join(','); - } else { - throw new TypeError('Invalid filter_indices: ' + params.filter_indices + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.filter_indices = !!params.filter_indices; - } - } - - if (typeof params.filter_metadata !== 'undefined') { - if (params.filter_metadata.toLowerCase && (params.filter_metadata = params.filter_metadata.toLowerCase()) - && (params.filter_metadata === 'no' || params.filter_metadata === 'off') - ) { - query.filter_metadata = false; - } else { - query.filter_metadata = !!params.filter_metadata; - } - } - - if (typeof params.filter_nodes !== 'undefined') { - if (params.filter_nodes.toLowerCase && (params.filter_nodes = params.filter_nodes.toLowerCase()) - && (params.filter_nodes === 'no' || params.filter_nodes === 'off') - ) { - query.filter_nodes = false; - } else { - query.filter_nodes = !!params.filter_nodes; - } - } - - if (typeof params.filter_routing_table !== 'undefined') { - if (params.filter_routing_table.toLowerCase && (params.filter_routing_table = params.filter_routing_table.toLowerCase()) - && (params.filter_routing_table === 'no' || params.filter_routing_table === 'off') - ) { - query.filter_routing_table = false; - } else { - query.filter_routing_table = !!params.filter_routing_table; - } - } - - if (typeof params.local !== 'undefined') { - if (params.local.toLowerCase && (params.local = params.local.toLowerCase()) - && (params.local === 'no' || params.local === 'off') - ) { - query.local = false; - } else { - query.local = !!params.local; - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doClusterState; diff --git a/src/api/count.js b/src/api/count.js deleted file mode 100644 index 5e7b062de..000000000 --- a/src/api/count.js +++ /dev/null @@ -1,144 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [count](http://elasticsearch.org/guide/reference/api/count/) request - * - * @for Client - * @method count - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {number} params.min_score - Include only documents with a specific `_score` value in the result - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {string} params.routing - Specific routing value - * @param {string} params.source - The URL-encoded query definition (instead of using the request body) - */ -function doCount(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_count'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_count'; - } - else { - request.path = '/_count'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.min_score !== 'undefined') { - if (_.isNumeric(params.min_score)) { - query.min_score = params.min_score * 1; - } else { - throw new TypeError('Invalid min_score: ' + params.min_score + ' should be a number.'); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doCount; diff --git a/src/api/create.js b/src/api/create.js deleted file mode 100644 index 91a797e29..000000000 --- a/src/api/create.js +++ /dev/null @@ -1,208 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var replicationOptions = ['sync', 'async']; -var versionTypeOptions = ['internal', 'external']; - -/** - * Perform an elasticsearch [create](http://elasticsearch.org/guide/reference/api/index_/) request - * - * @for Client - * @method create - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.consistency - Explicit write consistency setting for the operation - * @param {string} params.id - Specific document ID (when the POST method is used) - * @param {string} params.parent - ID of the parent document - * @param {string} params.percolate - Percolator queries to execute while indexing the document - * @param {boolean} params.refresh - Refresh the index after performing the operation - * @param {String} [params.replication=sync] - Specific replication type - * @param {string} params.routing - Specific routing value - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.timestamp - Explicit timestamp for the document - * @param {duration} params.ttl - Expiration time for the document - * @param {number} params.version - Explicit version number for concurrency control - * @param {String} params.version_type - Specific version type - */ -function doCreate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'PUT') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, PUT'); - } - } else { - request.method = 'POST'; - } - - // find the paths's params - if (typeof params.id !== 'undefined') { - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_create'; - delete params.id; - } - else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.id !== 'undefined') { - if (typeof params.id !== 'object' && params.id) { - query.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.percolate !== 'undefined') { - if (typeof params.percolate !== 'object' && params.percolate) { - query.percolate = '' + params.percolate; - } else { - throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.'); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.timestamp !== 'undefined') { - if (params.timestamp instanceof Date) { - query.timestamp = params.timestamp.getTime(); - } else if (_.isNumeric(params.timestamp)) { - query.timestamp = params.timestamp; - } else { - throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.'); - } - } - - if (typeof params.ttl !== 'undefined') { - if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) { - query.ttl = params.ttl; - } else { - throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).'); - } - } - - if (typeof params.version !== 'undefined') { - if (_.isNumeric(params.version)) { - query.version = params.version * 1; - } else { - throw new TypeError('Invalid version: ' + params.version + ' should be a number.'); - } - } - - if (typeof params.version_type !== 'undefined') { - if (_.contains(versionTypeOptions, params.version_type)) { - query.version_type = params.version_type; - } else { - throw new TypeError( - 'Invalid version_type: ' + params.version_type + - ' should be one of ' + versionTypeOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doCreate; diff --git a/src/api/delete.js b/src/api/delete.js deleted file mode 100644 index 8db80f0f5..000000000 --- a/src/api/delete.js +++ /dev/null @@ -1,154 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var replicationOptions = ['sync', 'async']; -var versionTypeOptions = ['internal', 'external']; - -/** - * Perform an elasticsearch [delete](http://elasticsearch.org/guide/reference/api/delete/) request - * - * @for Client - * @method delete - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.consistency - Specific write consistency setting for the operation - * @param {string} params.parent - ID of parent document - * @param {boolean} params.refresh - Refresh the index after performing the operation - * @param {String} [params.replication=sync] - Specific replication type - * @param {string} params.routing - Specific routing value - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {number} params.version - Explicit version number for concurrency control - * @param {String} params.version_type - Specific version type - */ -function doDelete(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.version !== 'undefined') { - if (_.isNumeric(params.version)) { - query.version = params.version * 1; - } else { - throw new TypeError('Invalid version: ' + params.version + ' should be a number.'); - } - } - - if (typeof params.version_type !== 'undefined') { - if (_.contains(versionTypeOptions, params.version_type)) { - query.version_type = params.version_type; - } else { - throw new TypeError( - 'Invalid version_type: ' + params.version_type + - ' should be one of ' + versionTypeOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doDelete; diff --git a/src/api/delete_by_query.js b/src/api/delete_by_query.js deleted file mode 100644 index b445bd7e3..000000000 --- a/src/api/delete_by_query.js +++ /dev/null @@ -1,192 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var defaultOperatorOptions = ['AND', 'OR']; -var ignoreIndicesOptions = ['none', 'missing']; -var replicationOptions = ['sync', 'async']; - -/** - * Perform an elasticsearch [delete_by_query](http://www.elasticsearch.org/guide/reference/api/delete-by-query/) request - * - * @for Client - * @method delete_by_query - * @param {Object} params - An object with parameters used to carry out this action - * @param {string} params.analyzer - The analyzer to use for the query string - * @param {String} params.consistency - Specific write consistency setting for the operation - * @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR) - * @param {string} params.df - The field to use as default where no field prefix is given in the query string - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {String} [params.replication=sync] - Specific replication type - * @param {string} params.q - Query in the Lucene query string syntax - * @param {string} params.routing - Specific routing value - * @param {string} params.source - The URL-encoded query definition (instead of using the request body) - * @param {Date|Number} params.timeout - Explicit operation timeout - */ -function doDeleteByQuery(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_query'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_query'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.analyzer !== 'undefined') { - if (typeof params.analyzer !== 'object' && params.analyzer) { - query.analyzer = '' + params.analyzer; - } else { - throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.'); - } - } - - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.default_operator !== 'undefined') { - if (_.contains(defaultOperatorOptions, params.default_operator)) { - query.default_operator = params.default_operator; - } else { - throw new TypeError( - 'Invalid default_operator: ' + params.default_operator + - ' should be one of ' + defaultOperatorOptions.join(', ') + '.' - ); - } - } - - if (typeof params.df !== 'undefined') { - if (typeof params.df !== 'object' && params.df) { - query.df = '' + params.df; - } else { - throw new TypeError('Invalid df: ' + params.df + ' should be a string.'); - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.q !== 'undefined') { - if (typeof params.q !== 'object' && params.q) { - query.q = '' + params.q; - } else { - throw new TypeError('Invalid q: ' + params.q + ' should be a string.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doDeleteByQuery; diff --git a/src/api/exists.js b/src/api/exists.js deleted file mode 100644 index 65630503c..000000000 --- a/src/api/exists.js +++ /dev/null @@ -1,122 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [exists](http://elasticsearch.org/guide/reference/api/get/) request - * - * @for Client - * @method exists - * @param {Object} params - An object with parameters used to carry out this action - * @param {string} params.parent - The ID of the parent document - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode - * @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation - * @param {string} params.routing - Specific routing value - */ -function doExists(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: _.union([404], params.ignore), - method: 'HEAD' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.realtime !== 'undefined') { - if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase()) - && (params.realtime === 'no' || params.realtime === 'off') - ) { - query.realtime = false; - } else { - query.realtime = !!params.realtime; - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, function (err, response) { - if (err instanceof errors.NotFound) { - cb(err, false); - } else { - cb(err, true); - } - }); -} - -module.exports = doExists; diff --git a/src/api/explain.js b/src/api/explain.js deleted file mode 100644 index 2ccd71b3a..000000000 --- a/src/api/explain.js +++ /dev/null @@ -1,257 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var defaultOperatorOptions = ['AND', 'OR']; - -/** - * Perform an elasticsearch [explain](http://elasticsearch.org/guide/reference/api/explain/) request - * - * @for Client - * @method explain - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.analyze_wildcard - Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false) - * @param {string} params.analyzer - The analyzer for the query string query - * @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR) - * @param {string} params.df - The default field for query string query (default: _all) - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response - * @param {boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored - * @param {boolean} params.lowercase_expanded_terms - Specify whether query terms should be lowercased - * @param {string} params.parent - The ID of the parent document - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {string} params.q - Query in the Lucene query string syntax - * @param {string} params.routing - Specific routing value - * @param {string} params.source - The URL-encoded query definition (instead of using the request body) - * @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return - * @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field - * @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field - */ -function doExplain(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_explain'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.analyze_wildcard !== 'undefined') { - if (params.analyze_wildcard.toLowerCase && (params.analyze_wildcard = params.analyze_wildcard.toLowerCase()) - && (params.analyze_wildcard === 'no' || params.analyze_wildcard === 'off') - ) { - query.analyze_wildcard = false; - } else { - query.analyze_wildcard = !!params.analyze_wildcard; - } - } - - if (typeof params.analyzer !== 'undefined') { - if (typeof params.analyzer !== 'object' && params.analyzer) { - query.analyzer = '' + params.analyzer; - } else { - throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.'); - } - } - - if (typeof params.default_operator !== 'undefined') { - if (_.contains(defaultOperatorOptions, params.default_operator)) { - query.default_operator = params.default_operator; - } else { - throw new TypeError( - 'Invalid default_operator: ' + params.default_operator + - ' should be one of ' + defaultOperatorOptions.join(', ') + '.' - ); - } - } - - if (typeof params.df !== 'undefined') { - if (typeof params.df !== 'object' && params.df) { - query.df = '' + params.df; - } else { - throw new TypeError('Invalid df: ' + params.df + ' should be a string.'); - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.lenient !== 'undefined') { - if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase()) - && (params.lenient === 'no' || params.lenient === 'off') - ) { - query.lenient = false; - } else { - query.lenient = !!params.lenient; - } - } - - if (typeof params.lowercase_expanded_terms !== 'undefined') { - if (params.lowercase_expanded_terms.toLowerCase && (params.lowercase_expanded_terms = params.lowercase_expanded_terms.toLowerCase()) - && (params.lowercase_expanded_terms === 'no' || params.lowercase_expanded_terms === 'off') - ) { - query.lowercase_expanded_terms = false; - } else { - query.lowercase_expanded_terms = !!params.lowercase_expanded_terms; - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.q !== 'undefined') { - if (typeof params.q !== 'object' && params.q) { - query.q = '' + params.q; - } else { - throw new TypeError('Invalid q: ' + params.q + ' should be a string.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - if (typeof params._source !== 'undefined') { - switch (typeof params._source) { - case 'string': - query._source = params._source; - break; - case 'object': - if (_.isArray(params._source)) { - query._source = params._source.join(','); - } else { - throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source = !!params._source; - } - } - - if (typeof params._source_exclude !== 'undefined') { - switch (typeof params._source_exclude) { - case 'string': - query._source_exclude = params._source_exclude; - break; - case 'object': - if (_.isArray(params._source_exclude)) { - query._source_exclude = params._source_exclude.join(','); - } else { - throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_exclude = !!params._source_exclude; - } - } - - if (typeof params._source_include !== 'undefined') { - switch (typeof params._source_include) { - case 'string': - query._source_include = params._source_include; - break; - case 'object': - if (_.isArray(params._source_include)) { - query._source_include = params._source_include.join(','); - } else { - throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_include = !!params._source_include; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doExplain; diff --git a/src/api/get.js b/src/api/get.js deleted file mode 100644 index 1bfbb6af9..000000000 --- a/src/api/get.js +++ /dev/null @@ -1,188 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [get](http://elasticsearch.org/guide/reference/api/get/) request - * - * @for Client - * @method get - * @param {Object} params - An object with parameters used to carry out this action - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response - * @param {string} params.parent - The ID of the parent document - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode - * @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation - * @param {string} params.routing - Specific routing value - * @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return - * @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field - * @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field - */ -function doGet(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.realtime !== 'undefined') { - if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase()) - && (params.realtime === 'no' || params.realtime === 'off') - ) { - query.realtime = false; - } else { - query.realtime = !!params.realtime; - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params._source !== 'undefined') { - switch (typeof params._source) { - case 'string': - query._source = params._source; - break; - case 'object': - if (_.isArray(params._source)) { - query._source = params._source.join(','); - } else { - throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source = !!params._source; - } - } - - if (typeof params._source_exclude !== 'undefined') { - switch (typeof params._source_exclude) { - case 'string': - query._source_exclude = params._source_exclude; - break; - case 'object': - if (_.isArray(params._source_exclude)) { - query._source_exclude = params._source_exclude.join(','); - } else { - throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_exclude = !!params._source_exclude; - } - } - - if (typeof params._source_include !== 'undefined') { - switch (typeof params._source_include) { - case 'string': - query._source_include = params._source_include; - break; - case 'object': - if (_.isArray(params._source_include)) { - query._source_include = params._source_include.join(','); - } else { - throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_include = !!params._source_include; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doGet; diff --git a/src/api/get_source.js b/src/api/get_source.js deleted file mode 100644 index 510752564..000000000 --- a/src/api/get_source.js +++ /dev/null @@ -1,152 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [get_source](http://elasticsearch.org/guide/reference/api/get/) request - * - * @for Client - * @method get_source - * @param {Object} params - An object with parameters used to carry out this action - * @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field - * @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field - * @param {string} params.parent - The ID of the parent document - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode - * @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation - * @param {string} params.routing - Specific routing value - */ -function doGetSource(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type || '_all') + '/' + encodeURIComponent(parts.id) + '/_source'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params._source_exclude !== 'undefined') { - switch (typeof params._source_exclude) { - case 'string': - query._source_exclude = params._source_exclude; - break; - case 'object': - if (_.isArray(params._source_exclude)) { - query._source_exclude = params._source_exclude.join(','); - } else { - throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_exclude = !!params._source_exclude; - } - } - - if (typeof params._source_include !== 'undefined') { - switch (typeof params._source_include) { - case 'string': - query._source_include = params._source_include; - break; - case 'object': - if (_.isArray(params._source_include)) { - query._source_include = params._source_include.join(','); - } else { - throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_include = !!params._source_include; - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.realtime !== 'undefined') { - if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase()) - && (params.realtime === 'no' || params.realtime === 'off') - ) { - query.realtime = false; - } else { - query.realtime = !!params.realtime; - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doGetSource; diff --git a/src/api/index.js b/src/api/index.js deleted file mode 100644 index b3a531d17..000000000 --- a/src/api/index.js +++ /dev/null @@ -1,211 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var opTypeOptions = ['index', 'create']; -var replicationOptions = ['sync', 'async']; -var versionTypeOptions = ['internal', 'external']; - -/** - * Perform an elasticsearch [index](http://elasticsearch.org/guide/reference/api/index_/) request - * - * @for Client - * @method index - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.consistency - Explicit write consistency setting for the operation - * @param {String} [params.op_type=index] - Explicit operation type - * @param {string} params.parent - ID of the parent document - * @param {string} params.percolate - Percolator queries to execute while indexing the document - * @param {boolean} params.refresh - Refresh the index after performing the operation - * @param {String} [params.replication=sync] - Specific replication type - * @param {string} params.routing - Specific routing value - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.timestamp - Explicit timestamp for the document - * @param {duration} params.ttl - Expiration time for the document - * @param {number} params.version - Explicit version number for concurrency control - * @param {String} params.version_type - Specific version type - */ -function doIndex(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'PUT') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, PUT'); - } - } else { - request.method = 'POST'; - } - - // find the paths's params - if (typeof params.id !== 'undefined') { - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + ''; - } - else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.op_type !== 'undefined') { - if (_.contains(opTypeOptions, params.op_type)) { - query.op_type = params.op_type; - } else { - throw new TypeError( - 'Invalid op_type: ' + params.op_type + - ' should be one of ' + opTypeOptions.join(', ') + '.' - ); - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.percolate !== 'undefined') { - if (typeof params.percolate !== 'object' && params.percolate) { - query.percolate = '' + params.percolate; - } else { - throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.'); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.timestamp !== 'undefined') { - if (params.timestamp instanceof Date) { - query.timestamp = params.timestamp.getTime(); - } else if (_.isNumeric(params.timestamp)) { - query.timestamp = params.timestamp; - } else { - throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.'); - } - } - - if (typeof params.ttl !== 'undefined') { - if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) { - query.ttl = params.ttl; - } else { - throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).'); - } - } - - if (typeof params.version !== 'undefined') { - if (_.isNumeric(params.version)) { - query.version = params.version * 1; - } else { - throw new TypeError('Invalid version: ' + params.version + ' should be a number.'); - } - } - - if (typeof params.version_type !== 'undefined') { - if (_.contains(versionTypeOptions, params.version_type)) { - query.version_type = params.version_type; - } else { - throw new TypeError( - 'Invalid version_type: ' + params.version_type + - ' should be one of ' + versionTypeOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndex; diff --git a/src/api/indices/analyze.js b/src/api/indices/analyze.js deleted file mode 100644 index 5355d8b30..000000000 --- a/src/api/indices/analyze.js +++ /dev/null @@ -1,154 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var formatOptions = ['detailed', 'text']; - -/** - * Perform an elasticsearch [indices.analyze](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/) request - * - * @for Client - * @method indices.analyze - * @param {Object} params - An object with parameters used to carry out this action - * @param {string} params.analyzer - The name of the analyzer to use - * @param {string} params.field - Use the analyzer configured for this field (instead of passing the analyzer name) - * @param {String|ArrayOfStrings|Boolean} params.filters - A comma-separated list of filters to use for the analysis - * @param {string} params.index - The name of the index to scope the operation - * @param {boolean} params.prefer_local - With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true) - * @param {string} params.text - The text on which the analysis should be performed (when request body is not used) - * @param {string} params.tokenizer - The name of the tokenizer to use for the analysis - * @param {String} [params.format=detailed] - Format of the output - */ -function doIndicesAnalyze(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_analyze'; - delete params.index; - } - else { - request.path = '/_analyze'; - } - - - // build the query string - if (typeof params.analyzer !== 'undefined') { - if (typeof params.analyzer !== 'object' && params.analyzer) { - query.analyzer = '' + params.analyzer; - } else { - throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.'); - } - } - - if (typeof params.field !== 'undefined') { - if (typeof params.field !== 'object' && params.field) { - query.field = '' + params.field; - } else { - throw new TypeError('Invalid field: ' + params.field + ' should be a string.'); - } - } - - if (typeof params.filters !== 'undefined') { - switch (typeof params.filters) { - case 'string': - query.filters = params.filters; - break; - case 'object': - if (_.isArray(params.filters)) { - query.filters = params.filters.join(','); - } else { - throw new TypeError('Invalid filters: ' + params.filters + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.filters = !!params.filters; - } - } - - if (typeof params.index !== 'undefined') { - if (typeof params.index !== 'object' && params.index) { - query.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - } - - if (typeof params.prefer_local !== 'undefined') { - if (params.prefer_local.toLowerCase && (params.prefer_local = params.prefer_local.toLowerCase()) - && (params.prefer_local === 'no' || params.prefer_local === 'off') - ) { - query.prefer_local = false; - } else { - query.prefer_local = !!params.prefer_local; - } - } - - if (typeof params.text !== 'undefined') { - if (typeof params.text !== 'object' && params.text) { - query.text = '' + params.text; - } else { - throw new TypeError('Invalid text: ' + params.text + ' should be a string.'); - } - } - - if (typeof params.tokenizer !== 'undefined') { - if (typeof params.tokenizer !== 'object' && params.tokenizer) { - query.tokenizer = '' + params.tokenizer; - } else { - throw new TypeError('Invalid tokenizer: ' + params.tokenizer + ' should be a string.'); - } - } - - if (typeof params.format !== 'undefined') { - if (_.contains(formatOptions, params.format)) { - query.format = params.format; - } else { - throw new TypeError( - 'Invalid format: ' + params.format + - ' should be one of ' + formatOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesAnalyze; diff --git a/src/api/indices/clear_cache.js b/src/api/indices/clear_cache.js deleted file mode 100644 index 57e34b1d6..000000000 --- a/src/api/indices/clear_cache.js +++ /dev/null @@ -1,212 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.clear_cache](http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/) request - * - * @for Client - * @method indices.clear_cache - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.field_data - Clear field data - * @param {boolean} params.fielddata - Clear field data - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to clear when using the `field_data` parameter (default: all) - * @param {boolean} params.filter - Clear filter caches - * @param {boolean} params.filter_cache - Clear filter caches - * @param {boolean} params.filter_keys - A comma-separated list of keys to clear when using the `filter_cache` parameter (default: all) - * @param {boolean} params.id - Clear ID caches for parent/child - * @param {boolean} params.id_cache - Clear ID caches for parent/child - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {String|ArrayOfStrings|Boolean} params.index - A comma-separated list of index name to limit the operation - * @param {boolean} params.recycler - Clear the recycler cache - */ -function doIndicesClearCache(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_cache/clear'; - delete params.index; - } - else { - request.path = '/_cache/clear'; - } - - - // build the query string - if (typeof params.field_data !== 'undefined') { - if (params.field_data.toLowerCase && (params.field_data = params.field_data.toLowerCase()) - && (params.field_data === 'no' || params.field_data === 'off') - ) { - query.field_data = false; - } else { - query.field_data = !!params.field_data; - } - } - - if (typeof params.fielddata !== 'undefined') { - if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase()) - && (params.fielddata === 'no' || params.fielddata === 'off') - ) { - query.fielddata = false; - } else { - query.fielddata = !!params.fielddata; - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.filter !== 'undefined') { - if (params.filter.toLowerCase && (params.filter = params.filter.toLowerCase()) - && (params.filter === 'no' || params.filter === 'off') - ) { - query.filter = false; - } else { - query.filter = !!params.filter; - } - } - - if (typeof params.filter_cache !== 'undefined') { - if (params.filter_cache.toLowerCase && (params.filter_cache = params.filter_cache.toLowerCase()) - && (params.filter_cache === 'no' || params.filter_cache === 'off') - ) { - query.filter_cache = false; - } else { - query.filter_cache = !!params.filter_cache; - } - } - - if (typeof params.filter_keys !== 'undefined') { - if (params.filter_keys.toLowerCase && (params.filter_keys = params.filter_keys.toLowerCase()) - && (params.filter_keys === 'no' || params.filter_keys === 'off') - ) { - query.filter_keys = false; - } else { - query.filter_keys = !!params.filter_keys; - } - } - - if (typeof params.id !== 'undefined') { - if (params.id.toLowerCase && (params.id = params.id.toLowerCase()) - && (params.id === 'no' || params.id === 'off') - ) { - query.id = false; - } else { - query.id = !!params.id; - } - } - - if (typeof params.id_cache !== 'undefined') { - if (params.id_cache.toLowerCase && (params.id_cache = params.id_cache.toLowerCase()) - && (params.id_cache === 'no' || params.id_cache === 'off') - ) { - query.id_cache = false; - } else { - query.id_cache = !!params.id_cache; - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - query.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - query.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.index = !!params.index; - } - } - - if (typeof params.recycler !== 'undefined') { - if (params.recycler.toLowerCase && (params.recycler = params.recycler.toLowerCase()) - && (params.recycler === 'no' || params.recycler === 'off') - ) { - query.recycler = false; - } else { - query.recycler = !!params.recycler; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesClearCache; diff --git a/src/api/indices/close.js b/src/api/indices/close.js deleted file mode 100644 index 24774f339..000000000 --- a/src/api/indices/close.js +++ /dev/null @@ -1,75 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request - * - * @for Client - * @method indices.close - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesClose(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_close'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesClose; diff --git a/src/api/indices/create.js b/src/api/indices/create.js deleted file mode 100644 index d1dd8ed50..000000000 --- a/src/api/indices/create.js +++ /dev/null @@ -1,85 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request - * - * @for Client - * @method indices.create - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesCreate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'PUT' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of PUT, POST'); - } - } else { - request.method = 'PUT'; - } - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesCreate; diff --git a/src/api/indices/delete.js b/src/api/indices/delete.js deleted file mode 100644 index b41847c43..000000000 --- a/src/api/indices/delete.js +++ /dev/null @@ -1,86 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request - * - * @for Client - * @method indices.delete - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesDelete(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + ''; - } - else { - request.path = '/'; - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesDelete; diff --git a/src/api/indices/delete_alias.js b/src/api/indices/delete_alias.js deleted file mode 100644 index 8021f4beb..000000000 --- a/src/api/indices/delete_alias.js +++ /dev/null @@ -1,81 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.delete_alias - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit timestamp for the document - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesDeleteAlias(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesDeleteAlias; diff --git a/src/api/indices/delete_mapping.js b/src/api/indices/delete_mapping.js deleted file mode 100644 index a85481796..000000000 --- a/src/api/indices/delete_mapping.js +++ /dev/null @@ -1,79 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.delete_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/) request - * - * @for Client - * @method indices.delete_mapping - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesDeleteMapping(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesDeleteMapping; diff --git a/src/api/indices/delete_template.js b/src/api/indices/delete_template.js deleted file mode 100644 index 74f0c2faa..000000000 --- a/src/api/indices/delete_template.js +++ /dev/null @@ -1,75 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request - * - * @for Client - * @method indices.delete_template - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesDeleteTemplate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('name')) { - request.path = '/_template/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesDeleteTemplate; diff --git a/src/api/indices/delete_warmer.js b/src/api/indices/delete_warmer.js deleted file mode 100644 index d9fbde232..000000000 --- a/src/api/indices/delete_warmer.js +++ /dev/null @@ -1,104 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.delete_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request - * - * @for Client - * @method indices.delete_warmer - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesDeleteWarmer(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'DELETE' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.name !== 'undefined') { - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_warmer'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesDeleteWarmer; diff --git a/src/api/indices/exists.js b/src/api/indices/exists.js deleted file mode 100644 index 5e6031e92..000000000 --- a/src/api/indices/exists.js +++ /dev/null @@ -1,69 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request - * - * @for Client - * @method indices.exists - * @param {Object} params - An object with parameters used to carry out this action - */ -function doIndicesExists(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: _.union([404], params.ignore), - method: 'HEAD' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, function (err, response) { - if (err instanceof errors.NotFound) { - cb(err, false); - } else { - cb(err, true); - } - }); -} - -module.exports = doIndicesExists; diff --git a/src/api/indices/exists_alias.js b/src/api/indices/exists_alias.js deleted file mode 100644 index 5dd1fe25f..000000000 --- a/src/api/indices/exists_alias.js +++ /dev/null @@ -1,102 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.exists_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.exists_alias - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - */ -function doIndicesExistsAlias(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: _.union([404], params.ignore), - method: 'HEAD' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - switch (typeof params.name) { - case 'string': - parts.name = params.name; - break; - case 'object': - if (_.isArray(params.name)) { - parts.name = params.name.join(','); - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.name = !!params.name; - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('name')) { - request.path = '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, function (err, response) { - if (err instanceof errors.NotFound) { - cb(err, false); - } else { - cb(err, true); - } - }); -} - -module.exports = doIndicesExistsAlias; diff --git a/src/api/indices/exists_type.js b/src/api/indices/exists_type.js deleted file mode 100644 index fe3ae8fc4..000000000 --- a/src/api/indices/exists_type.js +++ /dev/null @@ -1,97 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.exists_type](http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/) request - * - * @for Client - * @method indices.exists_type - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - */ -function doIndicesExistsType(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: _.union([404], params.ignore), - method: 'HEAD' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, function (err, response) { - if (err instanceof errors.NotFound) { - cb(err, false); - } else { - cb(err, true); - } - }); -} - -module.exports = doIndicesExistsType; diff --git a/src/api/indices/flush.js b/src/api/indices/flush.js deleted file mode 100644 index a15f27fd9..000000000 --- a/src/api/indices/flush.js +++ /dev/null @@ -1,120 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.flush](http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/) request - * - * @for Client - * @method indices.flush - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.force - TODO: ? - * @param {boolean} params.full - TODO: ? - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {boolean} params.refresh - Refresh the index after performing the operation - */ -function doIndicesFlush(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_flush'; - } - else { - request.path = '/_flush'; - } - - - // build the query string - if (typeof params.force !== 'undefined') { - if (params.force.toLowerCase && (params.force = params.force.toLowerCase()) - && (params.force === 'no' || params.force === 'off') - ) { - query.force = false; - } else { - query.force = !!params.force; - } - } - - if (typeof params.full !== 'undefined') { - if (params.full.toLowerCase && (params.full = params.full.toLowerCase()) - && (params.full === 'no' || params.full === 'off') - ) { - query.full = false; - } else { - query.full = !!params.full; - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesFlush; diff --git a/src/api/indices/get_alias.js b/src/api/indices/get_alias.js deleted file mode 100644 index 8431cc480..000000000 --- a/src/api/indices/get_alias.js +++ /dev/null @@ -1,96 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.get_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.get_alias - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - */ -function doIndicesGetAlias(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - switch (typeof params.name) { - case 'string': - parts.name = params.name; - break; - case 'object': - if (_.isArray(params.name)) { - parts.name = params.name.join(','); - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.name = !!params.name; - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('name')) { - request.path = '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetAlias; diff --git a/src/api/indices/get_aliases.js b/src/api/indices/get_aliases.js deleted file mode 100644 index 76d869a40..000000000 --- a/src/api/indices/get_aliases.js +++ /dev/null @@ -1,75 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.get_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.get_aliases - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - */ -function doIndicesGetAliases(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_aliases'; - } - else { - request.path = '/_aliases'; - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetAliases; diff --git a/src/api/indices/get_mapping.js b/src/api/indices/get_mapping.js deleted file mode 100644 index 4a8016256..000000000 --- a/src/api/indices/get_mapping.js +++ /dev/null @@ -1,85 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.get_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/) request - * - * @for Client - * @method indices.get_mapping - * @param {Object} params - An object with parameters used to carry out this action - */ -function doIndicesGetMapping(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_mapping'; - } - else { - request.path = '/_mapping'; - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetMapping; diff --git a/src/api/indices/get_settings.js b/src/api/indices/get_settings.js deleted file mode 100644 index f5f12a9b7..000000000 --- a/src/api/indices/get_settings.js +++ /dev/null @@ -1,65 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.get_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/) request - * - * @for Client - * @method indices.get_settings - * @param {Object} params - An object with parameters used to carry out this action - */ -function doIndicesGetSettings(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_settings'; - } - else { - request.path = '/_settings'; - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetSettings; diff --git a/src/api/indices/get_template.js b/src/api/indices/get_template.js deleted file mode 100644 index 0a28d6c23..000000000 --- a/src/api/indices/get_template.js +++ /dev/null @@ -1,54 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.get_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request - * - * @for Client - * @method indices.get_template - * @param {Object} params - An object with parameters used to carry out this action - */ -function doIndicesGetTemplate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('name')) { - request.path = '/_template/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetTemplate; diff --git a/src/api/indices/get_warmer.js b/src/api/indices/get_warmer.js deleted file mode 100644 index 6a9d4701c..000000000 --- a/src/api/indices/get_warmer.js +++ /dev/null @@ -1,94 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.get_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request - * - * @for Client - * @method indices.get_warmer - * @param {Object} params - An object with parameters used to carry out this action - */ -function doIndicesGetWarmer(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.name !== 'undefined') { - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_warmer'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesGetWarmer; diff --git a/src/api/indices/open.js b/src/api/indices/open.js deleted file mode 100644 index 9c68020fe..000000000 --- a/src/api/indices/open.js +++ /dev/null @@ -1,75 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request - * - * @for Client - * @method indices.open - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesOpen(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_open'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesOpen; diff --git a/src/api/indices/optimize.js b/src/api/indices/optimize.js deleted file mode 100644 index cdace0938..000000000 --- a/src/api/indices/optimize.js +++ /dev/null @@ -1,145 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.optimize](http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/) request - * - * @for Client - * @method indices.optimize - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.flush - Specify whether the index should be flushed after performing the operation (default: true) - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {number} params.max_num_segments - The number of segments the index should be merged into (default: dynamic) - * @param {boolean} params.only_expunge_deletes - Specify whether the operation should only expunge deleted documents - * @param {*} params.operation_threading - TODO: ? - * @param {boolean} params.refresh - Specify whether the index should be refreshed after performing the operation (default: true) - * @param {boolean} params.wait_for_merge - Specify whether the request should block until the merge process is finished (default: true) - */ -function doIndicesOptimize(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_optimize'; - } - else { - request.path = '/_optimize'; - } - - - // build the query string - if (typeof params.flush !== 'undefined') { - if (params.flush.toLowerCase && (params.flush = params.flush.toLowerCase()) - && (params.flush === 'no' || params.flush === 'off') - ) { - query.flush = false; - } else { - query.flush = !!params.flush; - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.max_num_segments !== 'undefined') { - if (_.isNumeric(params.max_num_segments)) { - query.max_num_segments = params.max_num_segments * 1; - } else { - throw new TypeError('Invalid max_num_segments: ' + params.max_num_segments + ' should be a number.'); - } - } - - if (typeof params.only_expunge_deletes !== 'undefined') { - if (params.only_expunge_deletes.toLowerCase && (params.only_expunge_deletes = params.only_expunge_deletes.toLowerCase()) - && (params.only_expunge_deletes === 'no' || params.only_expunge_deletes === 'off') - ) { - query.only_expunge_deletes = false; - } else { - query.only_expunge_deletes = !!params.only_expunge_deletes; - } - } - - if (typeof params.operation_threading !== 'undefined') { - query.operation_threading = params.operation_threading; - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.wait_for_merge !== 'undefined') { - if (params.wait_for_merge.toLowerCase && (params.wait_for_merge = params.wait_for_merge.toLowerCase()) - && (params.wait_for_merge === 'no' || params.wait_for_merge === 'off') - ) { - query.wait_for_merge = false; - } else { - query.wait_for_merge = !!params.wait_for_merge; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesOptimize; diff --git a/src/api/indices/put_alias.js b/src/api/indices/put_alias.js deleted file mode 100644 index 7984e84f0..000000000 --- a/src/api/indices/put_alias.js +++ /dev/null @@ -1,88 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.put_alias - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Explicit timestamp for the document - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesPutAlias(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'PUT' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('name')) { - request.path = '/_alias/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_alias'; - } - else { - request.path = '/_alias'; - } - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesPutAlias; diff --git a/src/api/indices/put_mapping.js b/src/api/indices/put_mapping.js deleted file mode 100644 index 2ec112c25..000000000 --- a/src/api/indices/put_mapping.js +++ /dev/null @@ -1,111 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.put_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/) request - * - * @for Client - * @method indices.put_mapping - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.ignore_conflicts - Specify whether to ignore conflicts while updating the mapping (default: false) - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesPutMapping(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'PUT' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of PUT, POST'); - } - } else { - request.method = 'PUT'; - } - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.ignore_conflicts !== 'undefined') { - if (params.ignore_conflicts.toLowerCase && (params.ignore_conflicts = params.ignore_conflicts.toLowerCase()) - && (params.ignore_conflicts === 'no' || params.ignore_conflicts === 'off') - ) { - query.ignore_conflicts = false; - } else { - query.ignore_conflicts = !!params.ignore_conflicts; - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesPutMapping; diff --git a/src/api/indices/put_settings.js b/src/api/indices/put_settings.js deleted file mode 100644 index dd3b619ce..000000000 --- a/src/api/indices/put_settings.js +++ /dev/null @@ -1,76 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.put_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/) request - * - * @for Client - * @method indices.put_settings - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesPutSettings(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'PUT' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_settings'; - } - else { - request.path = '/_settings'; - } - - - // build the query string - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesPutSettings; diff --git a/src/api/indices/put_template.js b/src/api/indices/put_template.js deleted file mode 100644 index 8bc45bccd..000000000 --- a/src/api/indices/put_template.js +++ /dev/null @@ -1,94 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request - * - * @for Client - * @method indices.put_template - * @param {Object} params - An object with parameters used to carry out this action - * @param {number} params.order - The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers) - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesPutTemplate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'PUT' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of PUT, POST'); - } - } else { - request.method = 'PUT'; - } - - // find the paths's params - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('name')) { - request.path = '/_template/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object]'); - } - - - // build the query string - if (typeof params.order !== 'undefined') { - if (_.isNumeric(params.order)) { - query.order = params.order * 1; - } else { - throw new TypeError('Invalid order: ' + params.order + ' should be a number.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesPutTemplate; diff --git a/src/api/indices/put_warmer.js b/src/api/indices/put_warmer.js deleted file mode 100644 index 2524d4689..000000000 --- a/src/api/indices/put_warmer.js +++ /dev/null @@ -1,100 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.put_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request - * - * @for Client - * @method indices.put_warmer - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesPutWarmer(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'PUT' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - - if (typeof params.name !== 'object' && params.name) { - parts.name = '' + params.name; - } else { - throw new TypeError('Invalid name: ' + params.name + ' should be a string.'); - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + ''; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesPutWarmer; diff --git a/src/api/indices/refresh.js b/src/api/indices/refresh.js deleted file mode 100644 index 0c0bcd914..000000000 --- a/src/api/indices/refresh.js +++ /dev/null @@ -1,92 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.refresh](http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh/) request - * - * @for Client - * @method indices.refresh - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {*} params.operation_threading - TODO: ? - */ -function doIndicesRefresh(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_refresh'; - } - else { - request.path = '/_refresh'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.operation_threading !== 'undefined') { - query.operation_threading = params.operation_threading; - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesRefresh; diff --git a/src/api/indices/segments.js b/src/api/indices/segments.js deleted file mode 100644 index bba1e05bb..000000000 --- a/src/api/indices/segments.js +++ /dev/null @@ -1,83 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.segments](http://elasticsearch.org/guide/reference/api/admin-indices-segments/) request - * - * @for Client - * @method indices.segments - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {*} params.operation_threading - TODO: ? - */ -function doIndicesSegments(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_segments'; - } - else { - request.path = '/_segments'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.operation_threading !== 'undefined') { - query.operation_threading = params.operation_threading; - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesSegments; diff --git a/src/api/indices/snapshot_index.js b/src/api/indices/snapshot_index.js deleted file mode 100644 index b99db8f54..000000000 --- a/src/api/indices/snapshot_index.js +++ /dev/null @@ -1,78 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.snapshot_index](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/) request - * - * @for Client - * @method indices.snapshot_index - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - */ -function doIndicesSnapshotIndex(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_gateway/snapshot'; - } - else { - request.path = '/_gateway/snapshot'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesSnapshotIndex; diff --git a/src/api/indices/stats.js b/src/api/indices/stats.js deleted file mode 100644 index 6ec6cd5de..000000000 --- a/src/api/indices/stats.js +++ /dev/null @@ -1,371 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; -var metricFamilyOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush', 'get', 'groups', 'id_cache', 'ignore_indices', 'indexing', 'merge', 'refresh', 'search', 'store', 'warmer']; - -/** - * Perform an elasticsearch [indices.stats](http://elasticsearch.org/guide/reference/api/admin-indices-stats/) request - * - * @for Client - * @method indices.stats - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.all - Return all available information - * @param {boolean} params.clear - Reset the default level of detail - * @param {boolean} params.completion - Return information about completion suggester stats - * @param {String|ArrayOfStrings|Boolean} params.completion_fields - A comma-separated list of fields for `completion` metric (supports wildcards) - * @param {boolean} params.docs - Return information about indexed and deleted documents - * @param {boolean} params.fielddata - Return information about field data - * @param {String|ArrayOfStrings|Boolean} params.fielddata_fields - A comma-separated list of fields for `fielddata` metric (supports wildcards) - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields for `fielddata` and `completion` metric (supports wildcards) - * @param {boolean} params.filter_cache - Return information about filter cache - * @param {boolean} params.flush - Return information about flush operations - * @param {boolean} params.get - Return information about get operations - * @param {boolean} params.groups - A comma-separated list of search groups for `search` statistics - * @param {boolean} params.id_cache - Return information about ID cache - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {boolean} params.indexing - Return information about indexing operations - * @param {boolean} params.merge - Return information about merge operations - * @param {boolean} params.refresh - Return information about refresh operations - * @param {boolean} params.search - Return information about search operations; use the `groups` parameter to include information for specific search groups - * @param {boolean} params.store - Return information about the size of the index - * @param {boolean} params.warmer - Return information about warmers - */ -function doIndicesStats(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - parts.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - parts.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.fields = !!params.fields; - } - } - - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.indexing_types !== 'undefined') { - switch (typeof params.indexing_types) { - case 'string': - parts.indexing_types = params.indexing_types; - break; - case 'object': - if (_.isArray(params.indexing_types)) { - parts.indexing_types = params.indexing_types.join(','); - } else { - throw new TypeError('Invalid indexing_types: ' + params.indexing_types + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.indexing_types = !!params.indexing_types; - } - } - - if (typeof params.metric_family !== 'undefined') { - if (_.contains(metricFamilyOptions, params.metric_family)) { - parts.metric_family = params.metric_family; - } else { - throw new TypeError( - 'Invalid metric_family: ' + params.metric_family + - ' should be one of ' + metricFamilyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.search_groups !== 'undefined') { - switch (typeof params.search_groups) { - case 'string': - parts.search_groups = params.search_groups; - break; - case 'object': - if (_.isArray(params.search_groups)) { - parts.search_groups = params.search_groups.join(','); - } else { - throw new TypeError('Invalid search_groups: ' + params.search_groups + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.search_groups = !!params.search_groups; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_stats'; - } - else { - request.path = '/_stats'; - } - - - // build the query string - if (typeof params.all !== 'undefined') { - if (params.all.toLowerCase && (params.all = params.all.toLowerCase()) - && (params.all === 'no' || params.all === 'off') - ) { - query.all = false; - } else { - query.all = !!params.all; - } - } - - if (typeof params.clear !== 'undefined') { - if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase()) - && (params.clear === 'no' || params.clear === 'off') - ) { - query.clear = false; - } else { - query.clear = !!params.clear; - } - } - - if (typeof params.completion !== 'undefined') { - if (params.completion.toLowerCase && (params.completion = params.completion.toLowerCase()) - && (params.completion === 'no' || params.completion === 'off') - ) { - query.completion = false; - } else { - query.completion = !!params.completion; - } - } - - if (typeof params.completion_fields !== 'undefined') { - switch (typeof params.completion_fields) { - case 'string': - query.completion_fields = params.completion_fields; - break; - case 'object': - if (_.isArray(params.completion_fields)) { - query.completion_fields = params.completion_fields.join(','); - } else { - throw new TypeError('Invalid completion_fields: ' + params.completion_fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.completion_fields = !!params.completion_fields; - } - } - - if (typeof params.docs !== 'undefined') { - if (params.docs.toLowerCase && (params.docs = params.docs.toLowerCase()) - && (params.docs === 'no' || params.docs === 'off') - ) { - query.docs = false; - } else { - query.docs = !!params.docs; - } - } - - if (typeof params.fielddata !== 'undefined') { - if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase()) - && (params.fielddata === 'no' || params.fielddata === 'off') - ) { - query.fielddata = false; - } else { - query.fielddata = !!params.fielddata; - } - } - - if (typeof params.fielddata_fields !== 'undefined') { - switch (typeof params.fielddata_fields) { - case 'string': - query.fielddata_fields = params.fielddata_fields; - break; - case 'object': - if (_.isArray(params.fielddata_fields)) { - query.fielddata_fields = params.fielddata_fields.join(','); - } else { - throw new TypeError('Invalid fielddata_fields: ' + params.fielddata_fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fielddata_fields = !!params.fielddata_fields; - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.filter_cache !== 'undefined') { - if (params.filter_cache.toLowerCase && (params.filter_cache = params.filter_cache.toLowerCase()) - && (params.filter_cache === 'no' || params.filter_cache === 'off') - ) { - query.filter_cache = false; - } else { - query.filter_cache = !!params.filter_cache; - } - } - - if (typeof params.flush !== 'undefined') { - if (params.flush.toLowerCase && (params.flush = params.flush.toLowerCase()) - && (params.flush === 'no' || params.flush === 'off') - ) { - query.flush = false; - } else { - query.flush = !!params.flush; - } - } - - if (typeof params.get !== 'undefined') { - if (params.get.toLowerCase && (params.get = params.get.toLowerCase()) - && (params.get === 'no' || params.get === 'off') - ) { - query.get = false; - } else { - query.get = !!params.get; - } - } - - if (typeof params.groups !== 'undefined') { - if (params.groups.toLowerCase && (params.groups = params.groups.toLowerCase()) - && (params.groups === 'no' || params.groups === 'off') - ) { - query.groups = false; - } else { - query.groups = !!params.groups; - } - } - - if (typeof params.id_cache !== 'undefined') { - if (params.id_cache.toLowerCase && (params.id_cache = params.id_cache.toLowerCase()) - && (params.id_cache === 'no' || params.id_cache === 'off') - ) { - query.id_cache = false; - } else { - query.id_cache = !!params.id_cache; - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.indexing !== 'undefined') { - if (params.indexing.toLowerCase && (params.indexing = params.indexing.toLowerCase()) - && (params.indexing === 'no' || params.indexing === 'off') - ) { - query.indexing = false; - } else { - query.indexing = !!params.indexing; - } - } - - if (typeof params.merge !== 'undefined') { - if (params.merge.toLowerCase && (params.merge = params.merge.toLowerCase()) - && (params.merge === 'no' || params.merge === 'off') - ) { - query.merge = false; - } else { - query.merge = !!params.merge; - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.search !== 'undefined') { - if (params.search.toLowerCase && (params.search = params.search.toLowerCase()) - && (params.search === 'no' || params.search === 'off') - ) { - query.search = false; - } else { - query.search = !!params.search; - } - } - - if (typeof params.store !== 'undefined') { - if (params.store.toLowerCase && (params.store = params.store.toLowerCase()) - && (params.store === 'no' || params.store === 'off') - ) { - query.store = false; - } else { - query.store = !!params.store; - } - } - - if (typeof params.warmer !== 'undefined') { - if (params.warmer.toLowerCase && (params.warmer = params.warmer.toLowerCase()) - && (params.warmer === 'no' || params.warmer === 'off') - ) { - query.warmer = false; - } else { - query.warmer = !!params.warmer; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesStats; diff --git a/src/api/indices/status.js b/src/api/indices/status.js deleted file mode 100644 index 90603c9ea..000000000 --- a/src/api/indices/status.js +++ /dev/null @@ -1,105 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.status](http://elasticsearch.org/guide/reference/api/admin-indices-status/) request - * - * @for Client - * @method indices.status - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {*} params.operation_threading - TODO: ? - * @param {boolean} params.recovery - Return information about shard recovery - * @param {boolean} params.snapshot - TODO: ? - */ -function doIndicesStatus(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - method: 'GET' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_status'; - } - else { - request.path = '/_status'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.operation_threading !== 'undefined') { - query.operation_threading = params.operation_threading; - } - - if (typeof params.recovery !== 'undefined') { - if (params.recovery.toLowerCase && (params.recovery = params.recovery.toLowerCase()) - && (params.recovery === 'no' || params.recovery === 'off') - ) { - query.recovery = false; - } else { - query.recovery = !!params.recovery; - } - } - - if (typeof params.snapshot !== 'undefined') { - if (params.snapshot.toLowerCase && (params.snapshot = params.snapshot.toLowerCase()) - && (params.snapshot === 'no' || params.snapshot === 'off') - ) { - query.snapshot = false; - } else { - query.snapshot = !!params.snapshot; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesStatus; diff --git a/src/api/indices/update_aliases.js b/src/api/indices/update_aliases.js deleted file mode 100644 index 6f5d4e1b8..000000000 --- a/src/api/indices/update_aliases.js +++ /dev/null @@ -1,82 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request - * - * @for Client - * @method indices.update_aliases - * @param {Object} params - An object with parameters used to carry out this action - * @param {Date|Number} params.timeout - Request timeout - * @param {Date|Number} params.master_timeout - Specify timeout for connection to master - */ -function doIndicesUpdateAliases(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - request.path = '/_aliases'; - - - // build the query string - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.master_timeout !== 'undefined') { - if (params.master_timeout instanceof Date) { - query.master_timeout = params.master_timeout.getTime(); - } else if (_.isNumeric(params.master_timeout)) { - query.master_timeout = params.master_timeout; - } else { - throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesUpdateAliases; diff --git a/src/api/indices/validate_query.js b/src/api/indices/validate_query.js deleted file mode 100644 index 12de7b6cc..000000000 --- a/src/api/indices/validate_query.js +++ /dev/null @@ -1,142 +0,0 @@ -var _ = require('../../lib/utils'), - errors = require('../../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [indices.validate_query](http://www.elasticsearch.org/guide/reference/api/validate/) request - * - * @for Client - * @method indices.validate_query - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.explain - Return detailed information about the error - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {*} params.operation_threading - TODO: ? - * @param {string} params.source - The URL-encoded query definition (instead of using the request body) - * @param {string} params.q - Query in the Lucene query string syntax - */ -function doIndicesValidateQuery(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_validate/query'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_validate/query'; - } - else { - request.path = '/_validate/query'; - } - - - // build the query string - if (typeof params.explain !== 'undefined') { - if (params.explain.toLowerCase && (params.explain = params.explain.toLowerCase()) - && (params.explain === 'no' || params.explain === 'off') - ) { - query.explain = false; - } else { - query.explain = !!params.explain; - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.operation_threading !== 'undefined') { - query.operation_threading = params.operation_threading; - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - if (typeof params.q !== 'undefined') { - if (typeof params.q !== 'object' && params.q) { - query.q = '' + params.q; - } else { - throw new TypeError('Invalid q: ' + params.q + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doIndicesValidateQuery; diff --git a/src/api/info.js b/src/api/info.js deleted file mode 100644 index 8cf5e72f1..000000000 --- a/src/api/info.js +++ /dev/null @@ -1,53 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [info](http://elasticsearch.org/guide/) request - * - * @for Client - * @method info - * @param {Object} params - An object with parameters used to carry out this action - */ -function doInfo(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'HEAD') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, HEAD'); - } - } else { - request.method = params.body ? 'HEAD' : 'GET'; - } - - // find the paths's params - - - // build the path - request.path = '/'; - - - // build the query string - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doInfo; diff --git a/src/api/mget.js b/src/api/mget.js deleted file mode 100644 index 7eb28626c..000000000 --- a/src/api/mget.js +++ /dev/null @@ -1,179 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request - * - * @for Client - * @method mget - * @param {Object} params - An object with parameters used to carry out this action - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {boolean} params.realtime - Specify whether to perform the operation in realtime or search mode - * @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation - * @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return - * @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field - * @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field - */ -function doMget(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - } - - if (typeof params.type !== 'undefined') { - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mget'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_mget'; - } - else { - request.path = '/_mget'; - } - - - // build the query string - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.realtime !== 'undefined') { - if (params.realtime.toLowerCase && (params.realtime = params.realtime.toLowerCase()) - && (params.realtime === 'no' || params.realtime === 'off') - ) { - query.realtime = false; - } else { - query.realtime = !!params.realtime; - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params._source !== 'undefined') { - switch (typeof params._source) { - case 'string': - query._source = params._source; - break; - case 'object': - if (_.isArray(params._source)) { - query._source = params._source.join(','); - } else { - throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source = !!params._source; - } - } - - if (typeof params._source_exclude !== 'undefined') { - switch (typeof params._source_exclude) { - case 'string': - query._source_exclude = params._source_exclude; - break; - case 'object': - if (_.isArray(params._source_exclude)) { - query._source_exclude = params._source_exclude.join(','); - } else { - throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_exclude = !!params._source_exclude; - } - } - - if (typeof params._source_include !== 'undefined') { - switch (typeof params._source_include) { - case 'string': - query._source_include = params._source_include; - break; - case 'object': - if (_.isArray(params._source_include)) { - query._source_include = params._source_include.join(','); - } else { - throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_include = !!params._source_include; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doMget; diff --git a/src/api/mlt.js b/src/api/mlt.js deleted file mode 100644 index 556df2264..000000000 --- a/src/api/mlt.js +++ /dev/null @@ -1,282 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [mlt](http://elasticsearch.org/guide/reference/api/more-like-this/) request - * - * @for Client - * @method mlt - * @param {Object} params - An object with parameters used to carry out this action - * @param {number} params.boost_terms - The boost factor - * @param {number} params.max_doc_freq - The word occurrence frequency as count: words with higher occurrence in the corpus will be ignored - * @param {number} params.max_query_terms - The maximum query terms to be included in the generated query - * @param {number} params.max_word_len - The minimum length of the word: longer words will be ignored - * @param {number} params.min_doc_freq - The word occurrence frequency as count: words with lower occurrence in the corpus will be ignored - * @param {number} params.min_term_freq - The term frequency as percent: terms with lower occurence in the source document will be ignored - * @param {number} params.min_word_len - The minimum length of the word: shorter words will be ignored - * @param {String|ArrayOfStrings|Boolean} params.mlt_fields - Specific fields to perform the query against - * @param {number} params.percent_terms_to_match - How many terms have to match in order to consider the document a match (default: 0.3) - * @param {string} params.routing - Specific routing value - * @param {number} params.search_from - The offset from which to return results - * @param {String|ArrayOfStrings|Boolean} params.search_indices - A comma-separated list of indices to perform the query against (default: the index containing the document) - * @param {string} params.search_query_hint - The search query hint - * @param {string} params.search_scroll - A scroll search request definition - * @param {number} params.search_size - The number of documents to return (default: 10) - * @param {string} params.search_source - A specific search request definition (instead of using the request body) - * @param {string} params.search_type - Specific search type (eg. `dfs_then_fetch`, `count`, etc) - * @param {String|ArrayOfStrings|Boolean} params.search_types - A comma-separated list of types to perform the query against (default: the same type as the document) - * @param {String|ArrayOfStrings|Boolean} params.stop_words - A list of stop words to be ignored - */ -function doMlt(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_mlt'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.boost_terms !== 'undefined') { - if (_.isNumeric(params.boost_terms)) { - query.boost_terms = params.boost_terms * 1; - } else { - throw new TypeError('Invalid boost_terms: ' + params.boost_terms + ' should be a number.'); - } - } - - if (typeof params.max_doc_freq !== 'undefined') { - if (_.isNumeric(params.max_doc_freq)) { - query.max_doc_freq = params.max_doc_freq * 1; - } else { - throw new TypeError('Invalid max_doc_freq: ' + params.max_doc_freq + ' should be a number.'); - } - } - - if (typeof params.max_query_terms !== 'undefined') { - if (_.isNumeric(params.max_query_terms)) { - query.max_query_terms = params.max_query_terms * 1; - } else { - throw new TypeError('Invalid max_query_terms: ' + params.max_query_terms + ' should be a number.'); - } - } - - if (typeof params.max_word_len !== 'undefined') { - if (_.isNumeric(params.max_word_len)) { - query.max_word_len = params.max_word_len * 1; - } else { - throw new TypeError('Invalid max_word_len: ' + params.max_word_len + ' should be a number.'); - } - } - - if (typeof params.min_doc_freq !== 'undefined') { - if (_.isNumeric(params.min_doc_freq)) { - query.min_doc_freq = params.min_doc_freq * 1; - } else { - throw new TypeError('Invalid min_doc_freq: ' + params.min_doc_freq + ' should be a number.'); - } - } - - if (typeof params.min_term_freq !== 'undefined') { - if (_.isNumeric(params.min_term_freq)) { - query.min_term_freq = params.min_term_freq * 1; - } else { - throw new TypeError('Invalid min_term_freq: ' + params.min_term_freq + ' should be a number.'); - } - } - - if (typeof params.min_word_len !== 'undefined') { - if (_.isNumeric(params.min_word_len)) { - query.min_word_len = params.min_word_len * 1; - } else { - throw new TypeError('Invalid min_word_len: ' + params.min_word_len + ' should be a number.'); - } - } - - if (typeof params.mlt_fields !== 'undefined') { - switch (typeof params.mlt_fields) { - case 'string': - query.mlt_fields = params.mlt_fields; - break; - case 'object': - if (_.isArray(params.mlt_fields)) { - query.mlt_fields = params.mlt_fields.join(','); - } else { - throw new TypeError('Invalid mlt_fields: ' + params.mlt_fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.mlt_fields = !!params.mlt_fields; - } - } - - if (typeof params.percent_terms_to_match !== 'undefined') { - if (_.isNumeric(params.percent_terms_to_match)) { - query.percent_terms_to_match = params.percent_terms_to_match * 1; - } else { - throw new TypeError('Invalid percent_terms_to_match: ' + params.percent_terms_to_match + ' should be a number.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.search_from !== 'undefined') { - if (_.isNumeric(params.search_from)) { - query.search_from = params.search_from * 1; - } else { - throw new TypeError('Invalid search_from: ' + params.search_from + ' should be a number.'); - } - } - - if (typeof params.search_indices !== 'undefined') { - switch (typeof params.search_indices) { - case 'string': - query.search_indices = params.search_indices; - break; - case 'object': - if (_.isArray(params.search_indices)) { - query.search_indices = params.search_indices.join(','); - } else { - throw new TypeError('Invalid search_indices: ' + params.search_indices + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.search_indices = !!params.search_indices; - } - } - - if (typeof params.search_query_hint !== 'undefined') { - if (typeof params.search_query_hint !== 'object' && params.search_query_hint) { - query.search_query_hint = '' + params.search_query_hint; - } else { - throw new TypeError('Invalid search_query_hint: ' + params.search_query_hint + ' should be a string.'); - } - } - - if (typeof params.search_scroll !== 'undefined') { - if (typeof params.search_scroll !== 'object' && params.search_scroll) { - query.search_scroll = '' + params.search_scroll; - } else { - throw new TypeError('Invalid search_scroll: ' + params.search_scroll + ' should be a string.'); - } - } - - if (typeof params.search_size !== 'undefined') { - if (_.isNumeric(params.search_size)) { - query.search_size = params.search_size * 1; - } else { - throw new TypeError('Invalid search_size: ' + params.search_size + ' should be a number.'); - } - } - - if (typeof params.search_source !== 'undefined') { - if (typeof params.search_source !== 'object' && params.search_source) { - query.search_source = '' + params.search_source; - } else { - throw new TypeError('Invalid search_source: ' + params.search_source + ' should be a string.'); - } - } - - if (typeof params.search_type !== 'undefined') { - if (typeof params.search_type !== 'object' && params.search_type) { - query.search_type = '' + params.search_type; - } else { - throw new TypeError('Invalid search_type: ' + params.search_type + ' should be a string.'); - } - } - - if (typeof params.search_types !== 'undefined') { - switch (typeof params.search_types) { - case 'string': - query.search_types = params.search_types; - break; - case 'object': - if (_.isArray(params.search_types)) { - query.search_types = params.search_types.join(','); - } else { - throw new TypeError('Invalid search_types: ' + params.search_types + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.search_types = !!params.search_types; - } - } - - if (typeof params.stop_words !== 'undefined') { - switch (typeof params.stop_words) { - case 'string': - query.stop_words = params.stop_words; - break; - case 'object': - if (_.isArray(params.stop_words)) { - query.stop_words = params.stop_words.join(','); - } else { - throw new TypeError('Invalid stop_words: ' + params.stop_words + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.stop_words = !!params.stop_words; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doMlt; diff --git a/src/api/msearch.js b/src/api/msearch.js deleted file mode 100644 index 00e5539b3..000000000 --- a/src/api/msearch.js +++ /dev/null @@ -1,108 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', 'dfs_query_and_fetch', 'count', 'scan']; - -/** - * Perform an elasticsearch [msearch](http://www.elasticsearch.org/guide/reference/api/multi-search/) request - * - * @for Client - * @method msearch - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.search_type - Search operation type - */ -function doMsearch(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: this.client.config.serializer.bulkBody(params.body || null) - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_msearch'; - } - else if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_msearch'; - } - else { - request.path = '/_msearch'; - } - - - // build the query string - if (typeof params.search_type !== 'undefined') { - if (_.contains(searchTypeOptions, params.search_type)) { - query.search_type = params.search_type; - } else { - throw new TypeError( - 'Invalid search_type: ' + params.search_type + - ' should be one of ' + searchTypeOptions.join(', ') + '.' - ); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doMsearch; diff --git a/src/api/percolate.js b/src/api/percolate.js deleted file mode 100644 index 24bbf0a4b..000000000 --- a/src/api/percolate.js +++ /dev/null @@ -1,80 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [percolate](http://elasticsearch.org/guide/reference/api/percolate/) request - * - * @for Client - * @method percolate - * @param {Object} params - An object with parameters used to carry out this action - * @param {boolean} params.prefer_local - With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true) - */ -function doPercolate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_percolate'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.prefer_local !== 'undefined') { - if (params.prefer_local.toLowerCase && (params.prefer_local = params.prefer_local.toLowerCase()) - && (params.prefer_local === 'no' || params.prefer_local === 'off') - ) { - query.prefer_local = false; - } else { - query.prefer_local = !!params.prefer_local; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doPercolate; diff --git a/src/api/scroll.js b/src/api/scroll.js deleted file mode 100644 index 917f0889e..000000000 --- a/src/api/scroll.js +++ /dev/null @@ -1,84 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -/** - * Perform an elasticsearch [scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request - * - * @for Client - * @method scroll - * @param {Object} params - An object with parameters used to carry out this action - * @param {duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search - * @param {string} params.scroll_id - The scroll ID for scrolled search - */ -function doScroll(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.scroll_id !== 'undefined') { - if (typeof params.scroll_id !== 'object' && params.scroll_id) { - parts.scroll_id = '' + params.scroll_id; - } else { - throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.'); - } - } - - - // build the path - if (parts.hasOwnProperty('scroll_id')) { - request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + ''; - delete params.scroll_id; - } - else { - request.path = '/_search/scroll'; - } - - - // build the query string - if (typeof params.scroll !== 'undefined') { - if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) { - query.scroll = params.scroll; - } else { - throw new TypeError('Invalid scroll: ' + params.scroll + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).'); - } - } - - if (typeof params.scroll_id !== 'undefined') { - if (typeof params.scroll_id !== 'object' && params.scroll_id) { - query.scroll_id = '' + params.scroll_id; - } else { - throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doScroll; diff --git a/src/api/search.js b/src/api/search.js deleted file mode 100644 index 0c94e7186..000000000 --- a/src/api/search.js +++ /dev/null @@ -1,453 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var defaultOperatorOptions = ['AND', 'OR']; -var ignoreIndicesOptions = ['none', 'missing']; -var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', 'dfs_query_and_fetch', 'count', 'scan']; -var suggestModeOptions = ['missing', 'popular', 'always']; - -/** - * Perform an elasticsearch [search](http://www.elasticsearch.org/guide/reference/api/search/) request - * - * @for Client - * @method search - * @param {Object} params - An object with parameters used to carry out this action - * @param {string} params.analyzer - The analyzer to use for the query string - * @param {boolean} params.analyze_wildcard - Specify whether wildcard and prefix queries should be analyzed (default: false) - * @param {String} [params.default_operator=OR] - The default operator for query string query (AND or OR) - * @param {string} params.df - The field to use as default where no field prefix is given in the query string - * @param {boolean} params.explain - Specify whether to return detailed information about score computation as part of a hit - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return as part of a hit - * @param {number} params.from - Starting offset (default: 0) - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {String|ArrayOfStrings|Boolean} params.indices_boost - Comma-separated list of index boosts - * @param {boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored - * @param {boolean} params.lowercase_expanded_terms - Specify whether query terms should be lowercased - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {string} params.q - Query in the Lucene query string syntax - * @param {String|ArrayOfStrings|Boolean} params.routing - A comma-separated list of specific routing values - * @param {duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search - * @param {String} params.search_type - Search operation type - * @param {number} params.size - Number of hits to return (default: 10) - * @param {String|ArrayOfStrings|Boolean} params.sort - A comma-separated list of : pairs - * @param {string} params.source - The URL-encoded request definition using the Query DSL (instead of using request body) - * @param {String|ArrayOfStrings|Boolean} params._source - True or false to return the _source field or not, or a list of fields to return - * @param {String|ArrayOfStrings|Boolean} params._source_exclude - A list of fields to exclude from the returned _source field - * @param {String|ArrayOfStrings|Boolean} params._source_include - A list of fields to extract and return from the _source field - * @param {String|ArrayOfStrings|Boolean} params.stats - Specific 'tag' of the request for logging and statistical purposes - * @param {string} params.suggest_field - Specify which field to use for suggestions - * @param {String} [params.suggest_mode=missing] - Specify suggest mode - * @param {number} params.suggest_size - How many suggestions to return in response - * @param {text} params.suggest_text - The source text for which the suggestions should be returned - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {boolean} params.version - Specify whether to return document version as part of a hit - */ -function doSearch(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'GET' || params.method === 'POST') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of GET, POST'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - if (typeof params.type !== 'undefined') { - switch (typeof params.type) { - case 'string': - parts.type = params.type; - break; - case 'object': - if (_.isArray(params.type)) { - parts.type = params.type.join(','); - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.type = !!params.type; - } - } - - - // build the path - if (parts.hasOwnProperty('type')) { - request.path = '/' + encodeURIComponent(parts.index || '_all') + '/' + encodeURIComponent(parts.type) + '/_search'; - } - else { - request.path = '/' + encodeURIComponent(parts.index || '_all') + '/_search'; - } - - - // build the query string - if (typeof params.analyzer !== 'undefined') { - if (typeof params.analyzer !== 'object' && params.analyzer) { - query.analyzer = '' + params.analyzer; - } else { - throw new TypeError('Invalid analyzer: ' + params.analyzer + ' should be a string.'); - } - } - - if (typeof params.analyze_wildcard !== 'undefined') { - if (params.analyze_wildcard.toLowerCase && (params.analyze_wildcard = params.analyze_wildcard.toLowerCase()) - && (params.analyze_wildcard === 'no' || params.analyze_wildcard === 'off') - ) { - query.analyze_wildcard = false; - } else { - query.analyze_wildcard = !!params.analyze_wildcard; - } - } - - if (typeof params.default_operator !== 'undefined') { - if (_.contains(defaultOperatorOptions, params.default_operator)) { - query.default_operator = params.default_operator; - } else { - throw new TypeError( - 'Invalid default_operator: ' + params.default_operator + - ' should be one of ' + defaultOperatorOptions.join(', ') + '.' - ); - } - } - - if (typeof params.df !== 'undefined') { - if (typeof params.df !== 'object' && params.df) { - query.df = '' + params.df; - } else { - throw new TypeError('Invalid df: ' + params.df + ' should be a string.'); - } - } - - if (typeof params.explain !== 'undefined') { - if (params.explain.toLowerCase && (params.explain = params.explain.toLowerCase()) - && (params.explain === 'no' || params.explain === 'off') - ) { - query.explain = false; - } else { - query.explain = !!params.explain; - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.from !== 'undefined') { - if (_.isNumeric(params.from)) { - query.from = params.from * 1; - } else { - throw new TypeError('Invalid from: ' + params.from + ' should be a number.'); - } - } - - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.indices_boost !== 'undefined') { - switch (typeof params.indices_boost) { - case 'string': - query.indices_boost = params.indices_boost; - break; - case 'object': - if (_.isArray(params.indices_boost)) { - query.indices_boost = params.indices_boost.join(','); - } else { - throw new TypeError('Invalid indices_boost: ' + params.indices_boost + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.indices_boost = !!params.indices_boost; - } - } - - if (typeof params.lenient !== 'undefined') { - if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase()) - && (params.lenient === 'no' || params.lenient === 'off') - ) { - query.lenient = false; - } else { - query.lenient = !!params.lenient; - } - } - - if (typeof params.lowercase_expanded_terms !== 'undefined') { - if (params.lowercase_expanded_terms.toLowerCase && (params.lowercase_expanded_terms = params.lowercase_expanded_terms.toLowerCase()) - && (params.lowercase_expanded_terms === 'no' || params.lowercase_expanded_terms === 'off') - ) { - query.lowercase_expanded_terms = false; - } else { - query.lowercase_expanded_terms = !!params.lowercase_expanded_terms; - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.q !== 'undefined') { - if (typeof params.q !== 'object' && params.q) { - query.q = '' + params.q; - } else { - throw new TypeError('Invalid q: ' + params.q + ' should be a string.'); - } - } - - if (typeof params.routing !== 'undefined') { - switch (typeof params.routing) { - case 'string': - query.routing = params.routing; - break; - case 'object': - if (_.isArray(params.routing)) { - query.routing = params.routing.join(','); - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.routing = !!params.routing; - } - } - - if (typeof params.scroll !== 'undefined') { - if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) { - query.scroll = params.scroll; - } else { - throw new TypeError('Invalid scroll: ' + params.scroll + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).'); - } - } - - if (typeof params.search_type !== 'undefined') { - if (_.contains(searchTypeOptions, params.search_type)) { - query.search_type = params.search_type; - } else { - throw new TypeError( - 'Invalid search_type: ' + params.search_type + - ' should be one of ' + searchTypeOptions.join(', ') + '.' - ); - } - } - - if (typeof params.size !== 'undefined') { - if (_.isNumeric(params.size)) { - query.size = params.size * 1; - } else { - throw new TypeError('Invalid size: ' + params.size + ' should be a number.'); - } - } - - if (typeof params.sort !== 'undefined') { - switch (typeof params.sort) { - case 'string': - query.sort = params.sort; - break; - case 'object': - if (_.isArray(params.sort)) { - query.sort = params.sort.join(','); - } else { - throw new TypeError('Invalid sort: ' + params.sort + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.sort = !!params.sort; - } - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - if (typeof params._source !== 'undefined') { - switch (typeof params._source) { - case 'string': - query._source = params._source; - break; - case 'object': - if (_.isArray(params._source)) { - query._source = params._source.join(','); - } else { - throw new TypeError('Invalid _source: ' + params._source + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source = !!params._source; - } - } - - if (typeof params._source_exclude !== 'undefined') { - switch (typeof params._source_exclude) { - case 'string': - query._source_exclude = params._source_exclude; - break; - case 'object': - if (_.isArray(params._source_exclude)) { - query._source_exclude = params._source_exclude.join(','); - } else { - throw new TypeError('Invalid _source_exclude: ' + params._source_exclude + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_exclude = !!params._source_exclude; - } - } - - if (typeof params._source_include !== 'undefined') { - switch (typeof params._source_include) { - case 'string': - query._source_include = params._source_include; - break; - case 'object': - if (_.isArray(params._source_include)) { - query._source_include = params._source_include.join(','); - } else { - throw new TypeError('Invalid _source_include: ' + params._source_include + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query._source_include = !!params._source_include; - } - } - - if (typeof params.stats !== 'undefined') { - switch (typeof params.stats) { - case 'string': - query.stats = params.stats; - break; - case 'object': - if (_.isArray(params.stats)) { - query.stats = params.stats.join(','); - } else { - throw new TypeError('Invalid stats: ' + params.stats + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.stats = !!params.stats; - } - } - - if (typeof params.suggest_field !== 'undefined') { - if (typeof params.suggest_field !== 'object' && params.suggest_field) { - query.suggest_field = '' + params.suggest_field; - } else { - throw new TypeError('Invalid suggest_field: ' + params.suggest_field + ' should be a string.'); - } - } - - if (typeof params.suggest_mode !== 'undefined') { - if (_.contains(suggestModeOptions, params.suggest_mode)) { - query.suggest_mode = params.suggest_mode; - } else { - throw new TypeError( - 'Invalid suggest_mode: ' + params.suggest_mode + - ' should be one of ' + suggestModeOptions.join(', ') + '.' - ); - } - } - - if (typeof params.suggest_size !== 'undefined') { - if (_.isNumeric(params.suggest_size)) { - query.suggest_size = params.suggest_size * 1; - } else { - throw new TypeError('Invalid suggest_size: ' + params.suggest_size + ' should be a number.'); - } - } - - if (typeof params.suggest_text !== 'undefined') { - if (typeof params.suggest_text !== 'object' && params.suggest_text) { - query.suggest_text = '' + params.suggest_text; - } else { - throw new TypeError('Invalid suggest_text: ' + params.suggest_text + ' should be a string.'); - } - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.version !== 'undefined') { - if (params.version.toLowerCase && (params.version = params.version.toLowerCase()) - && (params.version === 'no' || params.version === 'off') - ) { - query.version = false; - } else { - query.version = !!params.version; - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doSearch; diff --git a/src/api/suggest.js b/src/api/suggest.js deleted file mode 100644 index c25294b23..000000000 --- a/src/api/suggest.js +++ /dev/null @@ -1,115 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var ignoreIndicesOptions = ['none', 'missing']; - -/** - * Perform an elasticsearch [suggest](http://elasticsearch.org/guide/reference/api/search/suggest/) request - * - * @for Client - * @method suggest - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones - * @param {string} params.preference - Specify the node or shard the operation should be performed on (default: random) - * @param {string} params.routing - Specific routing value - * @param {string} params.source - The URL-encoded request definition (instead of using request body) - */ -function doSuggest(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null - }, - parts = {}, - query = {}, - responseOpts = {}; - - // figure out the method - if (params.method = _.toUpperString(params.method)) { - if (params.method === 'POST' || params.method === 'GET') { - request.method = params.method; - } else { - throw new TypeError('Invalid method: should be one of POST, GET'); - } - } else { - request.method = params.body ? 'POST' : 'GET'; - } - - // find the paths's params - if (typeof params.index !== 'undefined') { - switch (typeof params.index) { - case 'string': - parts.index = params.index; - break; - case 'object': - if (_.isArray(params.index)) { - parts.index = params.index.join(','); - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - parts.index = !!params.index; - } - } - - - // build the path - if (parts.hasOwnProperty('index')) { - request.path = '/' + encodeURIComponent(parts.index) + '/_suggest'; - } - else { - request.path = '/_suggest'; - } - - - // build the query string - if (typeof params.ignore_indices !== 'undefined') { - if (_.contains(ignoreIndicesOptions, params.ignore_indices)) { - query.ignore_indices = params.ignore_indices; - } else { - throw new TypeError( - 'Invalid ignore_indices: ' + params.ignore_indices + - ' should be one of ' + ignoreIndicesOptions.join(', ') + '.' - ); - } - } - - if (typeof params.preference !== 'undefined') { - if (typeof params.preference !== 'object' && params.preference) { - query.preference = '' + params.preference; - } else { - throw new TypeError('Invalid preference: ' + params.preference + ' should be a string.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.source !== 'undefined') { - if (typeof params.source !== 'object' && params.source) { - query.source = '' + params.source; - } else { - throw new TypeError('Invalid source: ' + params.source + ' should be a string.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doSuggest; diff --git a/src/api/update.js b/src/api/update.js deleted file mode 100644 index 414b73dd2..000000000 --- a/src/api/update.js +++ /dev/null @@ -1,221 +0,0 @@ -var _ = require('../lib/utils'), - errors = require('../lib/errors'), - q = require('q'); - -var consistencyOptions = ['one', 'quorum', 'all']; -var replicationOptions = ['sync', 'async']; - -/** - * Perform an elasticsearch [update](http://elasticsearch.org/guide/reference/api/update/) request - * - * @for Client - * @method update - * @param {Object} params - An object with parameters used to carry out this action - * @param {String} params.consistency - Explicit write consistency setting for the operation - * @param {String|ArrayOfStrings|Boolean} params.fields - A comma-separated list of fields to return in the response - * @param {string} params.lang - The script language (default: mvel) - * @param {string} params.parent - ID of the parent document - * @param {string} params.percolate - Perform percolation during the operation; use specific registered query name, attribute, or wildcard - * @param {boolean} params.refresh - Refresh the index after performing the operation - * @param {String} [params.replication=sync] - Specific replication type - * @param {number} params.retry_on_conflict - Specify how many times should the operation be retried when a conflict occurs (default: 0) - * @param {string} params.routing - Specific routing value - * @param {*} params.script - The URL-encoded script definition (instead of using request body) - * @param {Date|Number} params.timeout - Explicit operation timeout - * @param {Date|Number} params.timestamp - Explicit timestamp for the document - * @param {duration} params.ttl - Expiration time for the document - * @param {number} params.version - Explicit version number for concurrency control - * @param {number} params.version_type - Explicit version number for concurrency control - */ -function doUpdate(params, cb) { - if (typeof params === 'function') { - cb = params; - params = {}; - } else { - params = params || {}; - cb = typeof cb === 'function' ? cb : _.noop; - } - - var request = { - ignore: params.ignore, - body: params.body || null, - method: 'POST' - }, - parts = {}, - query = {}, - responseOpts = {}; - - - // find the paths's params - if (typeof params.id !== 'object' && params.id) { - parts.id = '' + params.id; - } else { - throw new TypeError('Invalid id: ' + params.id + ' should be a string.'); - } - - if (typeof params.index !== 'object' && params.index) { - parts.index = '' + params.index; - } else { - throw new TypeError('Invalid index: ' + params.index + ' should be a string.'); - } - - if (typeof params.type !== 'object' && params.type) { - parts.type = '' + params.type; - } else { - throw new TypeError('Invalid type: ' + params.type + ' should be a string.'); - } - - - // build the path - if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type') && parts.hasOwnProperty('id')) { - request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/' + encodeURIComponent(parts.id) + '/_update'; - } - else { - throw new TypeError('Unable to build a path with those params. Supply at least [object Object], [object Object], [object Object]'); - } - - - // build the query string - if (typeof params.consistency !== 'undefined') { - if (_.contains(consistencyOptions, params.consistency)) { - query.consistency = params.consistency; - } else { - throw new TypeError( - 'Invalid consistency: ' + params.consistency + - ' should be one of ' + consistencyOptions.join(', ') + '.' - ); - } - } - - if (typeof params.fields !== 'undefined') { - switch (typeof params.fields) { - case 'string': - query.fields = params.fields; - break; - case 'object': - if (_.isArray(params.fields)) { - query.fields = params.fields.join(','); - } else { - throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.'); - } - break; - default: - query.fields = !!params.fields; - } - } - - if (typeof params.lang !== 'undefined') { - if (typeof params.lang !== 'object' && params.lang) { - query.lang = '' + params.lang; - } else { - throw new TypeError('Invalid lang: ' + params.lang + ' should be a string.'); - } - } - - if (typeof params.parent !== 'undefined') { - if (typeof params.parent !== 'object' && params.parent) { - query.parent = '' + params.parent; - } else { - throw new TypeError('Invalid parent: ' + params.parent + ' should be a string.'); - } - } - - if (typeof params.percolate !== 'undefined') { - if (typeof params.percolate !== 'object' && params.percolate) { - query.percolate = '' + params.percolate; - } else { - throw new TypeError('Invalid percolate: ' + params.percolate + ' should be a string.'); - } - } - - if (typeof params.refresh !== 'undefined') { - if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase()) - && (params.refresh === 'no' || params.refresh === 'off') - ) { - query.refresh = false; - } else { - query.refresh = !!params.refresh; - } - } - - if (typeof params.replication !== 'undefined') { - if (_.contains(replicationOptions, params.replication)) { - query.replication = params.replication; - } else { - throw new TypeError( - 'Invalid replication: ' + params.replication + - ' should be one of ' + replicationOptions.join(', ') + '.' - ); - } - } - - if (typeof params.retry_on_conflict !== 'undefined') { - if (_.isNumeric(params.retry_on_conflict)) { - query.retry_on_conflict = params.retry_on_conflict * 1; - } else { - throw new TypeError('Invalid retry_on_conflict: ' + params.retry_on_conflict + ' should be a number.'); - } - } - - if (typeof params.routing !== 'undefined') { - if (typeof params.routing !== 'object' && params.routing) { - query.routing = '' + params.routing; - } else { - throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.'); - } - } - - if (typeof params.script !== 'undefined') { - query.script = params.script; - } - - if (typeof params.timeout !== 'undefined') { - if (params.timeout instanceof Date) { - query.timeout = params.timeout.getTime(); - } else if (_.isNumeric(params.timeout)) { - query.timeout = params.timeout; - } else { - throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.'); - } - } - - if (typeof params.timestamp !== 'undefined') { - if (params.timestamp instanceof Date) { - query.timestamp = params.timestamp.getTime(); - } else if (_.isNumeric(params.timestamp)) { - query.timestamp = params.timestamp; - } else { - throw new TypeError('Invalid timestamp: ' + params.timestamp + ' should be be some sort of time.'); - } - } - - if (typeof params.ttl !== 'undefined') { - if (_.isNumeric(params.ttl) || _.isInterval(params.ttl)) { - query.ttl = params.ttl; - } else { - throw new TypeError('Invalid ttl: ' + params.ttl + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).'); - } - } - - if (typeof params.version !== 'undefined') { - if (_.isNumeric(params.version)) { - query.version = params.version * 1; - } else { - throw new TypeError('Invalid version: ' + params.version + ' should be a number.'); - } - } - - if (typeof params.version_type !== 'undefined') { - if (_.isNumeric(params.version_type)) { - query.version_type = params.version_type * 1; - } else { - throw new TypeError('Invalid version_type: ' + params.version_type + ' should be a number.'); - } - } - - request.path = request.path + _.makeQueryString(query); - - this.client.request(request, cb); -} - -module.exports = doUpdate; diff --git a/src/lib/Client.js b/src/lib/Client.js index 59dcfccfc..0b2402da3 100644 --- a/src/lib/Client.js +++ b/src/lib/Client.js @@ -32,15 +32,10 @@ module.exports = Client; var _ = require('./utils'); var ClientConfig = require('./client_config'); -var api = _.reKey(_.requireDir(module, '../api'), _.camelCase); +// var api = _.reKey(_.requireDir(module, '../api'), _.camelCase); var q = require('q'); var errors = require('./errors'); -// Many API commands are namespaced, like cluster.nodeStats. The names of these namespaces will be -// tracked here and the namespace objects will be instantiated by reading the values from this -// array -var namespaces = []; - function Client(config) { this.client = this; @@ -53,8 +48,8 @@ function Client(config) { }); this.config.client = this; - for (var i = 0; i < namespaces.length; i++) { - this[namespaces[i]] = new this[namespaces[i]](this); + for (var i = 0; i < _namespaces.length; i++) { + this[_namespaces[i]] = new this[_namespaces[i]](this); } } @@ -77,6 +72,13 @@ Client.prototype.request = function (params, cb) { // in cb isn't a function make it one cb = typeof cb === 'function' ? cb : _.noop; + var connectionPool = this.config.connectionPool; + var log = this.config.log; + var remainingRetries = this.config.maxRetries; + var connection; + + log.debug('starting request', params); + // get ignore and ensure that it's an array var ignore = params.ignore; if (ignore && !_.isArray(ignore)) { @@ -85,12 +87,50 @@ Client.prototype.request = function (params, cb) { // serialize the body if (params.body) { - params.body = serializer.serialize(params.body); + params.body = params.bulkBody ? serializer.bulkBody(params.body) : serializer.serialize(params.body); } - this.config.transport.request(params, function (err, reqParams, body, status) { + if (params.body && params.method === 'GET') { + _.nextTick(cb, new TypeError('Body can not be sent with method "GET"')); + return; + } + function sendRequestWithConnection(err, _connection) { + if (err) { + log.error(err); + respond(err); + } else if (_connection) { + connection = _connection; + log.info('Selected', _connection.status, 'Connection, making request'); + connection.request(params, checkRespForFailure); + } else { + log.warning('No living connections'); + respond(new errors.ConnectionFault('No living connections.')); + } + } + + function checkRespForFailure(err, reqParams, body, status) { + connection.setStatus(err ? 'dead' : 'alive'); + + if (err) { + log.error(err); + } + + if (err && remainingRetries) { + remainingRetries--; + log.info('Connection error, retrying'); + connectionPool.select(sendRequestWithConnection); + } else { + log.info('Request complete'); + respond(err, reqParams, body, status); + } + } + + function respond(err, reqParams, body, status) { var parsedBody = null; + if (reqParams) { + log.trace(reqParams.method, reqParams, params.body, body, status); + } if (!err) { if (body) { parsedBody = serializer.unserialize(body); @@ -103,17 +143,19 @@ Client.prototype.request = function (params, cb) { } if (err) { - return cb(err, parsedBody, status); + cb(err, parsedBody, status); } else if ((status >= 200 && status < 300) || ignore && _.contains(ignore, status)) { - return cb(void 0, parsedBody, status); + cb(void 0, parsedBody, status); } else { if (errors[status]) { - return cb(new errors[status](parsedBody.error), parsedBody, status); + cb(new errors[status](parsedBody.error), parsedBody, status); } else { - return cb(new errors.Generic('unknown error'), parsedBody, status); + cb(new errors.Generic('unknown error'), parsedBody, status); } } - }); + } + + connectionPool.select(sendRequestWithConnection); }; /** @@ -123,41 +165,54 @@ Client.prototype.request = function (params, cb) { * @param {Function} cb - callback */ Client.prototype.ping = function (params, cb) { - this.config.transport.request({ + this.request({ method: 'HEAD', path: '/' }, cb); }; +/** + * Ask an ES node for a list of all the nodes, add/remove nodes from the connection + * pool as appropriate + * + * @param {Function} cb - Function to call back once complete + */ +Client.prototype.sniff = function (cb) { + var config = this.config; + + // make cb a function if it isn't + cb = typeof cb === 'function' ? cb : _.noop; + + this.request({ + path: '/_cluster/nodes', + method: 'GET' + }, function (err, resp) { + if (!err && resp && resp.nodes) { + var nodes = config.nodesToHostCallback(resp.nodes); + config.connectionPool.setNodes(nodes); + } + cb(err, resp); + }); +} + +var _namespaces = []; + /** * These names of the properties that hold namespace objects in the Client prototype * @type {Array} */ -Client.namespaces = []; - -/** - * Creates a namespace, who's prototype offers the actions within that namespace and this context - * provides the API actions and a link back to the client they were intended to operate on. - * @param {Object} actions - An object to use as the prototype for the namespace - */ -function makeNamespaceConstructor(actions) { - - function Namespace(client) { - this.client = client; +Client.namespace = function (namespace) { + var steps = namespace.split('.'); + var path = []; + var on = Client; + var i; + for (i = 0; i < steps.length; i ++) { + path.push(steps[i]); + _namespaces.push(path.join('.')); + on.prototype[steps[i]] = function ClientActionNamespace(client) { + this.client = client; + }; } +}; - Namespace.prototype = actions; - - return Namespace; -} - -// Extend the Client prototype with the top level API actions and the namespaces for other API actions -_.extend(Client.prototype, _.map(api, function (action, name) { - switch (typeof action) { - case 'function': - return action; - case 'object': - namespaces.push(name); - return makeNamespaceConstructor(action); - } -})); +require('./api.js').attach(Client); diff --git a/src/lib/Transport.js b/src/lib/Transport.js deleted file mode 100644 index d149b99ba..000000000 --- a/src/lib/Transport.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Manages connection pools, sniffs for nodes, and runs requests - * - * @main Transport - * @class Transport - * @constructor - * @param {Object} [config={}] - An object with configuration parameters - * @param {String|ArrayOfStrings} [config.hosts='localhost:9200'] - Host(s) that this client should communicate with. - * @param {Boolean} [config.connectionConstructor=false] - A constructor to use for connections to ES nodes - * @param {Function} [config.nodesToHostCallback=parseNodeList] - convert the value returned from _cluster/nodes into - * a host list - * @param {Boolean} [config.sniffOnStart=false] - inspect the cluster for a list of nodes upon startup - * @param {Number} [config.sniffAfterRequests=null] - Sniff after completing a certain number of request - * @param {Boolean} [config.sniffOnConnectionFail=false] - Sniff after a connection fails - * @param {Number} [config.max_retries=3] - The maximum number of times the client should retry connecting to a node - */ - -module.exports = Transport; - -var _ = require('./utils'), - q = require('q'), - ConnectionPool = require('./connection_pool'), - errors = require('./errors'); - -function Transport(config) { - this.config = config; -} - - -Transport.prototype.sniff = function (cb) { - var self = this; - - // make cb a function if it isn't - cb = typeof cb === 'function' ? cb : _.noop; - - self.request({ - path: '/_cluster/nodes', - method: 'GET' - }, function (err, resp) { - if (!err && resp && resp.nodes) { - self.createConnections(self.config.nodesToHostCallback(resp.nodes)); - } - cb(err, resp); - }); -}; - -Transport.prototype.createConnections = function (hosts) { - for (var i = 0; i < hosts.length; i++) { - this.config.connectionPool.add(new this.config.connectionConstructor( - this.config, - hosts[i] - )); - } -}; - -Transport.prototype.request = function (params, cb) { - cb = typeof cb === 'function' ? cb : _.noop; - - var connectionPool = this.config.connectionPool; - var log = this.config.log; - var remainingRetries = this.config.maxRetries; - var connection; - - function sendRequestWithConnection(err, _connection) { - if (err) { - log.error(err); - cb(err); - } else if (_connection) { - connection = _connection; - log.info('Selected', _connection.status, 'Connection, making request'); - connection.request(params, checkRespForFailure); - } else { - log.warning('No living connections'); - cb(new errors.ConnectionFault('No living connections.')); - } - } - - function checkRespForFailure(err, reqParams, body, status) { - connection.setStatus(err ? 'dead' : 'alive'); - - if (err) { - log.error(err); - } - - if (err && remainingRetries) { - remainingRetries--; - log.info('connection error, retrying'); - connectionPool.select(sendRequestWithConnection); - } else { - log.info('Request complete'); - cb(err, reqParams, body, status); - } - } - - connectionPool.select(sendRequestWithConnection); -}; diff --git a/src/lib/api.js b/src/lib/api.js new file mode 100644 index 000000000..a81657b61 --- /dev/null +++ b/src/lib/api.js @@ -0,0 +1,3298 @@ +var ClientAction = require('./client_action'); +var errors = require('./errors'); + +exports.attach = function (Client) { + Client.namespace('cluster'); + Client.namespace('indices'); + + /** + * Perform a [bulk](http://elasticsearch.org/guide/reference/api/bulk/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.consistency + * @param {Boolean} params.refresh + * @param {String} [params.replication=sync] + * @param {String} params.type + */ + Client.prototype.bulk = ClientAction({ + name: 'bulk', + methods: [ + 'POST', + 'PUT' + ], + params: { + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + refresh: { + type: 'boolean' + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + type: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_bulk', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_bulk', + req: { + index: { + type: 'string' + } + } + }, + { + fmt: '/_bulk' + } + ], + bulkBody: true + }); + + /** + * Perform a [clear_scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.clearScroll = ClientAction({ + name: 'clear_scroll', + methods: [ + 'DELETE' + ], + params: {}, + urls: [ + { + fmt: '/_search/scroll/<%=scroll_id%>', + req: { + scroll_id: { + type: 'list' + } + } + } + ] + }); + + /** + * Perform a [cluster.get_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.cluster.prototype.getSettings = ClientAction({ + name: 'cluster.get_settings', + methods: [ + 'GET' + ], + params: {}, + urls: [ + { + fmt: '/_cluster/settings' + } + ] + }); + + /** + * Perform a [cluster.health](http://elasticsearch.org/guide/reference/api/admin-cluster-health/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.level=cluster] + * @param {Boolean} params.local + * @param {Date|Number} params.master_timeout + * @param {Date|Number} params.timeout + * @param {Number} params.wait_for_active_shards + * @param {String} params.wait_for_nodes + * @param {Number} params.wait_for_relocating_shards + * @param {String} params.wait_for_status + */ + Client.prototype.cluster.prototype.health = ClientAction({ + name: 'cluster.health', + methods: [ + 'GET' + ], + params: { + level: { + type: 'enum', + 'default': 'cluster', + options: [ + 'cluster', + 'indices', + 'shards' + ] + }, + local: { + type: 'boolean' + }, + master_timeout: { + type: 'time' + }, + timeout: { + type: 'time' + }, + wait_for_active_shards: { + type: 'number' + }, + wait_for_nodes: { + type: 'string' + }, + wait_for_relocating_shards: { + type: 'number' + }, + wait_for_status: { + type: 'enum', + 'default': null, + options: [ + 'green', + 'yellow', + 'red' + ] + } + }, + urls: [ + { + fmt: '/_cluster/health/<%=index%>', + req: { + index: { + type: 'string' + } + } + }, + { + fmt: '/_cluster/health' + } + ] + }); + + /** + * Perform a [cluster.node_hot_threads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.interval + * @param {Number} params.snapshots + * @param {Number} params.threads + * @param {String} params.type + */ + Client.prototype.cluster.prototype.nodeHotThreads = ClientAction({ + name: 'cluster.node_hot_threads', + methods: [ + 'GET' + ], + params: { + interval: { + type: 'time' + }, + snapshots: { + type: 'number' + }, + threads: { + type: 'number' + }, + type: { + type: 'enum', + options: [ + 'cpu', + 'wait', + 'block' + ] + } + }, + urls: [ + { + fmt: '/_nodes/<%=node_id%>/hotthreads', + req: { + node_id: { + type: 'list' + } + } + }, + { + fmt: '/_nodes/hotthreads' + } + ] + }); + + /** + * Perform a [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.all + * @param {Boolean} params.clear + * @param {Boolean} params.http + * @param {Boolean} params.jvm + * @param {Boolean} params.network + * @param {Boolean} params.os + * @param {Boolean} params.plugin + * @param {Boolean} params.process + * @param {Boolean} params.settings + * @param {Boolean} params.thread_pool + * @param {Date|Number} params.timeout + * @param {Boolean} params.transport + */ + Client.prototype.cluster.prototype.nodeInfo = ClientAction({ + name: 'cluster.node_info', + methods: [ + 'GET' + ], + params: { + all: { + type: 'boolean' + }, + clear: { + type: 'boolean' + }, + http: { + type: 'boolean' + }, + jvm: { + type: 'boolean' + }, + network: { + type: 'boolean' + }, + os: { + type: 'boolean' + }, + plugin: { + type: 'boolean' + }, + process: { + type: 'boolean' + }, + settings: { + type: 'boolean' + }, + thread_pool: { + type: 'boolean' + }, + timeout: { + type: 'time' + }, + transport: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/_nodes/<%=node_id%>', + req: { + node_id: { + type: 'list' + } + } + }, + { + fmt: '/_nodes' + } + ] + }); + + /** + * Perform a [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.delay + * @param {Boolean} params.exit + */ + Client.prototype.cluster.prototype.nodeShutdown = ClientAction({ + name: 'cluster.node_shutdown', + methods: [ + 'POST' + ], + params: { + delay: { + type: 'time' + }, + exit: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/_cluster/nodes/<%=node_id%>/_shutdown', + req: { + node_id: { + type: 'list' + } + } + }, + { + fmt: '/_shutdown' + } + ] + }); + + /** + * Perform a [cluster.node_stats](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.all + * @param {Boolean} params.clear + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {Boolean} params.fs + * @param {Boolean} params.http + * @param {Boolean} params.indices + * @param {Boolean} params.jvm + * @param {Boolean} params.network + * @param {Boolean} params.os + * @param {Boolean} params.process + * @param {Boolean} params.thread_pool + * @param {Boolean} params.transport + */ + Client.prototype.cluster.prototype.nodeStats = ClientAction({ + name: 'cluster.node_stats', + methods: [ + 'GET' + ], + params: { + all: { + type: 'boolean' + }, + clear: { + type: 'boolean' + }, + fields: { + type: 'list' + }, + fs: { + type: 'boolean' + }, + http: { + type: 'boolean' + }, + indices: { + type: 'boolean' + }, + jvm: { + type: 'boolean' + }, + network: { + type: 'boolean' + }, + os: { + type: 'boolean' + }, + process: { + type: 'boolean' + }, + thread_pool: { + type: 'boolean' + }, + transport: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/_nodes/<%=node_id%>/stats', + req: { + node_id: { + type: 'list' + } + } + }, + { + fmt: '/_nodes/stats' + } + ] + }); + + /** + * Perform a [cluster.put_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.cluster.prototype.putSettings = ClientAction({ + name: 'cluster.put_settings', + methods: [ + 'PUT' + ], + params: {}, + urls: [ + { + fmt: '/_cluster/settings' + } + ] + }); + + /** + * Perform a [cluster.reroute](http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.dry_run + * @param {Boolean} params.filter_metadata + */ + Client.prototype.cluster.prototype.reroute = ClientAction({ + name: 'cluster.reroute', + methods: [ + 'POST' + ], + params: { + dry_run: { + type: 'boolean' + }, + filter_metadata: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/_cluster/reroute' + } + ] + }); + + /** + * Perform a [cluster.state](http://elasticsearch.org/guide/reference/api/admin-cluster-state/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.filter_blocks + * @param {Boolean} params.filter_index_templates + * @param {String|ArrayOfStrings|Boolean} params.filter_indices + * @param {Boolean} params.filter_metadata + * @param {Boolean} params.filter_nodes + * @param {Boolean} params.filter_routing_table + * @param {Boolean} params.local + * @param {Date|Number} params.master_timeout + */ + Client.prototype.cluster.prototype.state = ClientAction({ + name: 'cluster.state', + methods: [ + 'GET' + ], + params: { + filter_blocks: { + type: 'boolean' + }, + filter_index_templates: { + type: 'boolean' + }, + filter_indices: { + type: 'list' + }, + filter_metadata: { + type: 'boolean' + }, + filter_nodes: { + type: 'boolean' + }, + filter_routing_table: { + type: 'boolean' + }, + local: { + type: 'boolean' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/_cluster/state' + } + ] + }); + + /** + * Perform a [count](http://elasticsearch.org/guide/reference/api/count/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + * @param {Number} params.min_score + * @param {String} params.preference + * @param {String} params.routing + * @param {String} params.source + */ + Client.prototype.count = ClientAction({ + name: 'count', + methods: [ + 'POST', + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + min_score: { + type: 'number' + }, + preference: { + type: 'string' + }, + routing: { + type: 'string' + }, + source: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_count', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_count', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_count' + } + ] + }); + + /** + * Perform a [create](http://elasticsearch.org/guide/reference/api/index_/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.consistency + * @param {String} params.id + * @param {String} params.parent + * @param {String} params.percolate + * @param {Boolean} params.refresh + * @param {String} [params.replication=sync] + * @param {String} params.routing + * @param {Date|Number} params.timeout + * @param {Date|Number} params.timestamp + * @param {Duration} params.ttl + * @param {Number} params.version + * @param {String} params.version_type + */ + Client.prototype.create = ClientAction({ + name: 'create', + methods: [ + 'POST', + 'PUT' + ], + params: { + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + id: { + type: 'string' + }, + parent: { + type: 'string' + }, + percolate: { + type: 'string' + }, + refresh: { + type: 'boolean' + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + routing: { + type: 'string' + }, + timeout: { + type: 'time' + }, + timestamp: { + type: 'time' + }, + ttl: { + type: 'duration' + }, + version: { + type: 'number' + }, + version_type: { + type: 'enum', + options: [ + 'internal', + 'external' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>/_create', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/<%=type%>', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [delete](http://elasticsearch.org/guide/reference/api/delete/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.consistency + * @param {String} params.parent + * @param {Boolean} params.refresh + * @param {String} [params.replication=sync] + * @param {String} params.routing + * @param {Date|Number} params.timeout + * @param {Number} params.version + * @param {String} params.version_type + */ + Client.prototype['delete'] = ClientAction({ + name: 'delete', + methods: [ + 'DELETE' + ], + params: { + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + parent: { + type: 'string' + }, + refresh: { + type: 'boolean' + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + routing: { + type: 'string' + }, + timeout: { + type: 'time' + }, + version: { + type: 'number' + }, + version_type: { + type: 'enum', + options: [ + 'internal', + 'external' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [delete_by_query](http://www.elasticsearch.org/guide/reference/api/delete-by-query/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.analyzer + * @param {String} params.consistency + * @param {String} [params.default_operator=OR] + * @param {String} params.df + * @param {String} [params.ignore_indices=none] + * @param {String} [params.replication=sync] + * @param {String} params.q + * @param {String} params.routing + * @param {String} params.source + * @param {Date|Number} params.timeout + */ + Client.prototype.deleteByQuery = ClientAction({ + name: 'delete_by_query', + methods: [ + 'DELETE' + ], + params: { + analyzer: { + type: 'string' + }, + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + default_operator: { + type: 'enum', + 'default': 'OR', + options: [ + 'AND', + 'OR' + ] + }, + df: { + type: 'string' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + q: { + type: 'string' + }, + routing: { + type: 'string' + }, + source: { + type: 'string' + }, + timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_query', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_query', + req: { + index: { + type: 'list' + } + } + } + ] + }); + + /** + * Perform a [exists](http://elasticsearch.org/guide/reference/api/get/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.parent + * @param {String} params.preference + * @param {Boolean} params.realtime + * @param {Boolean} params.refresh + * @param {String} params.routing + */ + Client.prototype.exists = ClientAction({ + name: 'exists', + methods: [ + 'HEAD' + ], + params: { + parent: { + type: 'string' + }, + preference: { + type: 'string' + }, + realtime: { + type: 'boolean' + }, + refresh: { + type: 'boolean' + }, + routing: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>', + opt: { + type: { + type: 'string', + 'default': '_all' + } + }, + req: { + index: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ], + castNotFound: true + }); + + /** + * Perform a [explain](http://elasticsearch.org/guide/reference/api/explain/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.analyze_wildcard + * @param {String} params.analyzer + * @param {String} [params.default_operator=OR] + * @param {String} params.df + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {Boolean} params.lenient + * @param {Boolean} params.lowercase_expanded_terms + * @param {String} params.parent + * @param {String} params.preference + * @param {String} params.q + * @param {String} params.routing + * @param {String} params.source + * @param {String|ArrayOfStrings|Boolean} params._source + * @param {String|ArrayOfStrings|Boolean} params._source_exclude + * @param {String|ArrayOfStrings|Boolean} params._source_include + */ + Client.prototype.explain = ClientAction({ + name: 'explain', + methods: [ + 'GET', + 'POST' + ], + params: { + analyze_wildcard: { + type: 'boolean' + }, + analyzer: { + type: 'string' + }, + default_operator: { + type: 'enum', + 'default': 'OR', + options: [ + 'AND', + 'OR' + ] + }, + df: { + type: 'string' + }, + fields: { + type: 'list' + }, + lenient: { + type: 'boolean' + }, + lowercase_expanded_terms: { + type: 'boolean' + }, + parent: { + type: 'string' + }, + preference: { + type: 'string' + }, + q: { + type: 'string' + }, + routing: { + type: 'string' + }, + source: { + type: 'string' + }, + _source: { + type: 'list' + }, + _source_exclude: { + type: 'list' + }, + _source_include: { + type: 'list' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>/_explain', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [get](http://elasticsearch.org/guide/reference/api/get/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {String} params.parent + * @param {String} params.preference + * @param {Boolean} params.realtime + * @param {Boolean} params.refresh + * @param {String} params.routing + * @param {String|ArrayOfStrings|Boolean} params._source + * @param {String|ArrayOfStrings|Boolean} params._source_exclude + * @param {String|ArrayOfStrings|Boolean} params._source_include + */ + Client.prototype.get = ClientAction({ + name: 'get', + methods: [ + 'GET' + ], + params: { + fields: { + type: 'list' + }, + parent: { + type: 'string' + }, + preference: { + type: 'string' + }, + realtime: { + type: 'boolean' + }, + refresh: { + type: 'boolean' + }, + routing: { + type: 'string' + }, + _source: { + type: 'list' + }, + _source_exclude: { + type: 'list' + }, + _source_include: { + type: 'list' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>', + opt: { + type: { + type: 'string', + 'default': '_all' + } + }, + req: { + index: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [get_source](http://elasticsearch.org/guide/reference/api/get/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String|ArrayOfStrings|Boolean} params._source_exclude + * @param {String|ArrayOfStrings|Boolean} params._source_include + * @param {String} params.parent + * @param {String} params.preference + * @param {Boolean} params.realtime + * @param {Boolean} params.refresh + * @param {String} params.routing + */ + Client.prototype.getSource = ClientAction({ + name: 'get_source', + methods: [ + 'GET' + ], + params: { + _source_exclude: { + type: 'list' + }, + _source_include: { + type: 'list' + }, + parent: { + type: 'string' + }, + preference: { + type: 'string' + }, + realtime: { + type: 'boolean' + }, + refresh: { + type: 'boolean' + }, + routing: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>/_source', + opt: { + type: { + type: 'string', + 'default': '_all' + } + }, + req: { + index: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [index](http://elasticsearch.org/guide/reference/api/index_/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.consistency + * @param {String} [params.op_type=index] + * @param {String} params.parent + * @param {String} params.percolate + * @param {Boolean} params.refresh + * @param {String} [params.replication=sync] + * @param {String} params.routing + * @param {Date|Number} params.timeout + * @param {Date|Number} params.timestamp + * @param {Duration} params.ttl + * @param {Number} params.version + * @param {String} params.version_type + */ + Client.prototype.index = ClientAction({ + name: 'index', + methods: [ + 'POST', + 'PUT' + ], + params: { + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + op_type: { + type: 'enum', + 'default': 'index', + options: [ + 'index', + 'create' + ] + }, + parent: { + type: 'string' + }, + percolate: { + type: 'string' + }, + refresh: { + type: 'boolean' + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + routing: { + type: 'string' + }, + timeout: { + type: 'time' + }, + timestamp: { + type: 'time' + }, + ttl: { + type: 'duration' + }, + version: { + type: 'number' + }, + version_type: { + type: 'enum', + options: [ + 'internal', + 'external' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/<%=type%>', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.analyze](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.analyzer + * @param {String} params.field + * @param {String|ArrayOfStrings|Boolean} params.filters + * @param {String} params.index + * @param {Boolean} params.prefer_local + * @param {String} params.text + * @param {String} params.tokenizer + * @param {String} [params.format=detailed] + */ + Client.prototype.indices.prototype.analyze = ClientAction({ + name: 'indices.analyze', + methods: [ + 'GET', + 'POST' + ], + params: { + analyzer: { + type: 'string' + }, + field: { + type: 'string' + }, + filters: { + type: 'list' + }, + index: { + type: 'string' + }, + prefer_local: { + type: 'boolean' + }, + text: { + type: 'string' + }, + tokenizer: { + type: 'string' + }, + format: { + type: 'enum', + 'default': 'detailed', + options: [ + 'detailed', + 'text' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/_analyze', + req: { + index: { + type: 'string' + } + } + }, + { + fmt: '/_analyze' + } + ] + }); + + /** + * Perform a [indices.clear_cache](http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.field_data + * @param {Boolean} params.fielddata + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {Boolean} params.filter + * @param {Boolean} params.filter_cache + * @param {Boolean} params.filter_keys + * @param {Boolean} params.id + * @param {Boolean} params.id_cache + * @param {String} [params.ignore_indices=none] + * @param {String|ArrayOfStrings|Boolean} params.index + * @param {Boolean} params.recycler + */ + Client.prototype.indices.prototype.clearCache = ClientAction({ + name: 'indices.clear_cache', + methods: [ + 'POST', + 'GET' + ], + params: { + field_data: { + type: 'boolean' + }, + fielddata: { + type: 'boolean' + }, + fields: { + type: 'list' + }, + filter: { + type: 'boolean' + }, + filter_cache: { + type: 'boolean' + }, + filter_keys: { + type: 'boolean' + }, + id: { + type: 'boolean' + }, + id_cache: { + type: 'boolean' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + index: { + type: 'list' + }, + recycler: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/_cache/clear', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_cache/clear' + } + ] + }); + + /** + * Perform a [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.close = ClientAction({ + name: 'indices.close', + methods: [ + 'POST' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_close', + req: { + index: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.create = ClientAction({ + name: 'indices.create', + methods: [ + 'PUT', + 'POST' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>', + req: { + index: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype['delete'] = ClientAction({ + name: 'indices.delete', + methods: [ + 'DELETE' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/' + } + ] + }); + + /** + * Perform a [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.deleteAlias = ClientAction({ + name: 'indices.delete_alias', + methods: [ + 'DELETE' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_alias/<%=name%>', + req: { + index: { + type: 'string' + }, + name: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.delete_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.deleteMapping = ClientAction({ + name: 'indices.delete_mapping', + methods: [ + 'DELETE' + ], + params: { + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>', + req: { + index: { + type: 'list' + }, + type: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.deleteTemplate = ClientAction({ + name: 'indices.delete_template', + methods: [ + 'DELETE' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/_template/<%=name%>', + req: { + name: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.delete_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.deleteWarmer = ClientAction({ + name: 'indices.delete_warmer', + methods: [ + 'DELETE' + ], + params: { + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_warmer', + req: { + index: { + type: 'list' + } + } + } + ] + }); + + /** + * Perform a [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.indices.prototype.exists = ClientAction({ + name: 'indices.exists', + methods: [ + 'HEAD' + ], + params: {}, + urls: [ + { + fmt: '/<%=index%>', + req: { + index: { + type: 'list' + } + } + } + ], + castNotFound: true + }); + + /** + * Perform a [indices.exists_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + */ + Client.prototype.indices.prototype.existsAlias = ClientAction({ + name: 'indices.exists_alias', + methods: [ + 'HEAD' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/_alias/<%=name%>', + req: { + index: { + type: 'list' + }, + name: { + type: 'list' + } + } + }, + { + fmt: '/_alias/<%=name%>', + req: { + name: { + type: 'list' + } + } + } + ], + castNotFound: true + }); + + /** + * Perform a [indices.exists_type](http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + */ + Client.prototype.indices.prototype.existsType = ClientAction({ + name: 'indices.exists_type', + methods: [ + 'HEAD' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + } + ], + castNotFound: true + }); + + /** + * Perform a [indices.flush](http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.force + * @param {Boolean} params.full + * @param {String} [params.ignore_indices=none] + * @param {Boolean} params.refresh + */ + Client.prototype.indices.prototype.flush = ClientAction({ + name: 'indices.flush', + methods: [ + 'POST', + 'GET' + ], + params: { + force: { + type: 'boolean' + }, + full: { + type: 'boolean' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + refresh: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/_flush', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_flush' + } + ] + }); + + /** + * Perform a [indices.get_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + */ + Client.prototype.indices.prototype.getAlias = ClientAction({ + name: 'indices.get_alias', + methods: [ + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/_alias/<%=name%>', + req: { + index: { + type: 'list' + }, + name: { + type: 'list' + } + } + }, + { + fmt: '/_alias/<%=name%>', + req: { + name: { + type: 'list' + } + } + } + ] + }); + + /** + * Perform a [indices.get_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + */ + Client.prototype.indices.prototype.getAliases = ClientAction({ + name: 'indices.get_aliases', + methods: [ + 'GET' + ], + params: { + timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_aliases', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_aliases' + } + ] + }); + + /** + * Perform a [indices.get_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.indices.prototype.getMapping = ClientAction({ + name: 'indices.get_mapping', + methods: [ + 'GET' + ], + params: {}, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_mapping', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_mapping', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_mapping' + } + ] + }); + + /** + * Perform a [indices.get_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.indices.prototype.getSettings = ClientAction({ + name: 'indices.get_settings', + methods: [ + 'GET' + ], + params: {}, + urls: [ + { + fmt: '/<%=index%>/_settings', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_settings' + } + ] + }); + + /** + * Perform a [indices.get_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.indices.prototype.getTemplate = ClientAction({ + name: 'indices.get_template', + methods: [ + 'GET' + ], + params: {}, + urls: [ + { + fmt: '/_template/<%=name%>', + req: { + name: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.get_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.indices.prototype.getWarmer = ClientAction({ + name: 'indices.get_warmer', + methods: [ + 'GET' + ], + params: {}, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_warmer', + req: { + index: { + type: 'list' + } + } + } + ] + }); + + /** + * Perform a [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.open = ClientAction({ + name: 'indices.open', + methods: [ + 'POST' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_open', + req: { + index: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.optimize](http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.flush + * @param {String} [params.ignore_indices=none] + * @param {Number} params.max_num_segments + * @param {Boolean} params.only_expunge_deletes + * @param {*} params.operation_threading + * @param {Boolean} params.refresh + * @param {Boolean} params.wait_for_merge + */ + Client.prototype.indices.prototype.optimize = ClientAction({ + name: 'indices.optimize', + methods: [ + 'POST', + 'GET' + ], + params: { + flush: { + type: 'boolean' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + max_num_segments: { + type: 'number' + }, + only_expunge_deletes: { + type: 'boolean' + }, + operation_threading: {}, + refresh: { + type: 'boolean' + }, + wait_for_merge: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/_optimize', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_optimize' + } + ] + }); + + /** + * Perform a [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.putAlias = ClientAction({ + name: 'indices.put_alias', + methods: [ + 'PUT' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_alias/<%=name%>', + req: { + index: { + type: 'string' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/_alias/<%=name%>', + req: { + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_alias', + req: { + index: { + type: 'string' + } + } + }, + { + fmt: '/_alias' + } + ] + }); + + /** + * Perform a [indices.put_mapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.ignore_conflicts + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.putMapping = ClientAction({ + name: 'indices.put_mapping', + methods: [ + 'PUT', + 'POST' + ], + params: { + ignore_conflicts: { + type: 'boolean' + }, + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_mapping', + req: { + index: { + type: 'list' + }, + type: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.put_settings](http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.putSettings = ClientAction({ + name: 'indices.put_settings', + methods: [ + 'PUT' + ], + params: { + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/_settings', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_settings' + } + ] + }); + + /** + * Perform a [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Number} params.order + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.putTemplate = ClientAction({ + name: 'indices.put_template', + methods: [ + 'PUT', + 'POST' + ], + params: { + order: { + type: 'number' + }, + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/_template/<%=name%>', + req: { + name: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.put_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.putWarmer = ClientAction({ + name: 'indices.put_warmer', + methods: [ + 'PUT' + ], + params: { + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + }, + name: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_warmer/<%=name%>', + req: { + index: { + type: 'list' + }, + name: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [indices.refresh](http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + * @param {*} params.operation_threading + */ + Client.prototype.indices.prototype.refresh = ClientAction({ + name: 'indices.refresh', + methods: [ + 'POST', + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + operation_threading: {} + }, + urls: [ + { + fmt: '/<%=index%>/_refresh', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_refresh' + } + ] + }); + + /** + * Perform a [indices.segments](http://elasticsearch.org/guide/reference/api/admin-indices-segments/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + * @param {*} params.operation_threading + */ + Client.prototype.indices.prototype.segments = ClientAction({ + name: 'indices.segments', + methods: [ + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + operation_threading: {} + }, + urls: [ + { + fmt: '/<%=index%>/_segments', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_segments' + } + ] + }); + + /** + * Perform a [indices.snapshot_index](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + */ + Client.prototype.indices.prototype.snapshotIndex = ClientAction({ + name: 'indices.snapshot_index', + methods: [ + 'POST' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/_gateway/snapshot', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_gateway/snapshot' + } + ] + }); + + /** + * Perform a [indices.stats](http://elasticsearch.org/guide/reference/api/admin-indices-stats/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.all + * @param {Boolean} params.clear + * @param {Boolean} params.completion + * @param {String|ArrayOfStrings|Boolean} params.completion_fields + * @param {Boolean} params.docs + * @param {Boolean} params.fielddata + * @param {String|ArrayOfStrings|Boolean} params.fielddata_fields + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {Boolean} params.filter_cache + * @param {Boolean} params.flush + * @param {Boolean} params.get + * @param {Boolean} params.groups + * @param {Boolean} params.id_cache + * @param {String} [params.ignore_indices=none] + * @param {Boolean} params.indexing + * @param {Boolean} params.merge + * @param {Boolean} params.refresh + * @param {Boolean} params.search + * @param {Boolean} params.store + * @param {Boolean} params.warmer + */ + Client.prototype.indices.prototype.stats = ClientAction({ + name: 'indices.stats', + methods: [ + 'GET' + ], + params: { + all: { + type: 'boolean' + }, + clear: { + type: 'boolean' + }, + completion: { + type: 'boolean' + }, + completion_fields: { + type: 'list' + }, + docs: { + type: 'boolean' + }, + fielddata: { + type: 'boolean' + }, + fielddata_fields: { + type: 'list' + }, + fields: { + type: 'list' + }, + filter_cache: { + type: 'boolean' + }, + flush: { + type: 'boolean' + }, + get: { + type: 'boolean' + }, + groups: { + type: 'boolean' + }, + id_cache: { + type: 'boolean' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + indexing: { + type: 'boolean' + }, + merge: { + type: 'boolean' + }, + refresh: { + type: 'boolean' + }, + search: { + type: 'boolean' + }, + store: { + type: 'boolean' + }, + warmer: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/_stats', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_stats' + } + ] + }); + + /** + * Perform a [indices.status](http://elasticsearch.org/guide/reference/api/admin-indices-status/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + * @param {*} params.operation_threading + * @param {Boolean} params.recovery + * @param {Boolean} params.snapshot + */ + Client.prototype.indices.prototype.status = ClientAction({ + name: 'indices.status', + methods: [ + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + operation_threading: {}, + recovery: { + type: 'boolean' + }, + snapshot: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/_status', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_status' + } + ] + }); + + /** + * Perform a [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Date|Number} params.timeout + * @param {Date|Number} params.master_timeout + */ + Client.prototype.indices.prototype.updateAliases = ClientAction({ + name: 'indices.update_aliases', + methods: [ + 'POST' + ], + params: { + timeout: { + type: 'time' + }, + master_timeout: { + type: 'time' + } + }, + urls: [ + { + fmt: '/_aliases' + } + ] + }); + + /** + * Perform a [indices.validate_query](http://www.elasticsearch.org/guide/reference/api/validate/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.explain + * @param {String} [params.ignore_indices=none] + * @param {*} params.operation_threading + * @param {String} params.source + * @param {String} params.q + */ + Client.prototype.indices.prototype.validateQuery = ClientAction({ + name: 'indices.validate_query', + methods: [ + 'GET', + 'POST' + ], + params: { + explain: { + type: 'boolean' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + operation_threading: {}, + source: { + type: 'string' + }, + q: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_validate/query', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_validate/query', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_validate/query' + } + ] + }); + + /** + * Perform a [info](http://elasticsearch.org/guide/) request + * + * @param {Object} params - An object with parameters used to carry out this action + */ + Client.prototype.info = ClientAction({ + name: 'info', + methods: [ + 'GET', + 'HEAD' + ], + params: {}, + urls: [ + { + fmt: '/' + } + ] + }); + + /** + * Perform a [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {String} params.preference + * @param {Boolean} params.realtime + * @param {Boolean} params.refresh + * @param {String|ArrayOfStrings|Boolean} params._source + * @param {String|ArrayOfStrings|Boolean} params._source_exclude + * @param {String|ArrayOfStrings|Boolean} params._source_include + */ + Client.prototype.mget = ClientAction({ + name: 'mget', + methods: [ + 'GET', + 'POST' + ], + params: { + fields: { + type: 'list' + }, + preference: { + type: 'string' + }, + realtime: { + type: 'boolean' + }, + refresh: { + type: 'boolean' + }, + _source: { + type: 'list' + }, + _source_exclude: { + type: 'list' + }, + _source_include: { + type: 'list' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_mget', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + } + } + }, + { + fmt: '/<%=index%>/_mget', + req: { + index: { + type: 'string' + } + } + }, + { + fmt: '/_mget' + } + ] + }); + + /** + * Perform a [mlt](http://elasticsearch.org/guide/reference/api/more-like-this/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Number} params.boost_terms + * @param {Number} params.max_doc_freq + * @param {Number} params.max_query_terms + * @param {Number} params.max_word_len + * @param {Number} params.min_doc_freq + * @param {Number} params.min_term_freq + * @param {Number} params.min_word_len + * @param {String|ArrayOfStrings|Boolean} params.mlt_fields + * @param {Number} params.percent_terms_to_match + * @param {String} params.routing + * @param {Number} params.search_from + * @param {String|ArrayOfStrings|Boolean} params.search_indices + * @param {String} params.search_query_hint + * @param {String} params.search_scroll + * @param {Number} params.search_size + * @param {String} params.search_source + * @param {String} params.search_type + * @param {String|ArrayOfStrings|Boolean} params.search_types + * @param {String|ArrayOfStrings|Boolean} params.stop_words + */ + Client.prototype.mlt = ClientAction({ + name: 'mlt', + methods: [ + 'GET', + 'POST' + ], + params: { + boost_terms: { + type: 'number' + }, + max_doc_freq: { + type: 'number' + }, + max_query_terms: { + type: 'number' + }, + max_word_len: { + type: 'number' + }, + min_doc_freq: { + type: 'number' + }, + min_term_freq: { + type: 'number' + }, + min_word_len: { + type: 'number' + }, + mlt_fields: { + type: 'list' + }, + percent_terms_to_match: { + type: 'number' + }, + routing: { + type: 'string' + }, + search_from: { + type: 'number' + }, + search_indices: { + type: 'list' + }, + search_query_hint: { + type: 'string' + }, + search_scroll: { + type: 'string' + }, + search_size: { + type: 'number' + }, + search_source: { + type: 'string' + }, + search_type: { + type: 'string' + }, + search_types: { + type: 'list' + }, + stop_words: { + type: 'list' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>/_mlt', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [msearch](http://www.elasticsearch.org/guide/reference/api/multi-search/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.search_type + */ + Client.prototype.msearch = ClientAction({ + name: 'msearch', + methods: [ + 'GET', + 'POST' + ], + params: { + search_type: { + type: 'enum', + options: [ + 'query_then_fetch', + 'query_and_fetch', + 'dfs_query_then_fetch', + 'dfs_query_and_fetch', + 'count', + 'scan' + ] + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_msearch', + req: { + index: { + type: 'list' + }, + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_msearch', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_msearch' + } + ], + bulkBody: true + }); + + /** + * Perform a [percolate](http://elasticsearch.org/guide/reference/api/percolate/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.prefer_local + */ + Client.prototype.percolate = ClientAction({ + name: 'percolate', + methods: [ + 'GET', + 'POST' + ], + params: { + prefer_local: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_percolate', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + } + } + } + ] + }); + + /** + * Perform a [scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Duration} params.scroll + * @param {String} params.scroll_id + */ + Client.prototype.scroll = ClientAction({ + name: 'scroll', + methods: [ + 'GET', + 'POST' + ], + params: { + scroll: { + type: 'duration' + }, + scroll_id: { + type: 'string' + } + }, + urls: [ + { + fmt: '/_search/scroll/<%=scroll_id%>', + req: { + scroll_id: { + type: 'string' + } + } + }, + { + fmt: '/_search/scroll' + } + ] + }); + + /** + * Perform a [search](http://www.elasticsearch.org/guide/reference/api/search/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.analyzer + * @param {Boolean} params.analyze_wildcard + * @param {String} [params.default_operator=OR] + * @param {String} params.df + * @param {Boolean} params.explain + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {Number} params.from + * @param {String} [params.ignore_indices=none] + * @param {String|ArrayOfStrings|Boolean} params.indices_boost + * @param {Boolean} params.lenient + * @param {Boolean} params.lowercase_expanded_terms + * @param {String} params.preference + * @param {String} params.q + * @param {String|ArrayOfStrings|Boolean} params.routing + * @param {Duration} params.scroll + * @param {String} params.search_type + * @param {Number} params.size + * @param {String|ArrayOfStrings|Boolean} params.sort + * @param {String} params.source + * @param {String|ArrayOfStrings|Boolean} params._source + * @param {String|ArrayOfStrings|Boolean} params._source_exclude + * @param {String|ArrayOfStrings|Boolean} params._source_include + * @param {String|ArrayOfStrings|Boolean} params.stats + * @param {String} params.suggest_field + * @param {String} [params.suggest_mode=missing] + * @param {Number} params.suggest_size + * @param {Text} params.suggest_text + * @param {Date|Number} params.timeout + * @param {Boolean} params.version + */ + Client.prototype.search = ClientAction({ + name: 'search', + methods: [ + 'GET', + 'POST' + ], + params: { + analyzer: { + type: 'string' + }, + analyze_wildcard: { + type: 'boolean' + }, + default_operator: { + type: 'enum', + 'default': 'OR', + options: [ + 'AND', + 'OR' + ] + }, + df: { + type: 'string' + }, + explain: { + type: 'boolean' + }, + fields: { + type: 'list' + }, + from: { + type: 'number' + }, + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + indices_boost: { + type: 'list' + }, + lenient: { + type: 'boolean' + }, + lowercase_expanded_terms: { + type: 'boolean' + }, + preference: { + type: 'string' + }, + q: { + type: 'string' + }, + routing: { + type: 'list' + }, + scroll: { + type: 'duration' + }, + search_type: { + type: 'enum', + options: [ + 'query_then_fetch', + 'query_and_fetch', + 'dfs_query_then_fetch', + 'dfs_query_and_fetch', + 'count', + 'scan' + ] + }, + size: { + type: 'number' + }, + sort: { + type: 'list' + }, + source: { + type: 'string' + }, + _source: { + type: 'list' + }, + _source_exclude: { + type: 'list' + }, + _source_include: { + type: 'list' + }, + stats: { + type: 'list' + }, + suggest_field: { + type: 'string' + }, + suggest_mode: { + type: 'enum', + 'default': 'missing', + options: [ + 'missing', + 'popular', + 'always' + ] + }, + suggest_size: { + type: 'number' + }, + suggest_text: { + type: 'text' + }, + timeout: { + type: 'time' + }, + version: { + type: 'boolean' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/_search', + opt: { + index: { + type: 'list', + 'default': '_all' + } + }, + req: { + type: { + type: 'list' + } + } + }, + { + fmt: '/<%=index%>/_search', + opt: { + index: { + type: 'list', + 'default': '_all' + } + } + } + ] + }); + + /** + * Perform a [suggest](http://elasticsearch.org/guide/reference/api/search/suggest/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} [params.ignore_indices=none] + * @param {String} params.preference + * @param {String} params.routing + * @param {String} params.source + */ + Client.prototype.suggest = ClientAction({ + name: 'suggest', + methods: [ + 'POST', + 'GET' + ], + params: { + ignore_indices: { + type: 'enum', + 'default': 'none', + options: [ + 'none', + 'missing' + ] + }, + preference: { + type: 'string' + }, + routing: { + type: 'string' + }, + source: { + type: 'string' + } + }, + urls: [ + { + fmt: '/<%=index%>/_suggest', + req: { + index: { + type: 'list' + } + } + }, + { + fmt: '/_suggest' + } + ] + }); + + /** + * Perform a [update](http://elasticsearch.org/guide/reference/api/update/) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {String} params.consistency + * @param {String|ArrayOfStrings|Boolean} params.fields + * @param {String} params.lang + * @param {String} params.parent + * @param {String} params.percolate + * @param {Boolean} params.refresh + * @param {String} [params.replication=sync] + * @param {Number} params.retry_on_conflict + * @param {String} params.routing + * @param {*} params.script + * @param {Date|Number} params.timeout + * @param {Date|Number} params.timestamp + * @param {Duration} params.ttl + * @param {Number} params.version + * @param {Number} params.version_type + */ + Client.prototype.update = ClientAction({ + name: 'update', + methods: [ + 'POST' + ], + params: { + consistency: { + type: 'enum', + options: [ + 'one', + 'quorum', + 'all' + ] + }, + fields: { + type: 'list' + }, + lang: { + type: 'string' + }, + parent: { + type: 'string' + }, + percolate: { + type: 'string' + }, + refresh: { + type: 'boolean' + }, + replication: { + type: 'enum', + 'default': 'sync', + options: [ + 'sync', + 'async' + ] + }, + retry_on_conflict: { + type: 'number' + }, + routing: { + type: 'string' + }, + script: {}, + timeout: { + type: 'time' + }, + timestamp: { + type: 'time' + }, + ttl: { + type: 'duration' + }, + version: { + type: 'number' + }, + version_type: { + type: 'number' + } + }, + urls: [ + { + fmt: '/<%=index%>/<%=type%>/<%=id%>/_update', + req: { + index: { + type: 'string' + }, + type: { + type: 'string' + }, + id: { + type: 'string' + } + } + } + ] + }); + +}; \ No newline at end of file diff --git a/src/lib/client_action.js b/src/lib/client_action.js new file mode 100644 index 000000000..a8d90b896 --- /dev/null +++ b/src/lib/client_action.js @@ -0,0 +1,241 @@ +/** + * Constructs a function that can be called to make a request to ES + * @type {[type]} + */ +module.exports = function clientAction(spec) { + return function (params, cb) { + return exec(this.client, spec, params, cb); + } +}; + +var errors = require('./errors'); + +var _ = require('./utils'); +var urlParamRE = /\{(\w+)\}/g; + +function exec(client, spec, params, cb) { + if (typeof params === 'function') { + cb = params; + params = {}; + } else { + params = params || {}; + cb = typeof cb === 'function' ? cb : _.noop; + } + + var request = { + ignore: params.ignore + }; + var parts = {}; + var query = {}; + var i; + + if (spec.needsBody && !params.body) { + return _.nextTick(cb, new TyperError(spec.name + ' requires a request body.')); + } + + if (params.body) { + request.body = params.body; + request.bulkBody = spec.bulkBody; + } + + if (spec.methods.length === 1) { + request.method = spec.methods[0]; + } else { + // if set, uppercase the user's choice, other wise returns "" + request.method = _.toUpperString(params.method); + + if (request.method) { + // use the one specified as long as it's a valid option + if (!_.contains(spec.methods, request.method)) { + return _.nextTick(cb, new TypeError('Invalid method: should be one of ' + spec.methods.join(', '))); + } + } else { + // pick a method + if (request.body) { + // first method that isn't "GET" + request.method = spec.methodWithBody || ( + spec.methodWithBody = _.find(spec.methods, function (m) { return m !== 'GET'; }) + ); + } else { + // just use the first option + request.method = spec.methods[0]; + } + } + } + + if (spec.url) { + // only one url option + request.path = resolveUrl(spec.url, params); + } else { + for (i = 0; i < spec.urls.length; i++) { + if (request.path = resolveUrl(spec.urls[i], params)) { + break; + } + } + } + + if (!request.path) { + // there must have been some mimimun requirements that were not met + return _.nextTick( + cb, + new TypeError( + 'Unable to build a path with those params. Supply at least ' + + _.keys(spec.urls[spec.urls.length - 1].req).join(', ') + ) + ); + } + + // build the query string + if (!spec.paramKeys) { + // build a key list on demand + spec.paramKeys = _.keys(spec.params); + } + var key, param; + for (i = 0; i < spec.paramKeys.length; i++) { + key = spec.paramKeys[i]; + param = spec.params[key]; + try { + if (params[key] != null) { + query[key] = castType[param.type] ? castType[param.type](param, params[key], key) : params[key]; + if (param['default'] && query[key] === param['default']) { + delete query[key]; + } + } else if (param.required) { + throw new TypeError('Missing required parameter ' + key); + } + } catch (e) { + return _.nextTick(cb, e); + } + } + + request.path = request.path + _.makeQueryString(query); + + if (spec.castNotFound) { + client.request(request, function (err, response) { + if (err instanceof errors.NotFound) { + cb(null, false); + } else { + cb(err, !err); + } + }); + } else { + client.request(request, cb); + } +}; + +var castType = { + enum: function (param, val, name) { + if (_.contains(param.options, val)) { + return val; + } else { + throw new TypeError('Invalid ' + name + ': expected one of ' + param.options.join(',')); + } + }, + duration: function (param, val, name) { + if (_.isNumeric(val) || _.isInterval(val)) { + return val; + } else { + throw new TypeError( + 'Invalid ' + name + ': expected a number or interval ' + + '(an integer followed by one of Mwdhmsy).' + ); + } + }, + list: function (param, val, name) { + switch (typeof val) { + case 'string': + return val; + case 'object': + if (_.isArray(val)) { + return val.join(','); + } else { + throw new TypeError('Invalid ' + name + ': expected be a comma seperated list, array, or boolean.'); + } + break; + default: + return !!val; + } + }, + boolean: function (param, val, name) { + val = _.isString(val) ? val.toLowerCase() : val; + return (val === 'no' || val === 'off') ? false : !!val; + }, + number: function (param, val, name) { + if (_.isNumeric(val)) { + return val * 1; + } else { + throw new TypeError('Invalid ' + name + ': expected a number.'); + } + }, + string: function (param, val, name) { + if (typeof val !== 'object' && val) { + return '' + val; + } else { + throw new TypeError('Invalid ' + name + ': expected a string.'); + } + }, + time: function (param, val, name) { + if (val instanceof Date) { + return val.getTime(); + } else if (_.isNumeric(val)) { + return val; + } else { + throw new TypeError('Invalid ' + name + ': expected some sort of time.'); + } + } +}; + +function resolveUrl (url, params) { + var vars = {}, name, i, key; + + if (url.req) { + // url has required params + if (!url.reqParamKeys) { + // create cached key list on demand + url.reqParamKeys = _.keys(url.req); + } + + for (i = 0; i < url.reqParamKeys.length; i ++) { + key = url.reqParamKeys[i]; + if (!params.hasOwnProperty(key)) { + // missing a required param + return false; + } else { + // copy param vals into vars + vars[key] = params[key]; + } + } + } + + if (url.opt) { + // url has optional params + if (!url.optParamKeys) { + url.optParamKeys = _.keys(url.opt); + } + + for (i = 0; i < url.optParamKeys.length; i ++) { + key = url.optParamKeys[i]; + if (params[key]) { + if (castType[url.opt[key].type]) { + vars[key] = castType[url.opt[key].type](url.opt[key], params[key], key); + } else { + vars[key] = params[key]; + } + } else { + vars[key] = url.opt[key]['default']; + } + } + } + + if (!url.template) { + // compile the template on demand + url.template = _.template(url.fmt); + } + + return url.template(_.transform(vars, function (note, val, name) { + // encode each value + note[name] = encodeURIComponent(val); + // remove it from the params so that it isn't sent to the final request + delete params[name]; + }, {})); +}; diff --git a/src/lib/client_config.js b/src/lib/client_config.js index e8f5b3fe5..bd2af41ef 100644 --- a/src/lib/client_config.js +++ b/src/lib/client_config.js @@ -11,7 +11,6 @@ var _ = require('./utils'); var selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase); var connections = _.requireClasses(module, './connections'); var serializers = _.requireClasses(module, './serializers'); -var Transport = require('./transport'); var ConnectionPool = require('./connection_pool'); var Log = require('./log'); @@ -54,10 +53,6 @@ var defaultConfig = { function ClientConfig(config) { _.extend(this, defaultConfig, config); - if (typeof this.hosts !== 'object') { - this.hosts = [this.hosts]; - } - // validate connectionConstructor if (typeof this.connectionConstructor !== 'function') { if (_.has(connections, this.connectionConstructor)) { @@ -73,52 +68,76 @@ function ClientConfig(config) { if (_.has(selectors, this.selector)) { this.selector = selectors[this.selector]; } else { - throw new TypeError('Invalid Selector ' + this.selector + '. specify a function or one of ' + _.keys(selectors).join(', ')); + throw new TypeError('Invalid Selector ' + this.selector + '. ' + + 'Expected a function or one of ' + _.keys(selectors).join(', ')); } } - this.serializer = new serializers.Json(this); - this.hosts = _.map(this.hosts, this.transformHost); - + // currently not configurable because! this.log = new Log(this); - this.transport = new Transport(this); this.connectionPool = new ConnectionPool(this); + this.serializer = new serializers.Json(this); - this.transport.createConnections(this.hosts); - - if (this.randomizeHosts) { - this.connectionPool.connections.alive = _.shuffle(this.connectionPool.connections.alive); - } + // populate the connection pool + this.connectionPool.setNodes(this.prepareHosts(this.hosts)); + // nodes are completely managed by the connection pool, remove traces of the config + // value to prevent confusion + delete this.hosts; } -ClientConfig.prototype.transformHost = function (host) { - if (typeof host === 'object') { - if (host.protocol) { - // the protocol must end in a color - if (host.protocol[host.protocol.length - 1] !== ':') { - host.protocol = host.protocol + ':'; +ClientConfig.prototype.prepareHosts = function (hosts) { + var host; + var i; + + if (_.isArray(hosts)) { + hosts = [hosts]; + } + + for(i = 0; i < hosts.length; i++) { + host = hosts[i]; + if (typeof host === 'object') { + if (host.protocol) { + // the protocol must end in a color + if (host.protocol[host.protocol.length - 1] !== ':') { + host.protocol = host.protocol + ':'; + } + } else { + host.protocol = 'http:'; + } + + if (host.host && !host.hostname) { + // utl.format && url.parse uses "hostname" to represent just the name of the host, "host" is "hostname + port" + host.hostname = host.host; + delete host.host; + } + + if (!host.hostname) { + host.hostname = 'localhost'; + } + + if (!host.port) { + host.port = 9200; } } else { - host.protocol = 'http:'; - } + // assume it is a string. - if (host.host && !host.hostname) { - // utl.format && url.parse uses "hostname" to represent just the name of the host, "host" is "hostname + port" - host.hostname = host.host; - delete host.host; - } + if (!hostProtocolRE.test(host)) { + // add a defaul protocol + host = 'http://' + host; + } - return host; + // parse the url please, node + var urlInfo = url.parse(host, false, true); + + // override the host value + hosts[i] = { + protocol: urlInfo.protocol || 'http:', + hostname: urlInfo.hostname || 'localhost', + port: urlInfo.port || 9200 + }; + } } - if (!hostProtocolRE.test(host)) { - host = 'http://' + host; - } - var urlInfo = url.parse(host, false, true); - return { - protocol: urlInfo.protocol, - hostname: urlInfo.hostname, - port: urlInfo.port - }; + return hosts; }; diff --git a/src/lib/connection_pool.js b/src/lib/connection_pool.js index 1a94283a4..cf30e6893 100644 --- a/src/lib/connection_pool.js +++ b/src/lib/connection_pool.js @@ -41,15 +41,6 @@ ConnectionPool.prototype.select = function (cb) { } }; -ConnectionPool.prototype.empty = function () { - _.each(this.connection.dead, function (connection) { - connection.setStatus('closed'); - }); - _.each(this.connection.alive, function (connection) { - connection.setStatus('closed'); - }); -}; - ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus, connection) { var from, to, index; @@ -70,7 +61,6 @@ ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus break; case 'closed': from = this.connections[oldStatus]; - connection.removeListener('status changed', this.bound.onStatusChanged); break; } @@ -89,10 +79,45 @@ ConnectionPool.prototype.onStatusChanged = _.handler(function (status, oldStatus } }); -ConnectionPool.prototype.add = function (connection) { - if (!~this.connections.alive.indexOf(connection) && !~this.connections.dead.indexOf(connection)) { - connection.status = 'alive'; +ConnectionPool.prototype._add = function (connection) { + if (!this.index[connection.__id]) { + this.index[connection.__id] = connection; connection.on('status changed', this.bound.onStatusChanged); - this.connections.alive.push(connection); + connection.setStatus('alive'); } }; + +ConnectionPool.prototype._remove = function (connection) { + if (this.index[connection.__id]) { + delete this.index[connection.__id]; + connection.setStatus('closed'); + connection.removeListener('status changed', this.bound.onStatusChanged); + } +} + +ConnectionPool.prototype.setNodes = function (nodeConfigs) { + var i; + var connection; + var node; + var toRemove = _.clone(this.index); + for (i = 0; i < nodeConfigs.length; i++) { + node = nodeConfigs[i]; + if (node.hostname && node.port) { + id = node.hostname + ':' + node.port; + if (this.index[id]) { + delete toRemove[id]; + } else { + connection = new this.config.connectionConstructor(this.config, nodeConfigs[i]); + connection.__id = id; + this._add(connection); + } + } + } + + _.each(toRemove, this._remove, this); +} + + +ConnectionPool.prototype.empty = function () { + this.setNodes([]); +}; diff --git a/src/lib/connections/http.js b/src/lib/connections/http.js index 20e91d765..a36302c6e 100644 --- a/src/lib/connections/http.js +++ b/src/lib/connections/http.js @@ -86,12 +86,6 @@ HttpConnection.prototype.request = function (params, cb) { cleanUp = _.noop; }; - // ensure that "get" isn't being used with a request body - if (params.body && reqParams.method === 'GET') { - cleanUp(new TypeError('HTTP Method GET can not have a body')); - return; - } - reqParams.agent = this.agent; request = http.request(reqParams); diff --git a/src/lib/errors.js b/src/lib/errors.js index e316b0131..32095fd06 100644 --- a/src/lib/errors.js +++ b/src/lib/errors.js @@ -101,7 +101,7 @@ _.each(statusCodes, function (name, status) { var className = _.studlyCase(name); function StatusCodeError(msg) { - ErrorAbstract.call(this, msg || name, errors.StatusCodeError); + ErrorAbstract.call(this, msg || name, errors[className]); } _.inherits(StatusCodeError, ErrorAbstract); diff --git a/src/lib/utils.js b/src/lib/utils.js index 8e41609fd..f3d2c5203 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -15,6 +15,7 @@ var path = require('path'), * @static */ var utils = _.extend({}, _, nodeUtils); +_ = utils; utils.inspect = function (thing, opts) { return nodeUtils.inspect(thing, _.defaults(opts || {}, { @@ -33,23 +34,6 @@ utils.inspect = function (thing, opts) { */ utils.joinPath = path.join; -/** - * Extends lodash's map function so that objects can be passed to map and will be returned as an object with - * each value transformed by the iterator. - * - * @method utils.map - * @param [Collection] obj - the thing to iterate over - * @param [Function] mapper - the function to call for each element in obj - * @param [*] context - the this context to use for each call to mapper - */ -utils.map = function (obj, mapper, context) { - if (_.isPlainObject(obj)) { - return _.reduce(obj, function (note, val, key) { note[key] = mapper.call(context, val, key); return note; }, {}); - } else { - return _.map(obj, mapper, context); - } -}; - /** * Require all of the modules in a directory * @@ -400,9 +384,9 @@ utils.applyArgs = function (func, context, args, sliceIndex) { * when it is called. * @return {[type]} [description] */ -utils.nextTick = function (cb) { +_.nextTick = function (cb) { // bind the function and schedule it - process.nextTick(utils.bindKey(utils, 'applyArgs', cb, null, arguments, 1)); + process.nextTick(_.bindKey(_, 'applyArgs', cb, null, arguments, 1)); }; /** @@ -416,15 +400,15 @@ utils.nextTick = function (cb) { * }); * ``` * - * @alias utils.scheduled + * @alias _.scheduled * @param {Function} func - The method that is being defined * @return {Function} */ -utils.handler = function (func) { +_.handler = function (func) { func._provideBound = true; return func; }; -utils.scheduled = utils.handler; +_.scheduled = _.handler; /** * Creates an "bound" property on an object, which all or a subset of methods from @@ -443,28 +427,28 @@ utils.scheduled = utils.handler; * @param {Object} obj - The object to bind the methods to * @param {Array} [methods] - The methods to bind, false values === bind them all */ -utils.makeBoundMethods = function (obj, methods) { +_.makeBoundMethods = function (obj, methods) { obj.bound = {}; if (!methods) { methods = []; for (var prop in obj) { // dearest maintainer, we want to look through the prototype if (typeof obj[prop] === 'function' && obj[prop]._provideBound === true) { - obj.bound[prop] = utils.bind(obj[prop], obj); + obj.bound[prop] = _.bind(obj[prop], obj); } } } else { _.each(methods, function (method) { - obj.bound[method] = utils.bindKey(obj, method); + obj.bound[method] = _.bindKey(obj, method); }); } }; -utils.noop = function () {}; +_.noop = function () {}; -utils.getStackTrace = function (callee) { +_.getStackTrace = function (callee) { var e = {}; - Error.captureStackTrace(e, callee || utils.getStackTrace); + Error.captureStackTrace(e, callee || _.getStackTrace); return '\n' + e.stack.split('\n').slice(1).join('\n'); }; diff --git a/scripts/generate/js_api/aliases.js b/tasks/generate/js_api/aliases.js similarity index 100% rename from scripts/generate/js_api/aliases.js rename to tasks/generate/js_api/aliases.js diff --git a/tasks/generate/js_api/index.js b/tasks/generate/js_api/index.js new file mode 100644 index 000000000..521658b58 --- /dev/null +++ b/tasks/generate/js_api/index.js @@ -0,0 +1,120 @@ +var _ = require('../../../src/lib/utils'); +var asset = require('assert'); +var path = require('path'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); + +var outputDir = _.joinPath(__dirname, '../../../src/api/'); + +var templates = require('./templates'); +var specs = require('./spec')(outputDir); + +// completely delete the output directory +function clean(path) { + if (fs.existsSync(path)) { + fs.readdirSync(path).forEach(function (file, index) { + var curPath = path + '/' + file; + if (fs.statSync(curPath).isDirectory()) { // recurse + clean(curPath); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } +} + +exports.run = function () { + var defs = []; + var namespaces = []; + + var actions = _.map(specs, function (spec) { + spec.urls = _.map( + _.sortBy( + _.transform(spec.urls, function (note, url, i) { + var optionalVars = {}; + var requiredVars = {}; + var param; + var target; + var urlParamRE = /\{(\w+)\}/g; + + if (url.charAt(0) !== '/') { + url = '/' + url; + } + + while (match = urlParamRE.exec(url)) { + param = spec.urlParts[match[1]] || {}; + target = (param.required || !param.default) ? requiredVars : optionalVars; + target[match[1]] = _.omit(param, 'required'); + } + + [requiredVars, optionalVars].forEach(function (vars) { + _.each(vars, function (v, name) { + vars[name] = _.omit(v, 'description'); + }) + }) + + note.push(_.omit({ + fmt: url.replace(urlParamRE, '<%=$1%>'), + opt: _.size(optionalVars) ? optionalVars : null, + req: _.size(requiredVars) ? requiredVars : null, + sortOrder: _.size(requiredVars) * -1 + }, function (v) { return !v; })); + }, []) + , 'sortOrder') + , function (url) { + return _.omit(url, 'sortOrder'); + }); + + var docUrl = spec.docUrl; + + spec = _.pick(spec, [ + 'name', + 'methods', + 'params', + 'urls', + 'needBody', + 'bulkBody', + 'castNotFound' + ]); + + spec.params = _.transform(spec.params, function (note, param, name) { + param.name = name; + note[name] = _.pick(param, [ + 'type', 'default', 'options', 'required' + ]); + }, {}); + + var location = _.map(spec.name.split('.'), _.camelCase).join('.'); + if (~location.indexOf('.')) { + var steps = location.split('.'); + namespaces.push(steps.slice(0, -1).join('.')); + location = steps.join('.prototype.'); + } + + // escape method names with "special" keywords + location = location.replace(/(^|\.)(delete|default)(\.|$)/g, '[\'$2\']'); + + return templates.clientAction({spec: spec, location: location, docUrl: docUrl }); + }); + + namespaces = _.map(_.unique(namespaces.sort(), true), function (namespace) { + return templates.clientActionNamespace({ + get: namespace, + set: namespace.replace(/\./g, '.prototype.'), + }); + }) + + + var l = templates.lines(0); + l('var ClientAction = require(\'./client_action\');'); + l('var errors = require(\'./errors\');'); + l(''); + l('exports.attach = function (Client) {').in(); + l.split(namespaces.join('') + '\n' + actions.join('\n')); + l.out('};'); + + fs.writeFileSync(_.joinPath(__dirname, '../../../src/lib/api.js'), l.toString()); +}; + +exports.run(); diff --git a/scripts/generate/js_api/notes.js b/tasks/generate/js_api/notes.js similarity index 100% rename from scripts/generate/js_api/notes.js rename to tasks/generate/js_api/notes.js diff --git a/tasks/generate/js_api/spec.js b/tasks/generate/js_api/spec.js new file mode 100644 index 000000000..e61100cf6 --- /dev/null +++ b/tasks/generate/js_api/spec.js @@ -0,0 +1,54 @@ +var _ = require('../../../src/lib/utils') + +var docs = _.requireDir(module, '../../../es_api_spec/api'); +var aliases = require('./aliases'); +var notes = require('./notes'); + +var castNotFoundRE = /exists/; +var usesBulkBodyRE = /^(bulk|msearch)$/; + +var defs = []; + +// itterate all of the found docs +Object.keys(docs).forEach(function (filename) { + Object.keys(docs[filename]).forEach(function (name) { + var def = docs[filename][name]; + def.name = name; + defs.push(def); + }) +}); + +module.exports = function (outputDir) { + return _.map(defs, function (def) { + var name = def.name; + var steps = name.split('.'); + + var spec = { + fileName: steps.pop() + '.js', + dirName: _.joinPath(outputDir, steps.join('/') || './'), + name: name, + methods: _.map(def.methods, function (m) { return m.toUpperCase(); }), + docUrl: def.documentation, + urlParts: def.url.parts, + params: def.url.params, + urls: _.difference(def.url.paths, aliases[name]), + body: def.body || null, + path2lib: _.repeat('../', steps.length + 1) + 'lib/', + notes: notes[name], + }; + + if (def.body && def.body.requires) { + spec.needBody = true; + } + + if (usesBulkBodyRE.test(name)) { + spec.bulkBody = true; + } + + if (castNotFoundRE.test(name)) { + spec.castNotFound = true; + } + + return spec; + }); +}; diff --git a/scripts/generate/js_api/templates/action.tmpl b/tasks/generate/js_api/templates/action.tmpl similarity index 88% rename from scripts/generate/js_api/templates/action.tmpl rename to tasks/generate/js_api/templates/action.tmpl index 69a1cec06..d75624ac9 100644 --- a/scripts/generate/js_api/templates/action.tmpl +++ b/tasks/generate/js_api/templates/action.tmpl @@ -1,6 +1,6 @@ -var _ = require('<%= path2lib %>utils'), - errors = require('<%= path2lib %>errors'), - q = require('q');<% +var _ = require('<%= path2lib %>utils'); +var errors = require('<%= path2lib %>errors'); +var q = require('q');<% if (_.keys(enumOptions).length) { @@ -32,11 +32,11 @@ function do<%= _.studlyCase(name) %>(params, cb) { } var request = { -<%= writeRequestObjectBody(6, name, body, methods) %> - }, - parts = {}, - query = {}, - responseOpts = {}; +<%= writeRequestObjectBody(4, name, body, methods) %> + }; + var parts = {}; + var query = {}; + var responseOpts = {}; <% if (methods.length > 1) { %> diff --git a/scripts/generate/js_api/templates/any.param.tmpl b/tasks/generate/js_api/templates/any.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/any.param.tmpl rename to tasks/generate/js_api/templates/any.param.tmpl diff --git a/scripts/generate/js_api/templates/boolean.param.tmpl b/tasks/generate/js_api/templates/boolean.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/boolean.param.tmpl rename to tasks/generate/js_api/templates/boolean.param.tmpl diff --git a/tasks/generate/js_api/templates/client_action.tmpl b/tasks/generate/js_api/templates/client_action.tmpl new file mode 100644 index 000000000..e6684db76 --- /dev/null +++ b/tasks/generate/js_api/templates/client_action.tmpl @@ -0,0 +1,12 @@ +/** + * Perform a [<%= spec.name %>](<%= docUrl %>) request + * + * @param {Object} params - An object with parameters used to carry out this action<% +_.each(spec.params, function(param, paramName) { %> + * @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><% + if (param.description) { + %> - <%= param.description %><% + } +%><% }) %> + */ +Client.prototype<%= (location[0] === '[' ? '' : '.') + location %> = ClientAction(<%= stringify(spec, true) %>); diff --git a/tasks/generate/js_api/templates/client_action_namespace.tmpl b/tasks/generate/js_api/templates/client_action_namespace.tmpl new file mode 100644 index 000000000..01b82f48a --- /dev/null +++ b/tasks/generate/js_api/templates/client_action_namespace.tmpl @@ -0,0 +1 @@ +Client.namespace(<%= stringify(get) %>); diff --git a/scripts/generate/js_api/templates/duration.param.tmpl b/tasks/generate/js_api/templates/duration.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/duration.param.tmpl rename to tasks/generate/js_api/templates/duration.param.tmpl diff --git a/scripts/generate/js_api/templates/enum.param.tmpl b/tasks/generate/js_api/templates/enum.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/enum.param.tmpl rename to tasks/generate/js_api/templates/enum.param.tmpl diff --git a/scripts/generate/js_api/templates/index.js b/tasks/generate/js_api/templates/index.js similarity index 79% rename from scripts/generate/js_api/templates/index.js rename to tasks/generate/js_api/templates/index.js index 107e6c32c..63b54e9d7 100644 --- a/scripts/generate/js_api/templates/index.js +++ b/tasks/generate/js_api/templates/index.js @@ -26,7 +26,7 @@ function lines(i) { l.indent = i || 0; l.split = function (toSplit) { - _.each(_.filter(toSplit.split(/\r|\n/)), l); + _.each(toSplit.split(/\r?\n/), l); return l; }; @@ -47,15 +47,26 @@ function lines(i) { return l; } -function stringify(thing) { - return JSON.stringify(thing) - .replace('\'', '\\\'') +/** + * we want strings in code to use single-quotes, so this will JSON encode vars, but then + * modify them to follow our code standards. + * + * @param {*} thing - Any thing + * @return {String} - our pretty string + */ +function stringify(thing, pretty) { + return (pretty ? JSON.stringify(thing, null, ' ') : JSON.stringify(thing)) + .replace(/\'/g, '\\\'') .replace(/\\?"/g, function (quote) { // replace external (unescaped) double quotes with single quotes return quote === '\\"' ? '"' : '\''; }) - // inject a space between array parts - .replace(/([^\\])','/g, '$1\', \''); + // inject a space between STRING array parts + .replace(/([^\\])','/g, '$1\', \'') + // remove quotes around key names that are only made up of letters + .replace(/^( +)'([a-zA-Z_]+)':/gm, '$1$2:') + // requote "special" key names + .replace(/^( +)(default):/gm, '$1\'$2\':') } /** @@ -94,6 +105,34 @@ var templateGlobals = { return l.toString(); }, + writeBrowserParams: function (indent, params, namespace) { + var l = lines(indent); + + _.each(params, function (param, name) { + if (!param.required) { + l('if (_.has(params, ' + stringify(name) + ')) {').in(); + } + switch (param.type) { + case 'enum': + l( + namespace + name + ' = _.' + + (param.type || 'any') + 'Param(params.' + name + ', ' + stringify(param.options) + + ');' + ); + break; + default: + l(namespace + name + ' = _.' + (param.type || 'any') + 'Param(params.' + name + ');'); + break; + } + if (!param.required) { + l.out('}'); + } + l(''); + }); + + return l.toString(); + }, + writeUrls: function (indent, urls, urlParams, queryStringParams) { var l = lines(indent); @@ -136,7 +175,7 @@ var templateGlobals = { var requiredVars = _.filter(vars, urlVarIsRequired); var condition = _.map(requiredVars, function (v) { - return 'parts.hasOwnProperty(\'' + v.name + '\')'; + return 'parts.' + v.name + ')'; }).join(' && '); l((urlIndex > 0 ? 'else ' : '') + (condition ? 'if (' + condition + ') ' : '') + '{') @@ -188,13 +227,6 @@ var templateGlobals = { return l.toString(); }, - /** - * we want strings in code to use single-quotes, so this will JSON encode vars, but then - * modify them to follow our code standards. - * - * @param {*} thing - Any thing - * @return {String} - our pretty string - */ stringify: stringify, _: _, @@ -210,7 +242,7 @@ var templateGlobals = { case 'list': return 'String|ArrayOfStrings|Boolean'; default: - return type; + return _.ucfirst(type); } }, @@ -256,6 +288,9 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) { templates.text = templates.string; module.exports = { + lines: lines, action: templates.action, + clientAction: templates.client_action, + clientActionNamespace: templates.client_action_namespace, urlParamRE: urlParamRE }; diff --git a/scripts/generate/js_api/templates/list.param.tmpl b/tasks/generate/js_api/templates/list.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/list.param.tmpl rename to tasks/generate/js_api/templates/list.param.tmpl diff --git a/scripts/generate/js_api/templates/number.param.tmpl b/tasks/generate/js_api/templates/number.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/number.param.tmpl rename to tasks/generate/js_api/templates/number.param.tmpl diff --git a/scripts/generate/js_api/templates/string.param.tmpl b/tasks/generate/js_api/templates/string.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/string.param.tmpl rename to tasks/generate/js_api/templates/string.param.tmpl diff --git a/scripts/generate/js_api/templates/time.param.tmpl b/tasks/generate/js_api/templates/time.param.tmpl similarity index 100% rename from scripts/generate/js_api/templates/time.param.tmpl rename to tasks/generate/js_api/templates/time.param.tmpl diff --git a/test/integration/network-failures/timeout.js b/test/integration/network-failures/timeout.js index 238fcba6e..1cd04821f 100644 --- a/test/integration/network-failures/timeout.js +++ b/test/integration/network-failures/timeout.js @@ -21,7 +21,7 @@ describe('overall timeout for the network connections', function () { res.writeHead(200); - res.on('close', function() { + res.on('close', function () { clearInterval(dataInterval); clearTimeout(finTimeout); }); diff --git a/test/integration/yaml-suite/args.js b/test/integration/yaml-suite/args.js deleted file mode 100644 index db83624d2..000000000 --- a/test/integration/yaml-suite/args.js +++ /dev/null @@ -1,11 +0,0 @@ -var program = require('commander'); - -program - .version('0.0.1') - .option('-c, --clusterName [name]', 'Set the name of the "cluster" this node will start', 'yaml_test_runners') - .option('-n, --nodeName [name]', 'Set the node\'s name', 'yaml_runner') - .option('-p, --httpPort [port]', 'Set the port for this node', 9299) - .option('-d, --dataPath [path]', 'Do not set this', '/tmp/yaml-test-data') - .parse(process.argv); - -module.exports = program; diff --git a/test/integration/yaml-suite/index.js b/test/integration/yaml-suite/index.js index 787dd5a03..6d448e07d 100644 --- a/test/integration/yaml-suite/index.js +++ b/test/integration/yaml-suite/index.js @@ -33,7 +33,7 @@ var client = null; var logFile = path.resolve(__dirname, './log'); // empty all of the indices in ES please -function clearIndices (done) { +function clearIndices(done) { client.indices.delete({ index: '*', ignore: 404 @@ -75,11 +75,12 @@ before(function () { port: esServer ? esServer.__port : argv.port } ], - log: { - type: 'file', - level: ['error', 'warning', 'trace'], - path: logFile - } + log: null + // log: { + // type: 'file', + // level: ['error', 'warning', 'trace'], + // path: logFile + // } }); }); @@ -155,7 +156,7 @@ function versionToComparableString(version) { return (new Array(4 - part.length)).join('0') + part; }); - while(parts.length < 3) { + while (parts.length < 3) { parts.push('000'); } @@ -196,7 +197,7 @@ function loadFile(location) { var docsInFile = []; jsYaml.loadAll( - fs.readFileSync(location, { encoding:'utf8' }), + fs.readFileSync(location, { encoding: 'utf8' }), function (testConfig) { docsInFile.push(testConfig); }, @@ -305,7 +306,7 @@ ActionRunner.prototype = { // do a single level flatten, merge=ing the nested arrays from step one // into a master array, creating an array of action objects - return _.reduce(actionSets, function(note, set) { + return _.reduce(actionSets, function (note, set) { return note.concat(set); }, []); }, @@ -318,7 +319,7 @@ ActionRunner.prototype = { */ each: function (ittr) { var action; - while(action = this._actions.shift()) { + while (action = this._actions.shift()) { if (ittr(action.testable, action.name) === false) { break; } @@ -350,7 +351,7 @@ ActionRunner.prototype = { get: function (path, from) { var i - , log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {} ; + , log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {}; if (!from) { if (path[0] === '$') { @@ -410,7 +411,7 @@ ActionRunner.prototype = { var catcher; // resolve the catch arg to a value used for matching once the request is complete - switch(args.catch) { + switch (args.catch) { case void 0: catcher = null; break; @@ -441,14 +442,11 @@ ActionRunner.prototype = { var action = Object.keys(args).pop() , clientActionName = _.map(action.split('.'), _.camelCase).join('.') , clientAction = this.get(clientActionName, client) - , params = _.map(args[action], function (val, name) { - if (typeof val === 'string' && val[0] === '$') { - return this.get(val); - } - return val; - }, this); + , params = _.transform(args[action], function (note, val, name) { + note[name] = (typeof val === 'string' && val[0] === '$') ? this.get(val) : val; + }, {}, this); - expect(clientAction, clientActionName).to.be.a('function'); + expect(clientAction || clientActionName).to.be.a('function'); if (typeof clientAction === 'function') { if (_.isNumeric(catcher)) { @@ -459,7 +457,7 @@ ActionRunner.prototype = { clientAction.call(client, params, _.bind(function (error, body, status) { this._last_requests_response = body; - if (error){ + if (error) { if (catcher) { if (catcher instanceof RegExp) { // error message should match the regexp diff --git a/test/integration/yaml-suite/log b/test/integration/yaml-suite/log deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/unit/es_server.test.js b/test/unit/es_server.test.js index 47d53145a..05b14cc79 100644 --- a/test/unit/es_server.test.js +++ b/test/unit/es_server.test.js @@ -18,7 +18,7 @@ describe('EsServer Mock', function () { var port; function makeRequest(opts, respCb) { - opts = _.defaults(opts || {},{ + opts = _.defaults(opts || {}, { hostname: 'localhost', port: port }); @@ -28,7 +28,7 @@ describe('EsServer Mock', function () { response = ''; incomming.on('data', function (chunk) { - response+= chunk; + response += chunk; }); incomming.on('end', function () { diff --git a/test/unit/toolbelt.test.js b/test/unit/toolbelt.test.js index 56415a823..46a2e0257 100644 --- a/test/unit/toolbelt.test.js +++ b/test/unit/toolbelt.test.js @@ -118,8 +118,8 @@ describe('Utils', function () { describe('#map', function () { it('returns an object when passed an object', function () { - var out = _.map({a:1, b:2}, function (val) { return val * 2; }); - expect(out).to.eql({a:2, b:4}); + var out = _.map({a: 1, b: 2}, function (val) { return val * 2; }); + expect(out).to.eql({a: 2, b: 4}); }); it('returns an array for anything else', function () { @@ -181,7 +181,7 @@ describe('Utils', function () { it('returns the same object that was passed', function () { var obj = { - foo:'bar' + foo: 'bar' }; expect(_.deepMerge(obj, { bar: 'baz' })).to.eql(obj); }); @@ -204,7 +204,7 @@ describe('Utils', function () { it('works recursively', function () { var obj = { - foo:'bar', + foo: 'bar', bax: { foo: ['bax', 'boz'] }