yaml tests passing using a personl instance of ES, working on specifying the host/port
This commit is contained in:
11
package.json
11
package.json
@ -12,15 +12,16 @@
|
||||
"grunt-contrib-concat": "~0.3.0",
|
||||
"grunt-contrib-jshint": "~0.6.0",
|
||||
"grunt-contrib-nodeunit": "~0.2.0",
|
||||
"should": "~1.3.0",
|
||||
"nodeunit": "~0.8.1",
|
||||
"js-yaml": "~2.1.0",
|
||||
"mkdirp": "~0.3.5",
|
||||
"yuidoc-bootstrap-theme": "git://github.com/spenceralger/yuidoc-bootstrap-theme.git#master",
|
||||
"grunt-contrib-yuidoc": "~0.5.0",
|
||||
"grunt-simple-mocha": "~0.4.0",
|
||||
"mocha": "~1.13.0",
|
||||
"mocha-as-promised": "~1.4.0"
|
||||
"mocha-as-promised": "~1.4.0",
|
||||
"moment": "~2.2.1",
|
||||
"should": "~2.0.1",
|
||||
"sinon": "~1.7.3"
|
||||
},
|
||||
"license": "Apache License",
|
||||
"dependencies": {
|
||||
@ -28,7 +29,9 @@
|
||||
"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",
|
||||
"expect.js": "~0.2.0"
|
||||
"async": "~0.2.9",
|
||||
"optimist": "~0.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../src/lib/toolbelt')
|
||||
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/')
|
||||
, docs = _.requireDir(module, '../../../es_api_spec/api')
|
||||
, outputDir = _.joinPath(__dirname, '../../../src/api/')
|
||||
, templates = require('./templates')
|
||||
, notes = require('./notes')
|
||||
, aliases = require('./aliases');
|
||||
@ -35,7 +35,7 @@ _.each(docs, function (doc) {
|
||||
|
||||
var spec = {
|
||||
name: name,
|
||||
methods: _.map(def.methods, function (m) { return m.toLowerCase(); }),
|
||||
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||
docUrl: def.documentation,
|
||||
urlParts: def.url.parts,
|
||||
params: def.url.params,
|
||||
2
scripts/generate/js_api/notes.js
Normal file
2
scripts/generate/js_api/notes.js
Normal file
@ -0,0 +1,2 @@
|
||||
// exports['cluster.node_info'] =
|
||||
// '//TODO: this enpoint ***needs*** work, many of the possible urls are not supported';
|
||||
@ -1,5 +1,7 @@
|
||||
var _ = require('<%= path2lib %>toolbelt')
|
||||
, paramHelper = require('<%= path2lib %>param_helper');<%
|
||||
var _ = require('<%= path2lib %>utils'),
|
||||
paramHelper = require('<%= path2lib %>param_helper'),
|
||||
errors = require('<%= path2lib %>errors'),
|
||||
q = require('q');<%
|
||||
|
||||
|
||||
if (_.keys(enumOptions).length) {
|
||||
@ -11,9 +13,6 @@ var <%= name %>Options = <%= stringify(options) %>;<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%= notes ? notes + '\n' : ''
|
||||
%>
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [<%= name %>](<%= docUrl %>) request
|
||||
*
|
||||
@ -24,7 +23,7 @@ var <%= name %>Options = <%= stringify(options) %>;<%
|
||||
})
|
||||
%>
|
||||
*/
|
||||
function do<%= _.studlyCase(name) %>(params, callback) {
|
||||
function do<%= _.studlyCase(name) %>(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {<%
|
||||
@ -39,22 +38,22 @@ function do<%= _.studlyCase(name) %>(params, callback) {
|
||||
body: params.body || null<%
|
||||
} }%>
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
<%
|
||||
|
||||
if (methods.length > 1) { %>
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method = _.toUpperString(params.method)) {
|
||||
if (<%= _.map(methods, function (method) { return 'params.method === ' + stringify(method) }).join(' || ') %>) {
|
||||
request.method = params.method;
|
||||
} else {
|
||||
throw new TypeError('Invalid method: should be one of <%= methods.join(', ') %>');
|
||||
}
|
||||
} else {<%
|
||||
if (_.contains(methods, 'get')) {
|
||||
var nonGet = _.find(methods, function (m) {return m !== 'get'; });%>
|
||||
request.method = params.body ? <%= stringify(nonGet) %> : 'get';<%
|
||||
if (_.contains(methods, 'GET')) {
|
||||
var nonGet = _.find(methods, function (m) {return m !== 'GET'; });%>
|
||||
request.method = params.body ? <%= stringify(nonGet) %> : 'GET';<%
|
||||
} else {%>
|
||||
request.method = <%= stringify(methods[0]) %>;<%
|
||||
}%>
|
||||
@ -64,21 +63,17 @@ if (methods.length > 1) { %>
|
||||
}
|
||||
%>
|
||||
|
||||
// find the url's params
|
||||
<%= writeParams(2, urlParts, 'url.') %>
|
||||
// find the paths's params
|
||||
<%= writeParams(2, urlParts, 'parts.') %>
|
||||
|
||||
// build the url
|
||||
// build the path
|
||||
<%= writeUrls(2, urls, urlParts, params) %>
|
||||
|
||||
// build the query string
|
||||
<%= writeParams(2, params, 'query.') %>
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
<%= returnStatement(2, name) %>
|
||||
}
|
||||
|
||||
module.exports = do<%= _.studlyCase(name) %>;
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
var _ = require('../../../src/lib/toolbelt')
|
||||
var _ = require('../../../../src/lib/utils')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, urlParamRE = /\{(\w+)\}/g;
|
||||
@ -13,7 +13,9 @@ var _ = require('../../../src/lib/toolbelt')
|
||||
function lines(i) {
|
||||
|
||||
function l(line) {
|
||||
l.lines.push(_.repeat(' ', l.indent) + line);
|
||||
if (typeof line !== 'undefined') {
|
||||
l.lines.push(_.repeat(' ', l.indent) + line);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@ -25,14 +27,14 @@ function lines(i) {
|
||||
return l;
|
||||
};
|
||||
|
||||
l.in = function () {
|
||||
l.in = function (line) {
|
||||
l.indent += 2;
|
||||
return l;
|
||||
return l(line);
|
||||
};
|
||||
|
||||
l.out = function () {
|
||||
l.out = function (line) {
|
||||
l.indent -= 2;
|
||||
return l;
|
||||
return l(line);
|
||||
};
|
||||
|
||||
l.toString = function () {
|
||||
@ -109,14 +111,14 @@ var templateGlobals = {
|
||||
// collect the vars from the url and replace them to form the js that will build the url
|
||||
var makeL = lines(), vars = [];
|
||||
|
||||
makeL('request.url = \'' + url.replace(urlParamRE, function (match, varName) {
|
||||
makeL('request.path = \'' + url.replace(urlParamRE, function (match, varName) {
|
||||
var varDetails = urlParams[varName];
|
||||
varDetails.name = varName;
|
||||
vars.push(varDetails);
|
||||
if (urlVarIsRequired(varDetails)) {
|
||||
return '\' + encodeURIComponent(url.' + varName + ') + \'';
|
||||
return '\' + encodeURIComponent(parts.' + varName + ') + \'';
|
||||
} else {
|
||||
return '\' + encodeURIComponent(url.' + varName + ' || ' + stringify(varDetails.default) + ') + \'';
|
||||
return '\' + encodeURIComponent(parts.' + varName + ' || ' + stringify(varDetails.default) + ') + \'';
|
||||
}
|
||||
}) + '\';');
|
||||
|
||||
@ -131,17 +133,20 @@ var templateGlobals = {
|
||||
var requiredVars = _.filter(vars, urlVarIsRequired);
|
||||
|
||||
var condition = _.map(requiredVars, function (v) {
|
||||
return 'url.hasOwnProperty(\'' + v.name + '\')';
|
||||
return 'parts.hasOwnProperty(\'' + v.name + '\')';
|
||||
}).join(' && ');
|
||||
|
||||
l((urlIndex > 0 ? 'else ' : '') + (condition ? 'if (' + condition + ') ' : '') + '{').in();
|
||||
l.split(makeL.toString()).out();
|
||||
l('}');
|
||||
l((urlIndex > 0 ? 'else ' : '') + (condition ? 'if (' + condition + ') ' : '') + '{')
|
||||
.in()
|
||||
.split(makeL.toString())
|
||||
.out('}');
|
||||
|
||||
if (urlIndex === urls.length - 1 && condition) {
|
||||
l('else {').in();
|
||||
l('throw new TypeError(\'Unable to build a url with those params. Supply at least ' + vars.join(', ') + '\');').out();
|
||||
l('}');
|
||||
l('else {')
|
||||
.in('throw new TypeError(\'Unable to build a path with those params. Supply at least ' +
|
||||
vars.join(', ') + '\');'
|
||||
)
|
||||
.out('}');
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -185,6 +190,22 @@ var templateGlobals = {
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
},
|
||||
|
||||
returnStatement: function (indent, name) {
|
||||
var l = lines(indent);
|
||||
if (name.match(/(^|\.)exists/)) {
|
||||
l('this.client.request(request, function (err, response) {')
|
||||
.in('if (err instanceof errors.NotFound) {')
|
||||
.in('cb(err, false);')
|
||||
.out('} else {')
|
||||
.in('cb(err, true);')
|
||||
.out('}')
|
||||
.out('});');
|
||||
} else {
|
||||
l('this.client.request(request, cb);');
|
||||
}
|
||||
return l.toString();
|
||||
}
|
||||
};
|
||||
|
||||
155
scripts/generate/logs/index.js
Normal file
155
scripts/generate/logs/index.js
Normal file
@ -0,0 +1,155 @@
|
||||
// args
|
||||
var count = parseInt(process.argv[2] || 14000, 10),
|
||||
days = parseInt(process.argv[3] || 7, 10);
|
||||
|
||||
var es = require('../../../src/elasticsearch'),
|
||||
_ = require('../../../src/lib/utils'),
|
||||
q = require('q'),
|
||||
async = require('async'),
|
||||
moment = require('moment'),
|
||||
makeSamples = require('./samples').make,
|
||||
startingMoment = moment().startOf('day').subtract('days', days),
|
||||
endingMoment = moment().endOf('day').add('days', days),
|
||||
client = new es.Client({
|
||||
log: 'info'
|
||||
});
|
||||
|
||||
client.log.info('Generating', count, 'events across ±', days, 'days');
|
||||
|
||||
fillIndecies(function () {
|
||||
var actions = [],
|
||||
samples = makeSamples(startingMoment, endingMoment);
|
||||
|
||||
async.timesSeries(count, function (i, done) {
|
||||
// random date, plus less random time
|
||||
var date = moment(samples.randomMsInDayRange())
|
||||
.utc()
|
||||
.startOf('day')
|
||||
.add('milliseconds', samples.lessRandomMsInDay());
|
||||
|
||||
var event = {
|
||||
index: date.format('[logstash-]YYYY.MM.DD'),
|
||||
'@timestamp': date.toISOString(),
|
||||
ip: samples.ips(),
|
||||
extension: samples.extensions(),
|
||||
response: samples.responseCodes(),
|
||||
country: samples.countries(),
|
||||
point: samples.airports(),
|
||||
'@tags': [samples.tags(), samples.tags2()],
|
||||
utc_time: date.toISOString(),
|
||||
referer: 'http://' + samples.referrers() + '/' + samples.tags() + '/' + samples.astronauts(),
|
||||
agent: samples.userAgents(),
|
||||
};
|
||||
|
||||
event.clientip = event.ip;
|
||||
event.bytes = event.response < 500 ? samples.lessRandomRespSize() : 0;
|
||||
event.request = '/' + samples.astronauts() + '.' + event.extension;
|
||||
event.memory = event.extension === 'php' ? event.bytes * 40 : 0;
|
||||
if (event.memory) {
|
||||
event.phpmemory = event.memory;
|
||||
}
|
||||
|
||||
event['@message'] = event.ip + ' - - [' + date.toISOString() + '] "GET ' + event.request + ' HTTP/1.1" ' +
|
||||
event.respCode + ' ' + event.respSize + ' "-" "' + event.agent + '"';
|
||||
event.src = JSON.stringify(event, null, ' ');
|
||||
|
||||
actions.push({
|
||||
index: {
|
||||
_index: event.index,
|
||||
_type: samples.types(),
|
||||
_id: i
|
||||
}
|
||||
});
|
||||
actions.push(event);
|
||||
|
||||
if (actions.length === 3000 || i === count - 1) {
|
||||
client.log.info('writing', actions.length / 2, 'documents');
|
||||
client.bulk({
|
||||
body: actions
|
||||
}, done);
|
||||
actions = [];
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
console.log('Done!');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fillIndecies(cb) {
|
||||
var movingDate = moment(startingMoment);
|
||||
var indexBody = {
|
||||
mappings: {
|
||||
_default_: {
|
||||
properties: {
|
||||
'@timestamp': {
|
||||
type: 'date',
|
||||
index: 'not_analyzed'
|
||||
},
|
||||
id: {
|
||||
type: 'integer',
|
||||
index: 'not_analyzed',
|
||||
include_in_all: false
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
index: 'not_analyzed'
|
||||
},
|
||||
agent: {
|
||||
type: 'multi_field',
|
||||
fields: {
|
||||
agent: {
|
||||
type: 'string',
|
||||
index: 'analyzed'
|
||||
},
|
||||
raw: {
|
||||
type: 'string',
|
||||
index: 'not_analyzed'
|
||||
}
|
||||
}
|
||||
},
|
||||
ip: {
|
||||
type: 'ip'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
indexPushActions = [];
|
||||
|
||||
function createDateIndex(indexName) {
|
||||
return function (done) {
|
||||
client.indices.create({
|
||||
ignore: 400,
|
||||
index: indexName,
|
||||
body: indexBody
|
||||
}, function (err, resp) {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
done(null, resp.error ? 'existed' : 'created');
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
while (movingDate.unix() < endingMoment.unix()) {
|
||||
indexPushActions.push(createDateIndex(movingDate.format('[logstash-]YYYY.MM.DD')));
|
||||
movingDate.add('day', 1);
|
||||
}
|
||||
|
||||
async.parallel(indexPushActions, function (err, responses) {
|
||||
if (err) {
|
||||
client.log.error(err);
|
||||
} else {
|
||||
_.each(_.groupBy(responses), function (list, did) {
|
||||
client.log.info(list.length, 'indicies', did);
|
||||
});
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
3369
scripts/generate/logs/samples/airports.js
Normal file
3369
scripts/generate/logs/samples/airports.js
Normal file
File diff suppressed because it is too large
Load Diff
559
scripts/generate/logs/samples/astronauts.js
Normal file
559
scripts/generate/logs/samples/astronauts.js
Normal file
@ -0,0 +1,559 @@
|
||||
module.exports = [
|
||||
'Joseph M. Acaba',
|
||||
'Loren Acton',
|
||||
'Mike Adams',
|
||||
'James Adamson',
|
||||
'Viktor M. Afanasyev',
|
||||
'Thomas Akers',
|
||||
'Vladimir Aksyonov',
|
||||
'Gemini 12',
|
||||
'Aleksandar Panayotov Aleksandrov',
|
||||
'Aleksandr Pavlovich Aleksandrov',
|
||||
'Andrew M. Allen',
|
||||
'Joseph P. Allen',
|
||||
'Scott Altman',
|
||||
'Apollo 8',
|
||||
'Clayton Anderson',
|
||||
'Michael P. Anderson',
|
||||
'Claudie Haigneré',
|
||||
'Dominic A. Antonelli',
|
||||
'Jerome Apt',
|
||||
'Lee Archambault',
|
||||
'Gemini 8',
|
||||
'Richard R. Arnold',
|
||||
'Anatoly Artsebarsky',
|
||||
'Yuri Artyukhin',
|
||||
'Jeffrey Ashby',
|
||||
'Oleg Atkov',
|
||||
'Toktar Aubakirov',
|
||||
'Sergei Avdeyev',
|
||||
'James P. Bagian',
|
||||
'Ellen S. Baker',
|
||||
'Michael Baker',
|
||||
'Aleksandr Balandin',
|
||||
'Michael R. Barratt',
|
||||
'Daniel Barry',
|
||||
'John-David F. Bartoe',
|
||||
'Charlie Bassett',
|
||||
'Yuri Baturin',
|
||||
'Patrick Baudry',
|
||||
'Apollo 12',
|
||||
'Robert L. Behnken',
|
||||
'Ivan Bella',
|
||||
'Pavel Belyayev',
|
||||
'Georgi Beregovoi',
|
||||
'Anatoli Berezovoy',
|
||||
'John Blaha',
|
||||
'Michael J. Bloomfield',
|
||||
'Guion Bluford',
|
||||
'Karol Bobko',
|
||||
'Eric A. Boe',
|
||||
'Charles Bolden',
|
||||
'Roberta Bondar',
|
||||
'Valentin Bondarenko',
|
||||
'Andrei Borisenko',
|
||||
'Gemini 7',
|
||||
'Stephen G. Bowen',
|
||||
'Kenneth Bowersox',
|
||||
'Charles E. Brady, Jr.',
|
||||
'Vance Brand',
|
||||
'Daniel Brandenstein',
|
||||
'Randolph Bresnik',
|
||||
'Roy Bridges',
|
||||
'Curtis Brown',
|
||||
'David M. Brown',
|
||||
'Mark Brown',
|
||||
'James Buchli',
|
||||
'Jay C. Buckey',
|
||||
'Nikolai Budarin',
|
||||
'John S. Bull',
|
||||
'Daniel Burbank',
|
||||
'Daniel Bursch',
|
||||
'Valery Bykovsky',
|
||||
'Robert D. Cabana',
|
||||
'Yvonne Cagle',
|
||||
'Fernando Caldeiro',
|
||||
'Charles Camarda',
|
||||
'Kenneth D. Cameron',
|
||||
'Duane G. Carey',
|
||||
'Scott Carpenter',
|
||||
'Gerald P. Carr',
|
||||
'Sonny Carter',
|
||||
'John Casper',
|
||||
'Christopher Cassidy',
|
||||
'Robert J. Cenker',
|
||||
'Gemini 9A',
|
||||
'Roger B. Chaffee',
|
||||
'Gregory Chamitoff',
|
||||
'Franklin Chang-Diaz',
|
||||
'Philip K. Chapman',
|
||||
'Kalpana Chawla',
|
||||
'Maurizio Cheli',
|
||||
'Chen Quan',
|
||||
'Leroy Chiao',
|
||||
'Kevin P. Chilton',
|
||||
'Jean-Loup Chrétien',
|
||||
'Laurel B. Clark',
|
||||
'Mary L. Cleave',
|
||||
'Jean-François Clervoy',
|
||||
'Michael R. Clifford',
|
||||
'Michael Coats',
|
||||
'Kenneth Cockrell',
|
||||
'Catherine Coleman',
|
||||
'Eileen Collins',
|
||||
'',
|
||||
'Gordon Cooper',
|
||||
'Richard O. Covey',
|
||||
'Timothy Creamer',
|
||||
'John O. Creighton',
|
||||
'Robert Crippen',
|
||||
'Samantha Cristoforetti',
|
||||
'Roger K. Crouch',
|
||||
'Frank L. Culbertson, Jr.',
|
||||
'Walter Cunningham',
|
||||
'Robert Curbeam',
|
||||
'Nancy J. Currie',
|
||||
'Nancy Jan Davis',
|
||||
'Lawrence J. DeLucas',
|
||||
'Frank De Winne',
|
||||
'Vladimir N. Dezhurov',
|
||||
'Georgi Dobrovolski',
|
||||
'Takao Doi',
|
||||
'B. Alvin Drew',
|
||||
'Brian Duffy',
|
||||
'Apollo 16',
|
||||
'Bonnie J. Dunbar',
|
||||
'Pedro Duque',
|
||||
'Samuel T. Durrance',
|
||||
'James Dutton',
|
||||
'Lev Dyomin',
|
||||
'Tracy Caldwell Dyson',
|
||||
'Vladimir Dzhanibekov',
|
||||
'Joe Edwards',
|
||||
'Donn F. Eisele',
|
||||
'Anthony W. England',
|
||||
'Joe H. Engle',
|
||||
'Apollo 17',
|
||||
'Reinhold Ewald',
|
||||
'Léopold Eyharts',
|
||||
'John Fabian',
|
||||
'Muhammed Faris',
|
||||
'Bertalan Farkas',
|
||||
'Jean-Jacques Favier',
|
||||
'Fèi Jùnlóng',
|
||||
'Konstantin Feoktistov',
|
||||
'Christopher Ferguson',
|
||||
'Martin J. Fettman',
|
||||
'Andrew J. Feustel',
|
||||
'Anatoly Filipchenko',
|
||||
'Michael Fincke',
|
||||
'John L. Finley',
|
||||
'Anna Lee Fisher',
|
||||
'William Frederick Fisher',
|
||||
'Klaus-Dietrich Flade',
|
||||
'Michael Foale',
|
||||
'Kevin A. Ford',
|
||||
'Michael Foreman',
|
||||
'Patrick Forrester',
|
||||
'Michael Fossum',
|
||||
'Ted Freeman',
|
||||
'Stephen Frick',
|
||||
'Dirk Frimout',
|
||||
'Christer Fuglesang',
|
||||
'Charles Fullerton',
|
||||
'Reinhard Furrer',
|
||||
'Satoshi Furukawa',
|
||||
'F. Drew Gaffney',
|
||||
'Yuri Gagarin',
|
||||
'Ronald Garan',
|
||||
'Dale Gardner',
|
||||
'Guy Gardner',
|
||||
'Marc Garneau',
|
||||
'Owen Garriott',
|
||||
'Charles Gemar',
|
||||
'Michael Gernhardt',
|
||||
'Alexander Gerst',
|
||||
'Edward Gibson',
|
||||
'Robert L. Gibson',
|
||||
'Yuri Gidzenko',
|
||||
'Ed Givens',
|
||||
'Yuri Glazkov',
|
||||
'John Glenn',
|
||||
'Linda Godwin',
|
||||
'Michael T. Good',
|
||||
'Viktor Gorbatko',
|
||||
'Gemini 11',
|
||||
'Dominic Gorie',
|
||||
'Ronald Grabe',
|
||||
'Duane Graveline',
|
||||
'Georgi Grechko',
|
||||
'Frederick Gregory',
|
||||
'William Gregory',
|
||||
'David Griggs',
|
||||
'Virgil I. "Gus" Grissom',
|
||||
'John Grunsfeld',
|
||||
'Aleksei Gubarev',
|
||||
'Umberto Guidoni',
|
||||
'Zhugderdemidiyn Gurragcha',
|
||||
'Sidney Gutierrez',
|
||||
'Chris Hadfield',
|
||||
'Jean-Pierre Haigneré',
|
||||
'Apollo 13',
|
||||
'James Halsell',
|
||||
'Kenneth Ham',
|
||||
'Lloyd Hammond',
|
||||
'Jeremy Hansen',
|
||||
'Gregory Harbaugh',
|
||||
'Bernard A. Harris, Jr.',
|
||||
'Terry Hart',
|
||||
'Henry Hartsfield',
|
||||
'Frederick Hauck',
|
||||
'Steven Hawley',
|
||||
'Susan Helms',
|
||||
'Karl Henize',
|
||||
'Thomas Hennen',
|
||||
'Terence Henricks',
|
||||
'Miroslaw Hermaszewski',
|
||||
'José Hernández',
|
||||
'John Herrington',
|
||||
'Richard Hieb',
|
||||
'Joan Higginbotham',
|
||||
'David Hilmers',
|
||||
'Kathryn Hire',
|
||||
'Charles Hobaugh',
|
||||
'Jeffrey Hoffman',
|
||||
'Donald Holmquest',
|
||||
'Michael S. Hopkins',
|
||||
'Scott Horowitz',
|
||||
'Akihiko Hoshide',
|
||||
'Millie Hughes-Fulford',
|
||||
'Douglas G. Hurley',
|
||||
'Rick Husband',
|
||||
'Apollo 15',
|
||||
'Aleksandr Ivanchenkov',
|
||||
'Anatoli Ivanishin',
|
||||
'Georgi Ivanov',
|
||||
'Marsha Ivins',
|
||||
'Sigmund Jähn',
|
||||
'Mae Jemison',
|
||||
'Tamara E. Jernigan',
|
||||
'Brent W. Jett, Jr.',
|
||||
'Jing Haipeng',
|
||||
'Gregory C. Johnson',
|
||||
'Gregory H. Johnson',
|
||||
'Thomas D. Jones',
|
||||
'Leonid Kadenyuk',
|
||||
'Alexander Kaleri',
|
||||
'Janet L. Kavandi',
|
||||
'James M. Kelly',
|
||||
'Mark Kelly',
|
||||
'Scott Kelly',
|
||||
'Joseph Kerwin',
|
||||
'Yevgeny Khrunov',
|
||||
'Robert S. Kimbrough',
|
||||
'Leonid Kizim',
|
||||
'Petr Klimuk',
|
||||
'Pyotr Kolodin',
|
||||
'Vladimir Komarov',
|
||||
'Yelena Kondakova',
|
||||
'Dmitri Kondratyev',
|
||||
'Oleg Kononenko',
|
||||
'Timothy L. Kopra',
|
||||
'Mikhail Korniyenko',
|
||||
'Valery Korzun',
|
||||
'Oleg Kotov',
|
||||
'Vladimir Kovalyonok',
|
||||
'Konstantin Kozeyev',
|
||||
'Kevin Kregel',
|
||||
'Sergei Krikalev',
|
||||
'Valeri Kubasov',
|
||||
'André Kuipers',
|
||||
'Aleksandr Laveykin',
|
||||
'Robert Lawrence',
|
||||
'Wendy Lawrence',
|
||||
'Vasili Lazarev',
|
||||
'Aleksandr Lazutkin',
|
||||
'Valentin Lebedev',
|
||||
'Mark C. Lee',
|
||||
'David Leestma',
|
||||
'William B. Lenoir',
|
||||
'Aleksei Leonov',
|
||||
'Frederick W. Leslie',
|
||||
'Anatoli Levchenko',
|
||||
'Byron Lichtenberg',
|
||||
'Don Lind',
|
||||
'Steven Lindsey',
|
||||
'Jerry Linenger',
|
||||
'Richard Linnehan',
|
||||
'Gregory Linteris',
|
||||
'Liu Boming',
|
||||
'Liu Wang',
|
||||
'Liu Yang',
|
||||
'Yáng Lìwěi',
|
||||
'Anthony Llewellyn',
|
||||
'Paul Lockhart',
|
||||
'Yuri Lonchakov',
|
||||
'Michael Lopez-Alegria',
|
||||
'Christopher Loria',
|
||||
'John Lounge',
|
||||
'Jack Lousma',
|
||||
'Stanley G. Love',
|
||||
'G. David Low',
|
||||
'Edward Lu',
|
||||
'Shannon Lucid',
|
||||
'Vladimir Lyakhov',
|
||||
'Steven MacLean',
|
||||
'Sandra Magnus',
|
||||
'Oleg Makarov',
|
||||
'Yuri Malenchenko',
|
||||
'Franco Malerba',
|
||||
'Yuri Malyshev',
|
||||
'Gennadi Manakov',
|
||||
'Musa Manarov',
|
||||
'Ravish Malhotra',
|
||||
'Thomas Marshburn',
|
||||
'Michael Massimino',
|
||||
'Richard Mastracchio',
|
||||
'K. Megan McArthur',
|
||||
'William S. McArthur',
|
||||
'Jon McBride',
|
||||
'Bruce McCandless II',
|
||||
'William C. McCool',
|
||||
'Michael McCulley',
|
||||
'James McDivitt',
|
||||
'Donald McMonagle',
|
||||
'Ronald McNair',
|
||||
'Carl Meade',
|
||||
'Bruce Melnick',
|
||||
'Pamela Melroy',
|
||||
'Leland D. Melvin',
|
||||
'Ulf Merbold',
|
||||
'Ernst Messerschmid',
|
||||
'Dorothy M. Metcalf-Lindenburger',
|
||||
'Curt Michel',
|
||||
'Aleksandr Misurkin',
|
||||
'Apollo 14',
|
||||
'Andreas Mogensen',
|
||||
'Abdul Ahad Mohmand',
|
||||
'Mamoru Mohri',
|
||||
'Barbara Morgan',
|
||||
'Lee Morin',
|
||||
'Boris Morukov',
|
||||
'Chiaki Mukai',
|
||||
'Richard Mullane',
|
||||
'Talgat Musabayev',
|
||||
'Story Musgrave',
|
||||
'Steven R. Nagel',
|
||||
'George Nelson',
|
||||
'Grigori Nelyubov',
|
||||
'Rodolfo Neri Vela',
|
||||
'Paolo A. Nespoli',
|
||||
'James H. Newman',
|
||||
'Claude Nicollier',
|
||||
'Niè Hǎishèng',
|
||||
'Andriyan Nikolayev',
|
||||
'Soichi Noguchi',
|
||||
'Carlos I. Noriega',
|
||||
'Oleg Novitskiy',
|
||||
'Lisa Nowak',
|
||||
'Karen Nyberg',
|
||||
'Bryan O\'Connor',
|
||||
'Ellen Ochoa',
|
||||
'Wubbo Ockels',
|
||||
'William Oefelein',
|
||||
'Brian O\'Leary',
|
||||
'John D. Olivas',
|
||||
'Takuya Onishi',
|
||||
'Ellison Onizuka',
|
||||
'Yuri Onufrienko',
|
||||
'Stephen Oswald',
|
||||
'Robert Overmyer',
|
||||
'Gennady Padalka',
|
||||
'William Pailes',
|
||||
'Scott Parazynski',
|
||||
'Ronald A. Parise',
|
||||
'Robert Parker',
|
||||
'Luca Parmitano',
|
||||
'Nicholas Patrick',
|
||||
'Viktor Patsayev',
|
||||
'James Pawelczyk',
|
||||
'Julie Payette',
|
||||
'Gary Payton',
|
||||
'Timothy Peake',
|
||||
'Philippe Perrin',
|
||||
'Thomas Pesquet',
|
||||
'Donald Peterson',
|
||||
'Donald Pettit',
|
||||
'Pham Tuan',
|
||||
'John Phillips',
|
||||
'William Pogue',
|
||||
'Alan G. Poindexter',
|
||||
'Mark Polansky',
|
||||
'Alexander Poleshchuk',
|
||||
'Valeri Polyakov',
|
||||
'Marcos Pontes',
|
||||
'Leonid Popov',
|
||||
'Pavel Popovich',
|
||||
'Charles Precourt',
|
||||
'Dumitru Prunariu',
|
||||
'Ilan Ramon',
|
||||
'William Readdy',
|
||||
'Kenneth Reightler',
|
||||
'James F. Reilly',
|
||||
'Garrett Reisman',
|
||||
'Thomas Reiter',
|
||||
'Vladimír Remek',
|
||||
'Judith Resnik',
|
||||
'Sergei Revin',
|
||||
'Paul W. Richards',
|
||||
'Richard N. Richards',
|
||||
'Sally Ride',
|
||||
'Patricia Robertson',
|
||||
'Stephen Robinson',
|
||||
'Russell L. Rogers',
|
||||
'Roman Romanenko',
|
||||
'Yuri Romanenko',
|
||||
'Kent Rominger',
|
||||
'Jerry L. Ross',
|
||||
'Valery Rozhdestvensky',
|
||||
'Nikolay Rukavishnikov',
|
||||
'Mario Runco, Jr.',
|
||||
'Sergei Ryazanski',
|
||||
'Valery Ryumin',
|
||||
'Albert Sacco',
|
||||
'David Saint-Jacques',
|
||||
'Aleksandr Samokutyayev',
|
||||
'Gennadi Sarafanov',
|
||||
'Robert Satcher',
|
||||
'Sultan bin Salman bin Abdulaziz Al Saud',
|
||||
'Viktor Savinykh',
|
||||
'Svetlana Savitskaya',
|
||||
'Wally Schirra',
|
||||
'Hans Schlegel',
|
||||
'Rusty Schweickart',
|
||||
'Dick Scobee',
|
||||
'Winston Scott',
|
||||
'Paul Scully-Power',
|
||||
'Richard Searfoss',
|
||||
'Rhea Seddon',
|
||||
'Elliot See',
|
||||
'Ronald Sega',
|
||||
'Piers Sellers',
|
||||
'Aleksandr Serebrov',
|
||||
'Vitali Sevastyanov',
|
||||
'Yuri Shargin',
|
||||
'Salizhan Sharipov',
|
||||
'Rakesh Sharma',
|
||||
'Vladimir Shatalov',
|
||||
'Brewster Shaw',
|
||||
'Mercury-Redstone 3',
|
||||
'William Shepherd',
|
||||
'Nancy Currie',
|
||||
'Anton Shkaplerov',
|
||||
'Georgi Shonin',
|
||||
'Loren Shriver',
|
||||
'Sheikh Muszaphar Shukor',
|
||||
'Oleg Skripochka',
|
||||
'Aleksandr Skvortsov',
|
||||
'Donald "Deke" Slayton',
|
||||
'Michael J. Smith',
|
||||
'Steven Smith',
|
||||
'Anatoly Solovyev',
|
||||
'Vladimir Solovyov',
|
||||
'Voskhod 1',
|
||||
'Sherwood Spring',
|
||||
'Robert Springer',
|
||||
'Gemini 6A',
|
||||
'Heidemarie Stefanyshyn-Piper',
|
||||
'Robert Stewart',
|
||||
'Susan Still Kilrain',
|
||||
'Nicole Marie Passonno Stott',
|
||||
'Krasimir Stoyanov',
|
||||
'Gennady Strekalov',
|
||||
'Frederick Sturckow',
|
||||
'Kathryn Sullivan',
|
||||
'Maksim Surayev',
|
||||
'Steven Swanson',
|
||||
'Arnaldo Tamayo Méndez',
|
||||
'Daniel Tani',
|
||||
'Joseph Tanner',
|
||||
'Evgeny Tarelkin',
|
||||
'MOL',
|
||||
'Valentina Tereshkova',
|
||||
'Norman Thagard',
|
||||
'Gerhard Thiele',
|
||||
'Robert Thirsk',
|
||||
'Andrew Thomas',
|
||||
'Donald Thomas',
|
||||
'Stephen Thorne',
|
||||
'Kathryn Thornton',
|
||||
'William E. Thornton',
|
||||
'Pierre Thuot',
|
||||
'Gherman Titov',
|
||||
'Vladimir Titov',
|
||||
'Michel Tognini',
|
||||
'Valery Tokarev',
|
||||
'Sergei Treshchov',
|
||||
'Eugene Trinh',
|
||||
'Richard Truly',
|
||||
'Bjarni Tryggvason',
|
||||
'Vasili Tsibliyev',
|
||||
'Mikhail Tyurin',
|
||||
'Yury Usachov',
|
||||
'Lodewijk van den Berg',
|
||||
'James "Ox" van Hoften',
|
||||
'Vladimir Vasyutin',
|
||||
'Charles Veach',
|
||||
'Franz Viehböck',
|
||||
'Alexander Viktorenko',
|
||||
'Pavel Vinogradov',
|
||||
'Terry Virts',
|
||||
'Roberto Vittori',
|
||||
'Igor Volk',
|
||||
'Alexander Volkov',
|
||||
'Sergey Volkov',
|
||||
'Vladislav Volkov',
|
||||
'Boris Volynov',
|
||||
'James Voss',
|
||||
'Janice Voss',
|
||||
'Koichi Wakata',
|
||||
'Rex Walheim',
|
||||
'Charles D. Walker',
|
||||
'David M. Walker',
|
||||
'Joseph A. Walker',
|
||||
'Shannon Walker',
|
||||
'Ulrich Walter',
|
||||
'Carl Walz',
|
||||
'Taylor Wang',
|
||||
'Wang Yaping',
|
||||
'Mary Weber',
|
||||
'Paul Weitz',
|
||||
'James Wetherbee',
|
||||
'Douglas Wheelock',
|
||||
'Edward White',
|
||||
'Peggy Whitson',
|
||||
'Terrence Wilcutt',
|
||||
'Clifton Williams',
|
||||
'Dafydd Williams',
|
||||
'Donald Williams',
|
||||
'Jeffrey Williams',
|
||||
'Sunita "Suni" Williams',
|
||||
'Barry Wilmore',
|
||||
'Stephanie Wilson',
|
||||
'Peter Wisoff',
|
||||
'David Wolf',
|
||||
'Neil Woodward',
|
||||
'Naoko Yamazaki',
|
||||
'Boris Yegorov',
|
||||
'Aleksei Yeliseyev',
|
||||
'Yi So-yeon',
|
||||
'Gemini 3',
|
||||
'Kimiya Yui',
|
||||
'Fyodor Yurchikhin',
|
||||
'Sergei Zalyotin',
|
||||
'George D. Zamka',
|
||||
'Zhai Zhigang',
|
||||
'Zhang Xiaoguang',
|
||||
'Vitaliy Zholobov',
|
||||
'Vyacheslav Zudov'
|
||||
];
|
||||
250
scripts/generate/logs/samples/countries.js
Normal file
250
scripts/generate/logs/samples/countries.js
Normal file
@ -0,0 +1,250 @@
|
||||
module.exports = {
|
||||
'CN': 1330044000,
|
||||
'IN': 1173108018,
|
||||
'US': 610232863,
|
||||
'ID': 242968342,
|
||||
'BR': 201103330,
|
||||
'PK': 184404791,
|
||||
'BD': 156118464,
|
||||
'NG': 154000000,
|
||||
'RU': 140702000,
|
||||
'JP': 127288000,
|
||||
'MX': 112468855,
|
||||
'PH': 99900177,
|
||||
'VN': 89571130,
|
||||
'ET': 88013491,
|
||||
'DE': 81802257,
|
||||
'EG': 80471869,
|
||||
'TR': 77804122,
|
||||
'IR': 76923300,
|
||||
'CD': 70916439,
|
||||
'TH': 67089500,
|
||||
'FR': 64768389,
|
||||
'GB': 62348447,
|
||||
'IT': 60340328,
|
||||
'MM': 53414374,
|
||||
'ZA': 49000000,
|
||||
'KR': 48422644,
|
||||
'ES': 46505963,
|
||||
'UA': 45415596,
|
||||
'CO': 44205293,
|
||||
'TZ': 41892895,
|
||||
'AR': 41343201,
|
||||
'KE': 40046566,
|
||||
'PL': 38500000,
|
||||
'SD': 35000000,
|
||||
'DZ': 34586184,
|
||||
'CA': 33679000,
|
||||
'UG': 33398682,
|
||||
'MA': 31627428,
|
||||
'PE': 29907003,
|
||||
'IQ': 29671605,
|
||||
'AF': 29121286,
|
||||
'NP': 28951852,
|
||||
'MY': 28274729,
|
||||
'UZ': 27865738,
|
||||
'VE': 27223228,
|
||||
'SA': 25731776,
|
||||
'GH': 24339838,
|
||||
'YE': 23495361,
|
||||
'KP': 22912177,
|
||||
'TW': 22894384,
|
||||
'SY': 22198110,
|
||||
'MZ': 22061451,
|
||||
'RO': 21959278,
|
||||
'AU': 21515754,
|
||||
'LK': 21513990,
|
||||
'MG': 21281844,
|
||||
'CI': 21058798,
|
||||
'CM': 19294149,
|
||||
'CL': 16746491,
|
||||
'NL': 16645000,
|
||||
'BF': 16241811,
|
||||
'NE': 15878271,
|
||||
'MW': 15447500,
|
||||
'KZ': 15340000,
|
||||
'EC': 14790608,
|
||||
'KH': 14453680,
|
||||
'ML': 13796354,
|
||||
'GT': 13550440,
|
||||
'ZM': 13460305,
|
||||
'AO': 13068161,
|
||||
'SN': 12323252,
|
||||
'ZW': 11651858,
|
||||
'CU': 11423000,
|
||||
'RW': 11055976,
|
||||
'GR': 11000000,
|
||||
'CS': 10829175,
|
||||
'PT': 10676000,
|
||||
'TN': 10589025,
|
||||
'TD': 10543464,
|
||||
'CZ': 10476000,
|
||||
'BE': 10403000,
|
||||
'GN': 10324025,
|
||||
'SO': 10112453,
|
||||
'BO': 9947418,
|
||||
'HU': 9930000,
|
||||
'BI': 9863117,
|
||||
'DO': 9823821,
|
||||
'BY': 9685000,
|
||||
'HT': 9648924,
|
||||
'BJ': 9056010,
|
||||
'SE': 9045000,
|
||||
'AZ': 8303512,
|
||||
'SS': 8260490,
|
||||
'AT': 8205000,
|
||||
'HN': 7989415,
|
||||
'CH': 7581000,
|
||||
'TJ': 7487489,
|
||||
'IL': 7353985,
|
||||
'RS': 7344847,
|
||||
'BG': 7148785,
|
||||
'HK': 6898686,
|
||||
'TG': 6587239,
|
||||
'LY': 6461454,
|
||||
'JO': 6407085,
|
||||
'PY': 6375830,
|
||||
'LA': 6368162,
|
||||
'PG': 6064515,
|
||||
'SV': 6052064,
|
||||
'NI': 5995928,
|
||||
'ER': 5792984,
|
||||
'KG': 5508626,
|
||||
'DK': 5484000,
|
||||
'SK': 5455000,
|
||||
'SL': 5245695,
|
||||
'FI': 5244000,
|
||||
'NO': 5009150,
|
||||
'AE': 4975593,
|
||||
'TM': 4940916,
|
||||
'CF': 4844927,
|
||||
'SG': 4701069,
|
||||
'GE': 4630000,
|
||||
'IE': 4622917,
|
||||
'BA': 4590000,
|
||||
'CR': 4516220,
|
||||
'HR': 4491000,
|
||||
'MD': 4324000,
|
||||
'NZ': 4252277,
|
||||
'LB': 4125247,
|
||||
'PR': 3916632,
|
||||
'PS': 3800000,
|
||||
'LR': 3685076,
|
||||
'LT': 3565000,
|
||||
'UY': 3477000,
|
||||
'PA': 3410676,
|
||||
'MR': 3205060,
|
||||
'MN': 3086918,
|
||||
'CG': 3039126,
|
||||
'AL': 2986952,
|
||||
'AM': 2968000,
|
||||
'OM': 2967717,
|
||||
'JM': 2847232,
|
||||
'KW': 2789132,
|
||||
'LV': 2217969,
|
||||
'NA': 2128471,
|
||||
'MK': 2061000,
|
||||
'BW': 2029307,
|
||||
'SI': 2007000,
|
||||
'LS': 1919552,
|
||||
'XK': 1800000,
|
||||
'GM': 1593256,
|
||||
'GW': 1565126,
|
||||
'GA': 1545255,
|
||||
'SZ': 1354051,
|
||||
'MU': 1294104,
|
||||
'EE': 1291170,
|
||||
'TT': 1228691,
|
||||
'TL': 1154625,
|
||||
'CY': 1102677,
|
||||
'GQ': 1014999,
|
||||
'FJ': 875983,
|
||||
'QA': 840926,
|
||||
'RE': 776948,
|
||||
'KM': 773407,
|
||||
'GY': 748486,
|
||||
'DJ': 740528,
|
||||
'BH': 738004,
|
||||
'BT': 699847,
|
||||
'ME': 666730,
|
||||
'SB': 559198,
|
||||
'CV': 508659,
|
||||
'LU': 497538,
|
||||
'SR': 492829,
|
||||
'MO': 449198,
|
||||
'GP': 443000,
|
||||
'MQ': 432900,
|
||||
'MT': 403000,
|
||||
'MV': 395650,
|
||||
'BN': 395027,
|
||||
'BZ': 314522,
|
||||
'IS': 308910,
|
||||
'BS': 301790,
|
||||
'BB': 285653,
|
||||
'EH': 273008,
|
||||
'PF': 270485,
|
||||
'VU': 221552,
|
||||
'NC': 216494,
|
||||
'GF': 195506,
|
||||
'WS': 192001,
|
||||
'ST': 175808,
|
||||
'LC': 160922,
|
||||
'GU': 159358,
|
||||
'YT': 159042,
|
||||
'CW': 141766,
|
||||
'AN': 136197,
|
||||
'TO': 122580,
|
||||
'VI': 108708,
|
||||
'GD': 107818,
|
||||
'FM': 107708,
|
||||
'VC': 104217,
|
||||
'KI': 92533,
|
||||
'JE': 90812,
|
||||
'SC': 88340,
|
||||
'AG': 86754,
|
||||
'AD': 84000,
|
||||
'IM': 75049,
|
||||
'DM': 72813,
|
||||
'AW': 71566,
|
||||
'MH': 65859,
|
||||
'BM': 65365,
|
||||
'GG': 65228,
|
||||
'AS': 57881,
|
||||
'GL': 56375,
|
||||
'MP': 53883,
|
||||
'KN': 49898,
|
||||
'FO': 48228,
|
||||
'KY': 44270,
|
||||
'SX': 37429,
|
||||
'MF': 35925,
|
||||
'LI': 35000,
|
||||
'MC': 32965,
|
||||
'SM': 31477,
|
||||
'GI': 27884,
|
||||
'AX': 26711,
|
||||
'VG': 21730,
|
||||
'CK': 21388,
|
||||
'TC': 20556,
|
||||
'PW': 19907,
|
||||
'BQ': 18012,
|
||||
'WF': 16025,
|
||||
'AI': 13254,
|
||||
'TV': 10472,
|
||||
'NR': 10065,
|
||||
'MS': 9341,
|
||||
'BL': 8450,
|
||||
'SH': 7460,
|
||||
'PM': 7012,
|
||||
'IO': 4000,
|
||||
'FK': 2638,
|
||||
'SJ': 2550,
|
||||
'NU': 2166,
|
||||
'NF': 1828,
|
||||
'CX': 1500,
|
||||
'TK': 1466,
|
||||
'VA': 921,
|
||||
'CC': 628,
|
||||
'TF': 140,
|
||||
'PN': 46,
|
||||
'GS': 30
|
||||
};
|
||||
93
scripts/generate/logs/samples/index.js
Normal file
93
scripts/generate/logs/samples/index.js
Normal file
@ -0,0 +1,93 @@
|
||||
var _ = require('../../../../src/lib/utils'),
|
||||
WeightedList = require('./weighted_list'),
|
||||
RandomList = require('./random_list'),
|
||||
IpGenerator = require('./ip_generator'),
|
||||
Stochator = require('./stochator'),
|
||||
moment = require('moment'),
|
||||
dayMs = 86400000;
|
||||
|
||||
exports.make = function (startingMoment, endingMoment) {
|
||||
|
||||
var sets = {};
|
||||
|
||||
sets.randomMsInDayRange = new Stochator({
|
||||
min: startingMoment.toDate().getTime(),
|
||||
max: endingMoment.toDate().getTime()
|
||||
}, 'get');
|
||||
|
||||
sets.lessRandomRespSize = new Stochator({
|
||||
mean: 4500,
|
||||
stddev: 4500 * 0.56,
|
||||
min: 1500,
|
||||
max: 10000
|
||||
}, 'get');
|
||||
|
||||
sets.lessRandomMsInDay = new Stochator({
|
||||
min: 0,
|
||||
max: dayMs,
|
||||
mean: dayMs / 2,
|
||||
stdev: dayMs * 0.15,
|
||||
}, 'get');
|
||||
|
||||
sets.astronauts = new RandomList(require('./astronauts').map(function (name) {
|
||||
return name.replace(/\W+/g, '-').toLowerCase();
|
||||
}));
|
||||
|
||||
sets.airports = new RandomList(require('./airports'));
|
||||
|
||||
sets.ips = new IpGenerator(100, 1000);
|
||||
|
||||
sets.countries = new WeightedList(require('./countries'));
|
||||
|
||||
sets.extensions = new WeightedList({
|
||||
'html': 40,
|
||||
'php': 30,
|
||||
'png': 15,
|
||||
'gif': 5,
|
||||
'css': 10
|
||||
});
|
||||
|
||||
sets.responseCodes = new WeightedList({
|
||||
200: 92,
|
||||
404: 5,
|
||||
503: 3
|
||||
});
|
||||
|
||||
sets.tags = new WeightedList({
|
||||
'error': 6,
|
||||
'warning': 10,
|
||||
'success': 84
|
||||
});
|
||||
|
||||
sets.tags2 = new WeightedList({
|
||||
'security': 20,
|
||||
'info': 75,
|
||||
'login': 5
|
||||
});
|
||||
|
||||
sets.timezones = new WeightedList({
|
||||
'-07:00': 1
|
||||
});
|
||||
|
||||
sets.referrers = new WeightedList({
|
||||
'www.slate.com': 50,
|
||||
'twitter.com': 35,
|
||||
'facebook.com': 20,
|
||||
'nytimes.com': 10
|
||||
});
|
||||
|
||||
sets.userAgents = new WeightedList({
|
||||
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)': 30,
|
||||
'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24': 35,
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1': 40
|
||||
});
|
||||
|
||||
sets.types = new WeightedList({
|
||||
'nginx': 1,
|
||||
'apache': 4
|
||||
});
|
||||
|
||||
return _.map(sets, function (set, name) {
|
||||
return _.bindKey(set, 'get');
|
||||
});
|
||||
};
|
||||
36
scripts/generate/logs/samples/ip_generator.js
Normal file
36
scripts/generate/logs/samples/ip_generator.js
Normal file
@ -0,0 +1,36 @@
|
||||
module.exports = IpGenerator;
|
||||
|
||||
var _ = require('../../../../src/lib/utils');
|
||||
|
||||
function IpGenerator(maxCount, maxSessions) {
|
||||
this.maxSessions = maxSessions;
|
||||
this.maxCount = maxCount;
|
||||
|
||||
this.sessions = [];
|
||||
}
|
||||
|
||||
IpGenerator.prototype.get = function () {
|
||||
var session, index;
|
||||
if (this.sessions.length < this.maxSessions) {
|
||||
session = [this.makeRandom(), 0];
|
||||
index = this.sessions.length;
|
||||
this.sessions.push(session);
|
||||
} else {
|
||||
index = _.random(0, this.sessions.length - 1);
|
||||
session = this.sessions[index];
|
||||
}
|
||||
|
||||
if (session[1] > this.maxCount) {
|
||||
this.sessions.splice(index, 1);
|
||||
return this.getIp();
|
||||
} else {
|
||||
return session[0];
|
||||
}
|
||||
};
|
||||
|
||||
IpGenerator.prototype.makeRandom = function () {
|
||||
return _.random(0, 255) + '.' +
|
||||
_.random(0, 255) + '.' +
|
||||
_.random(0, 255) + '.' +
|
||||
_.random(0, 255);
|
||||
};
|
||||
13
scripts/generate/logs/samples/random_list.js
Normal file
13
scripts/generate/logs/samples/random_list.js
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @class RandomList
|
||||
*/
|
||||
|
||||
module.exports = RandomList;
|
||||
|
||||
var _ = require('../../../../src/lib/utils');
|
||||
|
||||
function RandomList(list) {
|
||||
this.get = function () {
|
||||
return list[Math.round(Math.random() * list.length)];
|
||||
};
|
||||
}
|
||||
464
scripts/generate/logs/samples/stochator.js
Normal file
464
scripts/generate/logs/samples/stochator.js
Normal file
@ -0,0 +1,464 @@
|
||||
(function() {
|
||||
var Set, Stochator, callFunctions, floatGenerator, integerGenerator, inverseNormalCumulativeDistribution, isType, randomBoundedFloat, randomBoundedInteger, randomCharacter, randomColor, randomNormallyDistributedFloat, randomSetMember, randomSetMemberWithoutReplacement, randomWeightedSetMember, setGenerator, shuffleSet,
|
||||
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
||||
__slice = Array.prototype.slice;
|
||||
|
||||
Set = (function() {
|
||||
|
||||
function Set(values) {
|
||||
this.values = values;
|
||||
this.length = this.values.length;
|
||||
}
|
||||
|
||||
Set.prototype.toString = function() {
|
||||
return "[object Set]";
|
||||
};
|
||||
|
||||
Set.prototype.copy = function() {
|
||||
return this.values.slice(0, this.length);
|
||||
};
|
||||
|
||||
Set.prototype.enumerate = function(depth) {
|
||||
var d, digits, e, enumeration, enumerations, enumerationsLength, i;
|
||||
if (depth == null) depth = this.length;
|
||||
enumerationsLength = Math.pow(this.length, depth);
|
||||
enumerations = [];
|
||||
for (enumeration = 0; 0 <= enumerationsLength ? enumeration < enumerationsLength : enumeration > enumerationsLength; 0 <= enumerationsLength ? enumeration++ : enumeration--) {
|
||||
e = enumeration;
|
||||
digits = [];
|
||||
for (i = 0; 0 <= depth ? i < depth : i > depth; 0 <= depth ? i++ : i--) {
|
||||
d = e % this.length;
|
||||
e -= d;
|
||||
e /= this.length;
|
||||
digits.push(this.values[d]);
|
||||
}
|
||||
enumerations.push(new Set(digits));
|
||||
}
|
||||
return new Set(enumerations);
|
||||
};
|
||||
|
||||
Set.prototype.intersection = function(set) {
|
||||
var value;
|
||||
return new Set((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = set.values;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
value = _ref[_i];
|
||||
if (__indexOf.call(this.values, value) >= 0) _results.push(value);
|
||||
}
|
||||
return _results;
|
||||
}).call(this));
|
||||
};
|
||||
|
||||
Set.prototype.union = function(set) {
|
||||
return new Set(this.values.concat(this.difference(set).values));
|
||||
};
|
||||
|
||||
Set.prototype.difference = function(set) {
|
||||
var value;
|
||||
return new Set((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = set.values;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
value = _ref[_i];
|
||||
if (!(__indexOf.call(this.values, value) >= 0)) _results.push(value);
|
||||
}
|
||||
return _results;
|
||||
}).call(this));
|
||||
};
|
||||
|
||||
Set.prototype.symmetricDifference = function(set) {
|
||||
return this.union(set).difference(this.intersection(set));
|
||||
};
|
||||
|
||||
Set.prototype.reduce = function(iterator) {
|
||||
return this.values.reduce(iterator);
|
||||
};
|
||||
|
||||
Set.prototype.reverse = function() {
|
||||
return new Set(this.copy().reverse());
|
||||
};
|
||||
|
||||
Set.prototype.sort = function(compare) {
|
||||
return this.copy().sort(compare);
|
||||
};
|
||||
|
||||
Set.prototype.sum = function() {
|
||||
var _ref;
|
||||
return (_ref = this._sum) != null ? _ref : this._sum = this.reduce(function(a, b) {
|
||||
return a + b;
|
||||
});
|
||||
};
|
||||
|
||||
Set.prototype.mean = function() {
|
||||
var _ref;
|
||||
return (_ref = this._mean) != null ? _ref : this._mean = this.sum() / this.length;
|
||||
};
|
||||
|
||||
Set.prototype.stdev = function() {
|
||||
var value, _ref;
|
||||
return (_ref = this._stdev) != null ? _ref : this._stdev = Math.sqrt(new Set((function() {
|
||||
var _i, _len, _ref2, _results;
|
||||
_ref2 = this.values;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
value = _ref2[_i];
|
||||
_results.push(Math.pow(value - this.mean(), 2));
|
||||
}
|
||||
return _results;
|
||||
}).call(this)).mean());
|
||||
};
|
||||
|
||||
Set.prototype.get = function(index, dflt) {
|
||||
if (this.values[index] != null) {
|
||||
return this.values[index];
|
||||
} else {
|
||||
return dflt;
|
||||
}
|
||||
};
|
||||
|
||||
Set.prototype.each = function(iterator) {
|
||||
var index, value, _len, _ref, _results;
|
||||
_ref = this.values;
|
||||
_results = [];
|
||||
for (index = 0, _len = _ref.length; index < _len; index++) {
|
||||
value = _ref[index];
|
||||
_results.push(iterator(value, index));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Set.prototype.map = function(iterator) {
|
||||
var index, value;
|
||||
return new Set((function() {
|
||||
var _len, _ref, _results;
|
||||
_ref = this.values;
|
||||
_results = [];
|
||||
for (index = 0, _len = _ref.length; index < _len; index++) {
|
||||
value = _ref[index];
|
||||
_results.push(iterator(value, index));
|
||||
}
|
||||
return _results;
|
||||
}).call(this));
|
||||
};
|
||||
|
||||
Set.prototype.pop = function(index) {
|
||||
var value;
|
||||
if (index == null) index = this.length - 1;
|
||||
value = this.values[index];
|
||||
this.values.splice(index, 1);
|
||||
return value;
|
||||
};
|
||||
|
||||
return Set;
|
||||
|
||||
})();
|
||||
|
||||
isType = function(type) {
|
||||
return function(arg) {
|
||||
return Object.prototype.toString.call(arg) === ("[object " + type + "]");
|
||||
};
|
||||
};
|
||||
|
||||
callFunctions = function(fns) {
|
||||
var fn, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = fns.length; _i < _len; _i++) {
|
||||
fn = fns[_i];
|
||||
_results.push(fn());
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
randomBoundedFloat = function(min, max) {
|
||||
var spread;
|
||||
if (min == null) min = 0;
|
||||
if (max == null) max = 1;
|
||||
spread = max - min;
|
||||
return Math.random() * spread + min;
|
||||
};
|
||||
|
||||
randomBoundedInteger = function(min, max) {
|
||||
var spread;
|
||||
if (min == null) min = 0;
|
||||
if (max == null) max = 1;
|
||||
spread = 1 + max - min;
|
||||
return Math.floor(Math.random() * spread) + min;
|
||||
};
|
||||
|
||||
randomColor = function() {
|
||||
var byte, mutator;
|
||||
byte = {
|
||||
kind: "integer",
|
||||
min: 0,
|
||||
max: 255
|
||||
};
|
||||
mutator = function(bytes) {
|
||||
var blue, green, red;
|
||||
red = bytes[0], green = bytes[1], blue = bytes[2];
|
||||
return {
|
||||
red: red,
|
||||
green: green,
|
||||
blue: blue
|
||||
};
|
||||
};
|
||||
return new Stochator(byte, byte, byte, mutator).next;
|
||||
};
|
||||
|
||||
randomNormallyDistributedFloat = function(mean, stdev, min, max) {
|
||||
var float, seed;
|
||||
seed = randomBoundedFloat();
|
||||
float = inverseNormalCumulativeDistribution(seed) * stdev + mean;
|
||||
if ((min != null) && (max != null)) {
|
||||
return Math.min(max, Math.max(min, float));
|
||||
} else {
|
||||
return float;
|
||||
}
|
||||
};
|
||||
|
||||
randomCharacter = function(lowercase) {
|
||||
var max, min, mutator, _ref;
|
||||
_ref = lowercase ? [97, 122] : [65, 90], min = _ref[0], max = _ref[1];
|
||||
mutator = function(charCode) {
|
||||
return String.fromCharCode(charCode);
|
||||
};
|
||||
return new Stochator({
|
||||
kind: "integer",
|
||||
min: min,
|
||||
max: max
|
||||
}, mutator).next;
|
||||
};
|
||||
|
||||
randomSetMember = function(set) {
|
||||
var max;
|
||||
max = set.length - 1;
|
||||
return set.get(randomBoundedInteger(0, max));
|
||||
};
|
||||
|
||||
randomSetMemberWithoutReplacement = function(set) {
|
||||
if (!set.get(0)) return;
|
||||
set.length -= 1;
|
||||
return set.pop(randomBoundedInteger(0, set.length));
|
||||
};
|
||||
|
||||
randomWeightedSetMember = function(set, weights) {
|
||||
var float, member, weightSum, _ref;
|
||||
_ref = [void 0, 0, randomBoundedFloat()], member = _ref[0], weightSum = _ref[1], float = _ref[2];
|
||||
set.each(function(value, index) {
|
||||
var weight;
|
||||
if (member) return;
|
||||
weight = weights.get(index);
|
||||
if (float <= weightSum + weight && float >= weightSum) member = value;
|
||||
return weightSum += weight;
|
||||
});
|
||||
return member;
|
||||
};
|
||||
|
||||
inverseNormalCumulativeDistribution = function(probability) {
|
||||
var base, coefficient, denomCoeffcients, denomMaxExponent, denominator, high, low, mapMaxExp, numCoefficients, numMaxExponent, numerator, _ref, _ref2;
|
||||
high = probability > 0.97575;
|
||||
low = probability < 0.02425;
|
||||
if (low || high) {
|
||||
numCoefficients = new Set([-7.784894002430293e-3, -3.223964580411365e-1, -2.400758277161838, -2.549732539343734, 4.374664141464968]);
|
||||
denomCoeffcients = new Set([7.784695709041462e-3, 3.224671290700398e-1, 2.445134137142996, 3.754408661907416]);
|
||||
_ref = [5, 4], numMaxExponent = _ref[0], denomMaxExponent = _ref[1];
|
||||
coefficient = low ? 1 : -1;
|
||||
base = Math.sqrt(-2 * Math.log(low ? probability : 1 - probability));
|
||||
} else {
|
||||
numCoefficients = new Set([-3.969683028665376e1, 2.209460984245205e2, -2.759285104469687e2, 1.383577518672690e2, -3.066479806614716e1, 2.506628277459239]);
|
||||
denomCoeffcients = new Set([-5.447609879822406e1, 1.615858368580409e2, -1.556989798598866e2, 6.680131188771972e1, -1.328068155288572e1]);
|
||||
_ref2 = [5, 5], numMaxExponent = _ref2[0], denomMaxExponent = _ref2[1];
|
||||
coefficient = probability - 0.5;
|
||||
base = Math.pow(coefficient, 2);
|
||||
}
|
||||
mapMaxExp = function(maxExp) {
|
||||
return function(value, index) {
|
||||
return value * Math.pow(base, maxExp - index);
|
||||
};
|
||||
};
|
||||
numerator = numCoefficients.map(mapMaxExp(numMaxExponent)).sum();
|
||||
denominator = denomCoeffcients.map(mapMaxExp(denomMaxExponent)).sum() + 1;
|
||||
return coefficient * numerator / denominator;
|
||||
};
|
||||
|
||||
shuffleSet = function(set) {
|
||||
var index, randomIndex, tmp, values, _ref;
|
||||
values = set.copy();
|
||||
for (index = _ref = values.length - 1; _ref <= 0 ? index < 0 : index > 0; _ref <= 0 ? index++ : index--) {
|
||||
randomIndex = randomBoundedInteger(0, index);
|
||||
tmp = values[index];
|
||||
values[index] = values[randomIndex];
|
||||
values[randomIndex] = tmp;
|
||||
}
|
||||
return values;
|
||||
};
|
||||
|
||||
floatGenerator = function(min, max, mean, stdev) {
|
||||
if (mean && stdev) {
|
||||
return function() {
|
||||
return randomNormallyDistributedFloat(mean, stdev, min, max);
|
||||
};
|
||||
} else {
|
||||
return function() {
|
||||
return randomBoundedFloat(min, max);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
integerGenerator = function(min, max) {
|
||||
if (min == null) min = 0;
|
||||
if (max == null) max = 1;
|
||||
return function() {
|
||||
return randomBoundedInteger(min, max);
|
||||
};
|
||||
};
|
||||
|
||||
setGenerator = function(values, replacement, shuffle, weights) {
|
||||
var set, weightsSet;
|
||||
if (replacement == null) replacement = true;
|
||||
if (shuffle == null) shuffle = false;
|
||||
if (weights == null) weights = null;
|
||||
if (!values || !values.length) {
|
||||
throw Error("Must provide a 'values' array for a set generator.");
|
||||
}
|
||||
set = new Set(values);
|
||||
if (shuffle) {
|
||||
return function() {
|
||||
return shuffleSet(set);
|
||||
};
|
||||
} else if (replacement) {
|
||||
if (weights) {
|
||||
weightsSet = new Set(weights);
|
||||
return function() {
|
||||
return randomWeightedSetMember(set, weightsSet);
|
||||
};
|
||||
} else {
|
||||
return function() {
|
||||
return randomSetMember(set);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return function() {
|
||||
return randomSetMemberWithoutReplacement(set);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Stochator = (function() {
|
||||
var VERSION;
|
||||
|
||||
VERSION = "0.3.1";
|
||||
|
||||
function Stochator() {
|
||||
var configs;
|
||||
configs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
this.setGenerator(configs);
|
||||
}
|
||||
|
||||
Stochator.prototype.createGenerator = function(config) {
|
||||
var generator, max, mean, min, replacement, shuffle, stdev, values, weights;
|
||||
if (config.kind == null) config.kind = "float";
|
||||
generator = (function() {
|
||||
switch (config.kind) {
|
||||
case "float":
|
||||
min = config.min, max = config.max, mean = config.mean, stdev = config.stdev;
|
||||
return floatGenerator(min, max, mean, stdev);
|
||||
case "integer":
|
||||
return integerGenerator(config.min, config.max);
|
||||
case "set":
|
||||
values = config.values, replacement = config.replacement, shuffle = config.shuffle, weights = config.weights;
|
||||
return setGenerator(values, replacement, shuffle, weights);
|
||||
case "color":
|
||||
case "rgb":
|
||||
return randomColor(config.kind);
|
||||
case "a-z":
|
||||
case "A-Z":
|
||||
return randomCharacter(config.kind === "a-z");
|
||||
}
|
||||
})();
|
||||
if (!generator) {
|
||||
throw Error("" + config.kind + " not a recognized kind.");
|
||||
} else {
|
||||
return generator;
|
||||
}
|
||||
};
|
||||
|
||||
Stochator.prototype.createGenerators = function(configs, mutator) {
|
||||
var callGenerators, caller, config, generators,
|
||||
_this = this;
|
||||
if (configs[0] == null) configs[0] = {};
|
||||
generators = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = configs.length; _i < _len; _i++) {
|
||||
config = configs[_i];
|
||||
_results.push(this.createGenerator(config));
|
||||
}
|
||||
return _results;
|
||||
}).call(this);
|
||||
if (!mutator) {
|
||||
callGenerators = generators.length === 1 ? function() {
|
||||
return callFunctions(generators)[0];
|
||||
} : function() {
|
||||
return callFunctions(generators);
|
||||
};
|
||||
} else {
|
||||
caller = generators.length === 1 ? function() {
|
||||
return callFunctions(generators)[0];
|
||||
} : function() {
|
||||
return callFunctions(generators);
|
||||
};
|
||||
callGenerators = function() {
|
||||
return _this.value = mutator.call(_this, caller(), _this.value);
|
||||
};
|
||||
}
|
||||
return function(times) {
|
||||
var time, _results;
|
||||
if (times) {
|
||||
_results = [];
|
||||
for (time = 1; 1 <= times ? time <= times : time >= times; 1 <= times ? time++ : time--) {
|
||||
_results.push(callGenerators());
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
return callGenerators();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Stochator.prototype.setGenerator = function(configs) {
|
||||
var config, generatorConfigs, mutator, name, _i, _len, _ref, _ref2;
|
||||
generatorConfigs = [];
|
||||
for (_i = 0, _len = configs.length; _i < _len; _i++) {
|
||||
config = configs[_i];
|
||||
if (isType("Object")(config)) {
|
||||
generatorConfigs.push(config);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ref = configs.slice(generatorConfigs.length), name = _ref[0], mutator = _ref[1];
|
||||
name || (name = "next");
|
||||
if (isType("Function")(name)) {
|
||||
_ref2 = ["next", name], name = _ref2[0], mutator = _ref2[1];
|
||||
}
|
||||
return this[name] = this.createGenerators(generatorConfigs, mutator);
|
||||
};
|
||||
|
||||
Stochator.prototype.toString = function() {
|
||||
return "[object Stochator]";
|
||||
};
|
||||
|
||||
return Stochator;
|
||||
|
||||
})();
|
||||
|
||||
if (typeof module !== "undefined" && module !== null ? module.exports : void 0) {
|
||||
module.exports = Stochator;
|
||||
} else {
|
||||
this.Stochator = Stochator;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
121
scripts/generate/logs/samples/weighted_list.js
Normal file
121
scripts/generate/logs/samples/weighted_list.js
Normal file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* @class WeightedList
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
module.exports = WeightedList;
|
||||
|
||||
var _ = require('../../../../src/lib/utils');
|
||||
|
||||
function WeightedList(list) {
|
||||
WeightedList.callSuper(this, arguments);
|
||||
_.forEach(list, _.bindKey(this, 'push'));
|
||||
}
|
||||
_.inherits(WeightedList, Array);
|
||||
|
||||
/**
|
||||
* Add a value to the weighted list.
|
||||
* @method add
|
||||
* @param {Any} value
|
||||
* @param {Number} [weight] Optional. Defaults to 1.
|
||||
* @return {Number} The index of the item that was added.
|
||||
*/
|
||||
WeightedList.prototype.push = function (weight, value) {
|
||||
if (!weight && weight !== 0) {
|
||||
weight = 1;
|
||||
}
|
||||
|
||||
Array.prototype.push.call(this, {
|
||||
value: value,
|
||||
weight: weight
|
||||
});
|
||||
|
||||
delete this._sum;
|
||||
delete this._totals;
|
||||
|
||||
return this.length - 1;
|
||||
};
|
||||
|
||||
WeightedList.prototype.get = function () {
|
||||
return this[this._randomIndex()].value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an index by weighted random distribution.
|
||||
* @method _randomIndex
|
||||
* @protected
|
||||
* @return {Number}
|
||||
*/
|
||||
WeightedList.prototype._randomIndex = function () {
|
||||
var maximumIndex,
|
||||
me = this,
|
||||
middleIndex,
|
||||
minimumIndex = 0,
|
||||
random,
|
||||
sum = me._sum,
|
||||
total,
|
||||
totals = me._totals;
|
||||
|
||||
if (!sum || !totals) {
|
||||
me._update();
|
||||
|
||||
sum = me._sum;
|
||||
totals = me._totals;
|
||||
|
||||
if (!sum || !totals || !totals.length) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
maximumIndex = totals.length - 1;
|
||||
random = Math.random() * sum;
|
||||
|
||||
while (maximumIndex >= minimumIndex) {
|
||||
middleIndex = (maximumIndex + minimumIndex) / 2;
|
||||
|
||||
if (middleIndex < 0) {
|
||||
middleIndex = 0;
|
||||
} else {
|
||||
middleIndex = Math.floor(middleIndex);
|
||||
}
|
||||
|
||||
total = totals[middleIndex];
|
||||
|
||||
if (random === total) {
|
||||
middleIndex += 1;
|
||||
break;
|
||||
} else if (random < total) {
|
||||
if (middleIndex && random > totals[middleIndex - 1]) {
|
||||
break;
|
||||
}
|
||||
|
||||
maximumIndex = middleIndex - 1;
|
||||
} else if (random > total) {
|
||||
minimumIndex = middleIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return middleIndex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates chached data for achieving weighted random distribution.
|
||||
* @method _update
|
||||
* @chainable
|
||||
* @protected
|
||||
*/
|
||||
WeightedList.prototype._update = function () {
|
||||
var me = this,
|
||||
sum = 0,
|
||||
totals = [];
|
||||
|
||||
_.each(me, function (item) {
|
||||
sum += item.weight;
|
||||
totals.push(sum);
|
||||
});
|
||||
|
||||
me._sum = sum;
|
||||
me._totals = totals;
|
||||
|
||||
return me;
|
||||
};
|
||||
@ -1,2 +0,0 @@
|
||||
exports['cluster.node_info'] =
|
||||
'//TODO: this enpoint ***needs*** work, many of the possible urls are not supported';
|
||||
@ -1,10 +0,0 @@
|
||||
var elasticsearch = require('../src/elasticsearch')
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var client = new elasticsearch.Client({
|
||||
logger: 'trace'
|
||||
});
|
||||
|
||||
console.log(EventEmitter.listenerCount(client.log, 'trace'));
|
||||
|
||||
client.cluster.node_stats();
|
||||
29
scripts/server.js
Normal file
29
scripts/server.js
Normal file
@ -0,0 +1,29 @@
|
||||
var http = require('http'),
|
||||
async = require('async');
|
||||
|
||||
var server = http.createServer(function (req, resp) {
|
||||
var closed, count = 0;
|
||||
|
||||
resp.on('close', function () {
|
||||
closed = true;
|
||||
console.log('response was closed');
|
||||
});
|
||||
|
||||
process.removeAllListeners();
|
||||
|
||||
var interval = setInterval(function () {
|
||||
if (count > 99 || resp.closed || closed) {
|
||||
clearInterval(interval);
|
||||
console.log('done writing', resp.socket.bytesWritten, 'bytes');
|
||||
resp.end();
|
||||
} else {
|
||||
process.stdout.write('->');
|
||||
resp.write('line of data, more to come... slowly!');
|
||||
count++;
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
server.listen(7500, function () {
|
||||
console.log('server listening at', server.address());
|
||||
});
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -17,57 +17,57 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @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, callback) {
|
||||
function doBulk(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_bulk';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_bulk';
|
||||
delete params.type;
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_bulk';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_bulk';
|
||||
}
|
||||
else {
|
||||
request.url = '/_bulk';
|
||||
request.path = '/_bulk';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.consistency !== 'undefined') {
|
||||
@ -80,7 +80,7 @@ function doBulk(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -90,7 +90,7 @@ function doBulk(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -101,7 +101,7 @@ function doBulk(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
query.type = '' + params.type;
|
||||
@ -109,14 +109,10 @@ function doBulk(params, callback) {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doBulk;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [clear_scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
@ -10,55 +10,51 @@ var _ = require('../lib/toolbelt')
|
||||
* @method clear_scroll
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClearScroll(params, callback) {
|
||||
function doClearScroll(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
switch (typeof params.scroll_id) {
|
||||
case 'string':
|
||||
url.scroll_id = params.scroll_id;
|
||||
parts.scroll_id = params.scroll_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.scroll_id)) {
|
||||
url.scroll_id = params.scroll_id.join(',');
|
||||
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:
|
||||
url.scroll_id = !!params.scroll_id;
|
||||
parts.scroll_id = !!params.scroll_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.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 url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClearScroll;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.get_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
@ -10,34 +10,30 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method cluster.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterGetSettings(params, callback) {
|
||||
function doClusterGetSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterGetSettings;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -21,36 +21,36 @@ var waitForStatusOptions = ['green', 'yellow', 'red'];
|
||||
* @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, callback) {
|
||||
function doClusterHealth(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/_cluster/health/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/_cluster/health/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/_cluster/health';
|
||||
request.path = '/_cluster/health';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.level !== 'undefined') {
|
||||
@ -63,7 +63,7 @@ function doClusterHealth(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.local !== 'undefined') {
|
||||
if (params.local.toLowerCase && (params.local = params.local.toLowerCase())
|
||||
&& (params.local === 'no' || params.local === 'off')
|
||||
@ -73,7 +73,7 @@ function doClusterHealth(params, callback) {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -83,7 +83,7 @@ function doClusterHealth(params, callback) {
|
||||
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();
|
||||
@ -93,7 +93,7 @@ function doClusterHealth(params, callback) {
|
||||
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;
|
||||
@ -101,7 +101,7 @@ function doClusterHealth(params, callback) {
|
||||
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;
|
||||
@ -109,7 +109,7 @@ function doClusterHealth(params, callback) {
|
||||
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;
|
||||
@ -117,7 +117,7 @@ function doClusterHealth(params, callback) {
|
||||
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;
|
||||
@ -128,14 +128,10 @@ function doClusterHealth(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterHealth;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -16,45 +16,45 @@ var typeOptions = ['cpu', 'wait', 'block'];
|
||||
* @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, callback) {
|
||||
function doClusterNodeHotThreads(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
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:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/hotthreads';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/hotthreads';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes/hotthreads';
|
||||
request.path = '/_nodes/hotthreads';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.interval !== 'undefined') {
|
||||
@ -66,7 +66,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
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;
|
||||
@ -74,7 +74,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
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;
|
||||
@ -82,7 +82,7 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
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;
|
||||
@ -93,14 +93,10 @@ function doClusterNodeHotThreads(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeHotThreads;
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
//TODO: this enpoint ***needs*** work, many of the possible urls are not supported
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_info](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/) request
|
||||
@ -23,45 +22,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeInfo(params, callback) {
|
||||
function doClusterNodeInfo(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
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:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes';
|
||||
request.path = '/_nodes';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -73,7 +72,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -83,7 +82,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
@ -93,7 +92,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
@ -103,7 +102,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
@ -113,7 +112,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
@ -123,7 +122,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.plugin !== 'undefined') {
|
||||
if (params.plugin.toLowerCase && (params.plugin = params.plugin.toLowerCase())
|
||||
&& (params.plugin === 'no' || params.plugin === 'off')
|
||||
@ -133,7 +132,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.plugin = !!params.plugin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
@ -143,7 +142,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.process = !!params.process;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.settings !== 'undefined') {
|
||||
if (params.settings.toLowerCase && (params.settings = params.settings.toLowerCase())
|
||||
&& (params.settings === 'no' || params.settings === 'off')
|
||||
@ -153,7 +152,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
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')
|
||||
@ -163,7 +162,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.thread_pool = !!params.thread_pool;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -173,7 +172,7 @@ function doClusterNodeInfo(params, callback) {
|
||||
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')
|
||||
@ -183,14 +182,10 @@ function doClusterNodeInfo(params, callback) {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeInfo;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.node_shutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
|
||||
@ -12,45 +12,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doClusterNodeShutdown(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
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:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_cluster/nodes/' + encodeURIComponent(url.node_id) + '/_shutdown';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_cluster/nodes/' + encodeURIComponent(parts.node_id) + '/_shutdown';
|
||||
}
|
||||
else {
|
||||
request.url = '/_shutdown';
|
||||
request.path = '/_shutdown';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.delay !== 'undefined') {
|
||||
@ -62,7 +62,7 @@ function doClusterNodeShutdown(params, callback) {
|
||||
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')
|
||||
@ -72,14 +72,10 @@ function doClusterNodeShutdown(params, callback) {
|
||||
query.exit = !!params.exit;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeShutdown;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -25,39 +25,39 @@ var metricOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'flush',
|
||||
* @param {boolean} params.thread_pool - Return information about the thread pool
|
||||
* @param {boolean} params.transport - Return information about transport
|
||||
*/
|
||||
function doClusterNodeStats(params, callback) {
|
||||
function doClusterNodeStats(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
url.metric_family = params.metric_family;
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
@ -65,10 +65,10 @@ function doClusterNodeStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric !== 'undefined') {
|
||||
if (_.contains(metricOptions, params.metric)) {
|
||||
url.metric = params.metric;
|
||||
parts.metric = params.metric;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric: ' + params.metric +
|
||||
@ -76,33 +76,33 @@ function doClusterNodeStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.node_id !== 'undefined') {
|
||||
switch (typeof params.node_id) {
|
||||
case 'string':
|
||||
url.node_id = params.node_id;
|
||||
parts.node_id = params.node_id;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.node_id)) {
|
||||
url.node_id = params.node_id.join(',');
|
||||
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:
|
||||
url.node_id = !!params.node_id;
|
||||
parts.node_id = !!params.node_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('node_id')) {
|
||||
request.url = '/_nodes/' + encodeURIComponent(url.node_id) + '/stats';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('node_id')) {
|
||||
request.path = '/_nodes/' + encodeURIComponent(parts.node_id) + '/stats';
|
||||
}
|
||||
else {
|
||||
request.url = '/_nodes/stats';
|
||||
request.path = '/_nodes/stats';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -114,7 +114,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -124,7 +124,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -141,7 +141,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fs !== 'undefined') {
|
||||
if (params.fs.toLowerCase && (params.fs = params.fs.toLowerCase())
|
||||
&& (params.fs === 'no' || params.fs === 'off')
|
||||
@ -151,7 +151,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.fs = !!params.fs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.http !== 'undefined') {
|
||||
if (params.http.toLowerCase && (params.http = params.http.toLowerCase())
|
||||
&& (params.http === 'no' || params.http === 'off')
|
||||
@ -161,7 +161,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.http = !!params.http;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indices !== 'undefined') {
|
||||
if (params.indices.toLowerCase && (params.indices = params.indices.toLowerCase())
|
||||
&& (params.indices === 'no' || params.indices === 'off')
|
||||
@ -171,7 +171,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.indices = !!params.indices;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.jvm !== 'undefined') {
|
||||
if (params.jvm.toLowerCase && (params.jvm = params.jvm.toLowerCase())
|
||||
&& (params.jvm === 'no' || params.jvm === 'off')
|
||||
@ -181,7 +181,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.jvm = !!params.jvm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.network !== 'undefined') {
|
||||
if (params.network.toLowerCase && (params.network = params.network.toLowerCase())
|
||||
&& (params.network === 'no' || params.network === 'off')
|
||||
@ -191,7 +191,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.network = !!params.network;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.os !== 'undefined') {
|
||||
if (params.os.toLowerCase && (params.os = params.os.toLowerCase())
|
||||
&& (params.os === 'no' || params.os === 'off')
|
||||
@ -201,7 +201,7 @@ function doClusterNodeStats(params, callback) {
|
||||
query.os = !!params.os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.process !== 'undefined') {
|
||||
if (params.process.toLowerCase && (params.process = params.process.toLowerCase())
|
||||
&& (params.process === 'no' || params.process === 'off')
|
||||
@ -211,7 +211,7 @@ function doClusterNodeStats(params, callback) {
|
||||
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')
|
||||
@ -221,7 +221,7 @@ function doClusterNodeStats(params, callback) {
|
||||
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')
|
||||
@ -231,14 +231,10 @@ function doClusterNodeStats(params, callback) {
|
||||
query.transport = !!params.transport;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterNodeStats;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.put_settings](http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/) request
|
||||
@ -10,35 +10,31 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method cluster.put_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doClusterPutSettings(params, callback) {
|
||||
function doClusterPutSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/settings';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/settings';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterPutSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.reroute](http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/) request
|
||||
@ -12,25 +12,25 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doClusterReroute(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/reroute';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/reroute';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.dry_run !== 'undefined') {
|
||||
@ -42,7 +42,7 @@ function doClusterReroute(params, callback) {
|
||||
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')
|
||||
@ -52,14 +52,10 @@ function doClusterReroute(params, callback) {
|
||||
query.filter_metadata = !!params.filter_metadata;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterReroute;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [cluster.state](http://elasticsearch.org/guide/reference/api/admin-cluster-state/) request
|
||||
@ -18,24 +18,24 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doClusterState(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_cluster/state';
|
||||
|
||||
// build the path
|
||||
request.path = '/_cluster/state';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.filter_blocks !== 'undefined') {
|
||||
@ -47,7 +47,7 @@ function doClusterState(params, callback) {
|
||||
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')
|
||||
@ -57,7 +57,7 @@ function doClusterState(params, callback) {
|
||||
query.filter_index_templates = !!params.filter_index_templates;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter_indices !== 'undefined') {
|
||||
switch (typeof params.filter_indices) {
|
||||
case 'string':
|
||||
@ -74,7 +74,7 @@ function doClusterState(params, callback) {
|
||||
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')
|
||||
@ -84,7 +84,7 @@ function doClusterState(params, callback) {
|
||||
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')
|
||||
@ -94,7 +94,7 @@ function doClusterState(params, callback) {
|
||||
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')
|
||||
@ -104,7 +104,7 @@ function doClusterState(params, callback) {
|
||||
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')
|
||||
@ -114,7 +114,7 @@ function doClusterState(params, callback) {
|
||||
query.local = !!params.local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
if (params.master_timeout instanceof Date) {
|
||||
query.master_timeout = params.master_timeout.getTime();
|
||||
@ -124,14 +124,10 @@ function doClusterState(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doClusterState;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [count](http://elasticsearch.org/guide/reference/api/count/) request
|
||||
*
|
||||
@ -17,74 +17,74 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doCount(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_count';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_count';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_count';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_count';
|
||||
}
|
||||
else {
|
||||
request.url = '/_count';
|
||||
request.path = '/_count';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -97,7 +97,7 @@ function doCount(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.min_score !== 'undefined') {
|
||||
if (_.isNumeric(params.min_score)) {
|
||||
query.min_score = params.min_score * 1;
|
||||
@ -105,7 +105,7 @@ function doCount(params, callback) {
|
||||
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;
|
||||
@ -113,7 +113,7 @@ function doCount(params, callback) {
|
||||
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;
|
||||
@ -121,7 +121,7 @@ function doCount(params, callback) {
|
||||
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;
|
||||
@ -129,14 +129,10 @@ function doCount(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCount;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -26,61 +26,61 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doCreate(params, callback) {
|
||||
function doCreate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_create';
|
||||
|
||||
// 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 (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -93,7 +93,7 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
query.id = '' + params.id;
|
||||
@ -101,7 +101,7 @@ function doCreate(params, callback) {
|
||||
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;
|
||||
@ -109,7 +109,7 @@ function doCreate(params, callback) {
|
||||
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;
|
||||
@ -117,7 +117,7 @@ function doCreate(params, callback) {
|
||||
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')
|
||||
@ -127,7 +127,7 @@ function doCreate(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -138,7 +138,7 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -146,7 +146,7 @@ function doCreate(params, callback) {
|
||||
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();
|
||||
@ -156,7 +156,7 @@ function doCreate(params, callback) {
|
||||
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();
|
||||
@ -166,7 +166,7 @@ function doCreate(params, callback) {
|
||||
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;
|
||||
@ -174,7 +174,7 @@ function doCreate(params, callback) {
|
||||
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;
|
||||
@ -182,7 +182,7 @@ function doCreate(params, callback) {
|
||||
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;
|
||||
@ -193,14 +193,10 @@ function doCreate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doCreate;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -22,46 +22,46 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doDelete(params, callback) {
|
||||
function doDelete(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -74,7 +74,7 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -82,7 +82,7 @@ function doDelete(params, callback) {
|
||||
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')
|
||||
@ -92,7 +92,7 @@ function doDelete(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -103,7 +103,7 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -111,7 +111,7 @@ function doDelete(params, callback) {
|
||||
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();
|
||||
@ -121,7 +121,7 @@ function doDelete(params, callback) {
|
||||
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;
|
||||
@ -129,7 +129,7 @@ function doDelete(params, callback) {
|
||||
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;
|
||||
@ -140,14 +140,10 @@ function doDelete(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDelete;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -25,64 +25,64 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @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, callback) {
|
||||
function doDeleteByQuery(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_query';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_query';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_query';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -92,7 +92,7 @@ function doDeleteByQuery(params, callback) {
|
||||
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;
|
||||
@ -103,7 +103,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
@ -114,7 +114,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -122,7 +122,7 @@ function doDeleteByQuery(params, callback) {
|
||||
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;
|
||||
@ -133,7 +133,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -144,7 +144,7 @@ function doDeleteByQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.q !== 'undefined') {
|
||||
if (typeof params.q !== 'object' && params.q) {
|
||||
query.q = '' + params.q;
|
||||
@ -152,7 +152,7 @@ function doDeleteByQuery(params, callback) {
|
||||
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;
|
||||
@ -160,7 +160,7 @@ function doDeleteByQuery(params, callback) {
|
||||
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;
|
||||
@ -168,7 +168,7 @@ function doDeleteByQuery(params, callback) {
|
||||
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();
|
||||
@ -178,14 +178,10 @@ function doDeleteByQuery(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doDeleteByQuery;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [exists](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -15,48 +15,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doExists(params, callback) {
|
||||
function doExists(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -66,7 +66,7 @@ function doExists(params, callback) {
|
||||
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;
|
||||
@ -74,7 +74,7 @@ function doExists(params, callback) {
|
||||
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')
|
||||
@ -84,7 +84,7 @@ function doExists(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -94,7 +94,7 @@ function doExists(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -102,14 +102,16 @@ function doExists(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
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;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var defaultOperatorOptions = ['AND', 'OR'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [explain](http://elasticsearch.org/guide/reference/api/explain/) request
|
||||
*
|
||||
@ -27,55 +27,55 @@ var defaultOperatorOptions = ['AND', 'OR'];
|
||||
* @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, callback) {
|
||||
function doExplain(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_explain';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -87,7 +87,7 @@ function doExplain(params, callback) {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
if (typeof params.analyzer !== 'object' && params.analyzer) {
|
||||
query.analyzer = '' + params.analyzer;
|
||||
@ -95,7 +95,7 @@ function doExplain(params, callback) {
|
||||
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;
|
||||
@ -106,7 +106,7 @@ function doExplain(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -114,7 +114,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid df: ' + params.df + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -131,7 +131,7 @@ function doExplain(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lenient !== 'undefined') {
|
||||
if (params.lenient.toLowerCase && (params.lenient = params.lenient.toLowerCase())
|
||||
&& (params.lenient === 'no' || params.lenient === 'off')
|
||||
@ -141,7 +141,7 @@ function doExplain(params, callback) {
|
||||
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')
|
||||
@ -151,7 +151,7 @@ function doExplain(params, callback) {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -159,7 +159,7 @@ function doExplain(params, callback) {
|
||||
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;
|
||||
@ -167,7 +167,7 @@ function doExplain(params, callback) {
|
||||
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;
|
||||
@ -175,7 +175,7 @@ function doExplain(params, callback) {
|
||||
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;
|
||||
@ -183,7 +183,7 @@ function doExplain(params, callback) {
|
||||
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;
|
||||
@ -191,7 +191,7 @@ function doExplain(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -208,7 +208,7 @@ function doExplain(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -225,7 +225,7 @@ function doExplain(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -242,14 +242,10 @@ function doExplain(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doExplain;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -19,48 +19,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doGet(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -79,7 +79,7 @@ function doGet(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -87,7 +87,7 @@ function doGet(params, callback) {
|
||||
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;
|
||||
@ -95,7 +95,7 @@ function doGet(params, callback) {
|
||||
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')
|
||||
@ -105,7 +105,7 @@ function doGet(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -115,7 +115,7 @@ function doGet(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -123,7 +123,7 @@ function doGet(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -140,7 +140,7 @@ function doGet(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -157,7 +157,7 @@ function doGet(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -174,14 +174,10 @@ function doGet(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGet;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [get_source](http://elasticsearch.org/guide/reference/api/get/) request
|
||||
@ -17,48 +17,48 @@ var _ = require('../lib/toolbelt')
|
||||
* @param {boolean} params.refresh - Refresh the shard containing the document before performing the operation
|
||||
* @param {string} params.routing - Specific routing value
|
||||
*/
|
||||
function doGetSource(params, callback) {
|
||||
function doGetSource(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type || '_all') + '/' + encodeURIComponent(url.id) + '/_source';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -77,7 +77,7 @@ function doGetSource(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -94,7 +94,7 @@ function doGetSource(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -102,7 +102,7 @@ function doGetSource(params, callback) {
|
||||
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;
|
||||
@ -110,7 +110,7 @@ function doGetSource(params, callback) {
|
||||
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')
|
||||
@ -120,7 +120,7 @@ function doGetSource(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -130,7 +130,7 @@ function doGetSource(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -138,14 +138,10 @@ function doGetSource(params, callback) {
|
||||
throw new TypeError('Invalid routing: ' + params.routing + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doGetSource;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -27,60 +27,60 @@ var versionTypeOptions = ['internal', 'external'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {String} params.version_type - Specific version type
|
||||
*/
|
||||
function doIndex(params, callback) {
|
||||
function doIndex(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'put') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, PUT');
|
||||
}
|
||||
} else {
|
||||
request.method = 'post';
|
||||
request.method = 'POST';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'undefined') {
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '';
|
||||
|
||||
// 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 (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -93,7 +93,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.op_type !== 'undefined') {
|
||||
if (_.contains(opTypeOptions, params.op_type)) {
|
||||
query.op_type = params.op_type;
|
||||
@ -104,7 +104,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.parent !== 'undefined') {
|
||||
if (typeof params.parent !== 'object' && params.parent) {
|
||||
query.parent = '' + params.parent;
|
||||
@ -112,7 +112,7 @@ function doIndex(params, callback) {
|
||||
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;
|
||||
@ -120,7 +120,7 @@ function doIndex(params, callback) {
|
||||
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')
|
||||
@ -130,7 +130,7 @@ function doIndex(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -141,7 +141,7 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
if (typeof params.routing !== 'object' && params.routing) {
|
||||
query.routing = '' + params.routing;
|
||||
@ -149,7 +149,7 @@ function doIndex(params, callback) {
|
||||
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();
|
||||
@ -159,7 +159,7 @@ function doIndex(params, callback) {
|
||||
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();
|
||||
@ -169,7 +169,7 @@ function doIndex(params, callback) {
|
||||
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;
|
||||
@ -177,7 +177,7 @@ function doIndex(params, callback) {
|
||||
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;
|
||||
@ -185,7 +185,7 @@ function doIndex(params, callback) {
|
||||
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;
|
||||
@ -196,14 +196,10 @@ function doIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndex;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -20,46 +20,46 @@ var formatOptions = ['detailed', 'text'];
|
||||
* @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, callback) {
|
||||
function doIndicesAnalyze(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_analyze';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_analyze';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.url = '/_analyze';
|
||||
request.path = '/_analyze';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
@ -69,7 +69,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
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;
|
||||
@ -77,7 +77,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
throw new TypeError('Invalid field: ' + params.field + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filters !== 'undefined') {
|
||||
switch (typeof params.filters) {
|
||||
case 'string':
|
||||
@ -94,7 +94,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
query.filters = !!params.filters;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
query.index = '' + params.index;
|
||||
@ -102,7 +102,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
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')
|
||||
@ -112,7 +112,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.text !== 'undefined') {
|
||||
if (typeof params.text !== 'object' && params.text) {
|
||||
query.text = '' + params.text;
|
||||
@ -120,7 +120,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
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;
|
||||
@ -128,7 +128,7 @@ function doIndicesAnalyze(params, callback) {
|
||||
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;
|
||||
@ -139,14 +139,10 @@ function doIndicesAnalyze(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesAnalyze;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -23,54 +23,54 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesClearCache(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_cache/clear';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_cache/clear';
|
||||
delete params.index;
|
||||
}
|
||||
else {
|
||||
request.url = '/_cache/clear';
|
||||
request.path = '/_cache/clear';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.field_data !== 'undefined') {
|
||||
@ -82,7 +82,7 @@ function doIndicesClearCache(params, callback) {
|
||||
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')
|
||||
@ -92,7 +92,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -109,7 +109,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.filter !== 'undefined') {
|
||||
if (params.filter.toLowerCase && (params.filter = params.filter.toLowerCase())
|
||||
&& (params.filter === 'no' || params.filter === 'off')
|
||||
@ -119,7 +119,7 @@ function doIndicesClearCache(params, callback) {
|
||||
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')
|
||||
@ -129,7 +129,7 @@ function doIndicesClearCache(params, callback) {
|
||||
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')
|
||||
@ -139,7 +139,7 @@ function doIndicesClearCache(params, callback) {
|
||||
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')
|
||||
@ -149,7 +149,7 @@ function doIndicesClearCache(params, callback) {
|
||||
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')
|
||||
@ -159,7 +159,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -170,7 +170,7 @@ function doIndicesClearCache(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
@ -187,7 +187,7 @@ function doIndicesClearCache(params, callback) {
|
||||
query.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.recycler !== 'undefined') {
|
||||
if (params.recycler.toLowerCase && (params.recycler = params.recycler.toLowerCase())
|
||||
&& (params.recycler === 'no' || params.recycler === 'off')
|
||||
@ -197,14 +197,10 @@ function doIndicesClearCache(params, callback) {
|
||||
query.recycler = !!params.recycler;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClearCache;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesClose(params, callback) {
|
||||
function doIndicesClose(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_close';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_close';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -51,7 +51,7 @@ function doIndicesClose(params, callback) {
|
||||
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();
|
||||
@ -61,14 +61,10 @@ function doIndicesClose(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesClose;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request
|
||||
@ -12,43 +12,43 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesCreate(params, callback) {
|
||||
function doIndicesCreate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -60,7 +60,7 @@ function doIndicesCreate(params, callback) {
|
||||
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();
|
||||
@ -70,14 +70,10 @@ function doIndicesCreate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesCreate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request
|
||||
@ -12,45 +12,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDelete(params, callback) {
|
||||
function doIndicesDelete(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
request.url = '/';
|
||||
request.path = '/';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -62,7 +62,7 @@ function doIndicesDelete(params, callback) {
|
||||
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();
|
||||
@ -72,14 +72,10 @@ function doIndicesDelete(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDelete;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,40 +12,40 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesDeleteAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + 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) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -57,7 +57,7 @@ function doIndicesDeleteAlias(params, callback) {
|
||||
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();
|
||||
@ -67,14 +67,10 @@ function doIndicesDeleteAlias(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
@ -11,49 +11,49 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesDeleteMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -65,14 +65,10 @@ function doIndicesDeleteMapping(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesDeleteTemplate(params, callback) {
|
||||
function doIndicesDeleteTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -51,7 +51,7 @@ function doIndicesDeleteTemplate(params, callback) {
|
||||
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();
|
||||
@ -61,14 +61,10 @@ function doIndicesDeleteTemplate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.delete_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -11,74 +11,74 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesDeleteWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'delete';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'DELETE';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + 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':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// 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 (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -90,14 +90,10 @@ function doIndicesDeleteWarmer(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesDeleteWarmer;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request
|
||||
@ -10,53 +10,55 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.exists
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesExists(params, callback) {
|
||||
function doIndicesExists(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, function (err, response) {
|
||||
if (err instanceof errors.NotFound) {
|
||||
cb(err, false);
|
||||
} else {
|
||||
cb(err, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = doIndicesExists;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -13,63 +13,63 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesExistsAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -82,14 +82,16 @@ function doIndicesExistsAlias(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
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;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -13,58 +13,58 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesExistsType(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: _.union([404], params.ignore)
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'head';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'HEAD';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -77,14 +77,16 @@ function doIndicesExistsType(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
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;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -16,53 +16,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesFlush(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_flush';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_flush';
|
||||
}
|
||||
else {
|
||||
request.url = '/_flush';
|
||||
request.path = '/_flush';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.force !== 'undefined') {
|
||||
@ -74,7 +74,7 @@ function doIndicesFlush(params, callback) {
|
||||
query.force = !!params.force;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.full !== 'undefined') {
|
||||
if (params.full.toLowerCase && (params.full = params.full.toLowerCase())
|
||||
&& (params.full === 'no' || params.full === 'off')
|
||||
@ -84,7 +84,7 @@ function doIndicesFlush(params, callback) {
|
||||
query.full = !!params.full;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -95,7 +95,7 @@ function doIndicesFlush(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -105,14 +105,10 @@ function doIndicesFlush(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesFlush;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -13,63 +13,63 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesGetAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (typeof params.name) {
|
||||
case 'string':
|
||||
url.name = params.name;
|
||||
parts.name = params.name;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.name)) {
|
||||
url.name = params.name.join(',');
|
||||
parts.name = params.name.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.name = !!params.name;
|
||||
parts.name = !!params.name;
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -82,14 +82,10 @@ function doIndicesGetAlias(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -11,45 +11,45 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
*/
|
||||
function doIndicesGetAliases(params, callback) {
|
||||
function doIndicesGetAliases(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_aliases';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_aliases';
|
||||
}
|
||||
else {
|
||||
request.url = '/_aliases';
|
||||
request.path = '/_aliases';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -61,14 +61,10 @@ function doIndicesGetAliases(params, callback) {
|
||||
throw new TypeError('Invalid timeout: ' + params.timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetAliases;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
@ -10,75 +10,71 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_mapping
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetMapping(params, callback) {
|
||||
function doIndicesGetMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mapping';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mapping';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mapping';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mapping';
|
||||
request.path = '/_mapping';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
@ -10,55 +10,51 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_settings
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetSettings(params, callback) {
|
||||
function doIndicesGetSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -10,44 +10,40 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_template
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetTemplate(params, callback) {
|
||||
function doIndicesGetTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.get_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -10,84 +10,80 @@ var _ = require('../../lib/toolbelt')
|
||||
* @method indices.get_warmer
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doIndicesGetWarmer(params, callback) {
|
||||
function doIndicesGetWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'undefined') {
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + 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':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// 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 (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_warmer';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least [object Object]');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesGetWarmer;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
|
||||
@ -12,34 +12,34 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesOpen(params, callback) {
|
||||
function doIndicesOpen(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + params.index;
|
||||
parts.index = '' + params.index;
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_open';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_open';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -51,7 +51,7 @@ function doIndicesOpen(params, callback) {
|
||||
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();
|
||||
@ -61,14 +61,10 @@ function doIndicesOpen(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOpen;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -19,53 +19,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesOptimize(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_optimize';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_optimize';
|
||||
}
|
||||
else {
|
||||
request.url = '/_optimize';
|
||||
request.path = '/_optimize';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.flush !== 'undefined') {
|
||||
@ -77,7 +77,7 @@ function doIndicesOptimize(params, callback) {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -88,7 +88,7 @@ function doIndicesOptimize(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.max_num_segments !== 'undefined') {
|
||||
if (_.isNumeric(params.max_num_segments)) {
|
||||
query.max_num_segments = params.max_num_segments * 1;
|
||||
@ -96,7 +96,7 @@ function doIndicesOptimize(params, callback) {
|
||||
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')
|
||||
@ -106,11 +106,11 @@ function doIndicesOptimize(params, callback) {
|
||||
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')
|
||||
@ -120,7 +120,7 @@ function doIndicesOptimize(params, callback) {
|
||||
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')
|
||||
@ -130,14 +130,10 @@ function doIndicesOptimize(params, callback) {
|
||||
query.wait_for_merge = !!params.wait_for_merge;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesOptimize;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_alias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,47 +12,47 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesPutAlias(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + 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) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('name')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_alias/' + encodeURIComponent(url.name) + '';
|
||||
else if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_alias/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_alias';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_alias';
|
||||
}
|
||||
else {
|
||||
request.url = '/_alias';
|
||||
request.path = '/_alias';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -64,7 +64,7 @@ function doIndicesPutAlias(params, callback) {
|
||||
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();
|
||||
@ -74,14 +74,10 @@ function doIndicesPutAlias(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutAlias;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
@ -13,58 +13,58 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutMapping(params, callback) {
|
||||
function doIndicesPutMapping(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'object' && params.type) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mapping';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -76,7 +76,7 @@ function doIndicesPutMapping(params, callback) {
|
||||
query.ignore_conflicts = !!params.ignore_conflicts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
if (params.timeout instanceof Date) {
|
||||
query.timeout = params.timeout.getTime();
|
||||
@ -86,7 +86,7 @@ function doIndicesPutMapping(params, callback) {
|
||||
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();
|
||||
@ -96,14 +96,10 @@ function doIndicesPutMapping(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutMapping;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
@ -11,46 +11,46 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesPutSettings(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_settings';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_settings';
|
||||
}
|
||||
else {
|
||||
request.url = '/_settings';
|
||||
request.path = '/_settings';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.master_timeout !== 'undefined') {
|
||||
@ -62,14 +62,10 @@ function doIndicesPutSettings(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutSettings;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_template](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
|
||||
@ -13,43 +13,43 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Explicit operation timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesPutTemplate(params, callback) {
|
||||
function doIndicesPutTemplate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'put' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of PUT, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = 'put';
|
||||
request.method = 'PUT';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + params.name;
|
||||
parts.name = '' + params.name;
|
||||
} else {
|
||||
throw new TypeError('Invalid name: ' + params.name + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('name')) {
|
||||
request.url = '/_template/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('name')) {
|
||||
request.path = '/_template/' + encodeURIComponent(parts.name) + '';
|
||||
}
|
||||
else {
|
||||
throw new TypeError('Unable to build a url with those params. Supply at least [object Object]');
|
||||
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') {
|
||||
@ -59,7 +59,7 @@ function doIndicesPutTemplate(params, callback) {
|
||||
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();
|
||||
@ -69,7 +69,7 @@ function doIndicesPutTemplate(params, callback) {
|
||||
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();
|
||||
@ -79,14 +79,10 @@ function doIndicesPutTemplate(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutTemplate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.put_warmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
|
||||
@ -11,70 +11,70 @@ var _ = require('../../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doIndicesPutWarmer(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'put';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'PUT';
|
||||
|
||||
// find the paths's params
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.name !== 'object' && params.name) {
|
||||
url.name = '' + 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':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_warmer/' + encodeURIComponent(url.name) + '';
|
||||
|
||||
// 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 (url.hasOwnProperty('index') && url.hasOwnProperty('name')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_warmer/' + encodeURIComponent(url.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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -86,14 +86,10 @@ function doIndicesPutWarmer(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesPutWarmer;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -14,53 +14,53 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesRefresh(params, callback) {
|
||||
function doIndicesRefresh(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_refresh';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_refresh';
|
||||
}
|
||||
else {
|
||||
request.url = '/_refresh';
|
||||
request.path = '/_refresh';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -73,18 +73,14 @@ function doIndicesRefresh(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesRefresh;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -14,45 +14,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {String} [params.ignore_indices=none] - When performed on multiple indices, allows to ignore `missing` ones
|
||||
* @param {*} params.operation_threading - TODO: ?
|
||||
*/
|
||||
function doIndicesSegments(params, callback) {
|
||||
function doIndicesSegments(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_segments';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_segments';
|
||||
}
|
||||
else {
|
||||
request.url = '/_segments';
|
||||
request.path = '/_segments';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -65,18 +65,14 @@ function doIndicesSegments(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.operation_threading !== 'undefined') {
|
||||
query.operation_threading = params.operation_threading;
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSegments;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -13,45 +13,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesSnapshotIndex(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_gateway/snapshot';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_gateway/snapshot';
|
||||
}
|
||||
else {
|
||||
request.url = '/_gateway/snapshot';
|
||||
request.path = '/_gateway/snapshot';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -64,14 +64,10 @@ function doIndicesSnapshotIndex(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesSnapshotIndex;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -33,73 +33,73 @@ var metricFamilyOptions = ['completion', 'docs', 'fielddata', 'filter_cache', 'f
|
||||
* @param {boolean} params.store - Return information about the size of the index
|
||||
* @param {boolean} params.warmer - Return information about warmers
|
||||
*/
|
||||
function doIndicesStats(params, callback) {
|
||||
function doIndicesStats(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
url.fields = params.fields;
|
||||
parts.fields = params.fields;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.fields)) {
|
||||
url.fields = params.fields.join(',');
|
||||
parts.fields = params.fields.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid fields: ' + params.fields + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.fields = !!params.fields;
|
||||
parts.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indexing_types !== 'undefined') {
|
||||
switch (typeof params.indexing_types) {
|
||||
case 'string':
|
||||
url.indexing_types = params.indexing_types;
|
||||
parts.indexing_types = params.indexing_types;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.indexing_types)) {
|
||||
url.indexing_types = params.indexing_types.join(',');
|
||||
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:
|
||||
url.indexing_types = !!params.indexing_types;
|
||||
parts.indexing_types = !!params.indexing_types;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.metric_family !== 'undefined') {
|
||||
if (_.contains(metricFamilyOptions, params.metric_family)) {
|
||||
url.metric_family = params.metric_family;
|
||||
parts.metric_family = params.metric_family;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Invalid metric_family: ' + params.metric_family +
|
||||
@ -107,33 +107,33 @@ function doIndicesStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search_groups !== 'undefined') {
|
||||
switch (typeof params.search_groups) {
|
||||
case 'string':
|
||||
url.search_groups = params.search_groups;
|
||||
parts.search_groups = params.search_groups;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.search_groups)) {
|
||||
url.search_groups = params.search_groups.join(',');
|
||||
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:
|
||||
url.search_groups = !!params.search_groups;
|
||||
parts.search_groups = !!params.search_groups;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_stats';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_stats';
|
||||
}
|
||||
else {
|
||||
request.url = '/_stats';
|
||||
request.path = '/_stats';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.all !== 'undefined') {
|
||||
@ -145,7 +145,7 @@ function doIndicesStats(params, callback) {
|
||||
query.all = !!params.all;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.clear !== 'undefined') {
|
||||
if (params.clear.toLowerCase && (params.clear = params.clear.toLowerCase())
|
||||
&& (params.clear === 'no' || params.clear === 'off')
|
||||
@ -155,7 +155,7 @@ function doIndicesStats(params, callback) {
|
||||
query.clear = !!params.clear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.completion !== 'undefined') {
|
||||
if (params.completion.toLowerCase && (params.completion = params.completion.toLowerCase())
|
||||
&& (params.completion === 'no' || params.completion === 'off')
|
||||
@ -165,7 +165,7 @@ function doIndicesStats(params, callback) {
|
||||
query.completion = !!params.completion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.completion_fields !== 'undefined') {
|
||||
switch (typeof params.completion_fields) {
|
||||
case 'string':
|
||||
@ -182,7 +182,7 @@ function doIndicesStats(params, callback) {
|
||||
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')
|
||||
@ -192,7 +192,7 @@ function doIndicesStats(params, callback) {
|
||||
query.docs = !!params.docs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fielddata !== 'undefined') {
|
||||
if (params.fielddata.toLowerCase && (params.fielddata = params.fielddata.toLowerCase())
|
||||
&& (params.fielddata === 'no' || params.fielddata === 'off')
|
||||
@ -202,7 +202,7 @@ function doIndicesStats(params, callback) {
|
||||
query.fielddata = !!params.fielddata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fielddata_fields !== 'undefined') {
|
||||
switch (typeof params.fielddata_fields) {
|
||||
case 'string':
|
||||
@ -219,7 +219,7 @@ function doIndicesStats(params, callback) {
|
||||
query.fielddata_fields = !!params.fielddata_fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -236,7 +236,7 @@ function doIndicesStats(params, callback) {
|
||||
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')
|
||||
@ -246,7 +246,7 @@ function doIndicesStats(params, callback) {
|
||||
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')
|
||||
@ -256,7 +256,7 @@ function doIndicesStats(params, callback) {
|
||||
query.flush = !!params.flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.get !== 'undefined') {
|
||||
if (params.get.toLowerCase && (params.get = params.get.toLowerCase())
|
||||
&& (params.get === 'no' || params.get === 'off')
|
||||
@ -266,7 +266,7 @@ function doIndicesStats(params, callback) {
|
||||
query.get = !!params.get;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.groups !== 'undefined') {
|
||||
if (params.groups.toLowerCase && (params.groups = params.groups.toLowerCase())
|
||||
&& (params.groups === 'no' || params.groups === 'off')
|
||||
@ -276,7 +276,7 @@ function doIndicesStats(params, callback) {
|
||||
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')
|
||||
@ -286,7 +286,7 @@ function doIndicesStats(params, callback) {
|
||||
query.id_cache = !!params.id_cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -297,7 +297,7 @@ function doIndicesStats(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indexing !== 'undefined') {
|
||||
if (params.indexing.toLowerCase && (params.indexing = params.indexing.toLowerCase())
|
||||
&& (params.indexing === 'no' || params.indexing === 'off')
|
||||
@ -307,7 +307,7 @@ function doIndicesStats(params, callback) {
|
||||
query.indexing = !!params.indexing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.merge !== 'undefined') {
|
||||
if (params.merge.toLowerCase && (params.merge = params.merge.toLowerCase())
|
||||
&& (params.merge === 'no' || params.merge === 'off')
|
||||
@ -317,7 +317,7 @@ function doIndicesStats(params, callback) {
|
||||
query.merge = !!params.merge;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -327,7 +327,7 @@ function doIndicesStats(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.search !== 'undefined') {
|
||||
if (params.search.toLowerCase && (params.search = params.search.toLowerCase())
|
||||
&& (params.search === 'no' || params.search === 'off')
|
||||
@ -337,7 +337,7 @@ function doIndicesStats(params, callback) {
|
||||
query.search = !!params.search;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.store !== 'undefined') {
|
||||
if (params.store.toLowerCase && (params.store = params.store.toLowerCase())
|
||||
&& (params.store === 'no' || params.store === 'off')
|
||||
@ -347,7 +347,7 @@ function doIndicesStats(params, callback) {
|
||||
query.store = !!params.store;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.warmer !== 'undefined') {
|
||||
if (params.warmer.toLowerCase && (params.warmer = params.warmer.toLowerCase())
|
||||
&& (params.warmer === 'no' || params.warmer === 'off')
|
||||
@ -357,14 +357,10 @@ function doIndicesStats(params, callback) {
|
||||
query.warmer = !!params.warmer;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStats;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -16,45 +16,45 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {boolean} params.recovery - Return information about shard recovery
|
||||
* @param {boolean} params.snapshot - TODO: ?
|
||||
*/
|
||||
function doIndicesStatus(params, callback) {
|
||||
function doIndicesStatus(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'get';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'GET';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_status';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_status';
|
||||
}
|
||||
else {
|
||||
request.url = '/_status';
|
||||
request.path = '/_status';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -67,11 +67,11 @@ function doIndicesStatus(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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')
|
||||
@ -81,7 +81,7 @@ function doIndicesStatus(params, callback) {
|
||||
query.recovery = !!params.recovery;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.snapshot !== 'undefined') {
|
||||
if (params.snapshot.toLowerCase && (params.snapshot = params.snapshot.toLowerCase())
|
||||
&& (params.snapshot === 'no' || params.snapshot === 'off')
|
||||
@ -91,14 +91,10 @@ function doIndicesStatus(params, callback) {
|
||||
query.snapshot = !!params.snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesStatus;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
errors = require('../../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [indices.update_aliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
|
||||
@ -12,41 +12,41 @@ var _ = require('../../lib/toolbelt')
|
||||
* @param {Date|Number} params.timeout - Request timeout
|
||||
* @param {Date|Number} params.master_timeout - Specify timeout for connection to master
|
||||
*/
|
||||
function doIndicesUpdateAliases(params, callback) {
|
||||
function doIndicesUpdateAliases(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/_aliases';
|
||||
|
||||
|
||||
// build the path
|
||||
request.path = '/_aliases';
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.timeout !== 'undefined') {
|
||||
@ -58,7 +58,7 @@ function doIndicesUpdateAliases(params, callback) {
|
||||
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();
|
||||
@ -68,14 +68,10 @@ function doIndicesUpdateAliases(params, callback) {
|
||||
throw new TypeError('Invalid master_timeout: ' + params.master_timeout + ' should be be some sort of time.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesUpdateAliases;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../../lib/toolbelt')
|
||||
, paramHelper = require('../../lib/param_helper');
|
||||
var _ = require('../../lib/utils'),
|
||||
paramHelper = require('../../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -17,74 +17,74 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @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, callback) {
|
||||
function doIndicesValidateQuery(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_validate/query';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_validate/query';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_validate/query';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_validate/query';
|
||||
}
|
||||
else {
|
||||
request.url = '/_validate/query';
|
||||
request.path = '/_validate/query';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.explain !== 'undefined') {
|
||||
@ -96,7 +96,7 @@ function doIndicesValidateQuery(params, callback) {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
if (_.contains(ignoreIndicesOptions, params.ignore_indices)) {
|
||||
query.ignore_indices = params.ignore_indices;
|
||||
@ -107,11 +107,11 @@ function doIndicesValidateQuery(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@ -119,7 +119,7 @@ function doIndicesValidateQuery(params, callback) {
|
||||
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;
|
||||
@ -127,14 +127,10 @@ function doIndicesValidateQuery(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doIndicesValidateQuery;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [info](http://elasticsearch.org/guide/) request
|
||||
@ -10,42 +10,38 @@ var _ = require('../lib/toolbelt')
|
||||
* @method info
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
*/
|
||||
function doInfo(params, callback) {
|
||||
function doInfo(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'head') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, HEAD');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'head' : 'get';
|
||||
request.method = params.body ? 'HEAD' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
|
||||
|
||||
// build the url
|
||||
request.url = '/';
|
||||
|
||||
// build the path
|
||||
request.path = '/';
|
||||
|
||||
|
||||
// build the query string
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doInfo;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request
|
||||
@ -17,56 +17,56 @@ var _ = require('../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doMget(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_mget';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_mget';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_mget';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_mget';
|
||||
}
|
||||
else {
|
||||
request.url = '/_mget';
|
||||
request.path = '/_mget';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
@ -85,7 +85,7 @@ function doMget(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -93,7 +93,7 @@ function doMget(params, callback) {
|
||||
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')
|
||||
@ -103,7 +103,7 @@ function doMget(params, callback) {
|
||||
query.realtime = !!params.realtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.refresh !== 'undefined') {
|
||||
if (params.refresh.toLowerCase && (params.refresh = params.refresh.toLowerCase())
|
||||
&& (params.refresh === 'no' || params.refresh === 'off')
|
||||
@ -113,7 +113,7 @@ function doMget(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -130,7 +130,7 @@ function doMget(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -147,7 +147,7 @@ function doMget(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -164,14 +164,10 @@ function doMget(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMget;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [mlt](http://elasticsearch.org/guide/reference/api/more-like-this/) request
|
||||
@ -29,55 +29,55 @@ var _ = require('../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doMlt(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_mlt';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -87,7 +87,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -95,7 +95,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -103,7 +103,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -111,7 +111,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -119,7 +119,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -127,7 +127,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -135,7 +135,7 @@ function doMlt(params, callback) {
|
||||
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':
|
||||
@ -152,7 +152,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -160,7 +160,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -168,7 +168,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -176,7 +176,7 @@ function doMlt(params, callback) {
|
||||
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':
|
||||
@ -193,7 +193,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -201,7 +201,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -209,7 +209,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -217,7 +217,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -225,7 +225,7 @@ function doMlt(params, callback) {
|
||||
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;
|
||||
@ -233,7 +233,7 @@ function doMlt(params, callback) {
|
||||
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':
|
||||
@ -250,7 +250,7 @@ function doMlt(params, callback) {
|
||||
query.search_types = !!params.search_types;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.stop_words !== 'undefined') {
|
||||
switch (typeof params.stop_words) {
|
||||
case 'string':
|
||||
@ -267,14 +267,10 @@ function doMlt(params, callback) {
|
||||
query.stop_words = !!params.stop_words;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMlt;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -13,74 +13,74 @@ var searchTypeOptions = ['query_then_fetch', 'query_and_fetch', 'dfs_query_then_
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.search_type - Search operation type
|
||||
*/
|
||||
function doMsearch(params, callback) {
|
||||
function doMsearch(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: paramHelper.bulkBody(params.body, this.client.serializer) || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_msearch';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index') && parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/' + encodeURIComponent(parts.type) + '/_msearch';
|
||||
}
|
||||
else if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_msearch';
|
||||
else if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_msearch';
|
||||
}
|
||||
else {
|
||||
request.url = '/_msearch';
|
||||
request.path = '/_msearch';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.search_type !== 'undefined') {
|
||||
@ -93,14 +93,10 @@ function doMsearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doMsearch;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [percolate](http://elasticsearch.org/guide/reference/api/percolate/) request
|
||||
@ -11,49 +11,49 @@ var _ = require('../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doPercolate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'object' && params.index) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/_percolate';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object]');
|
||||
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') {
|
||||
@ -65,14 +65,10 @@ function doPercolate(params, callback) {
|
||||
query.prefer_local = !!params.prefer_local;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doPercolate;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
|
||||
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [scroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
|
||||
@ -12,46 +12,46 @@ var _ = require('../lib/toolbelt')
|
||||
* @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, callback) {
|
||||
function doScroll(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.scroll_id !== 'undefined') {
|
||||
if (typeof params.scroll_id !== 'object' && params.scroll_id) {
|
||||
url.scroll_id = '' + 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 url
|
||||
if (url.hasOwnProperty('scroll_id')) {
|
||||
request.url = '/_search/scroll/' + encodeURIComponent(url.scroll_id) + '';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('scroll_id')) {
|
||||
request.path = '/_search/scroll/' + encodeURIComponent(parts.scroll_id) + '';
|
||||
delete params.scroll_id;
|
||||
}
|
||||
else {
|
||||
request.url = '/_search/scroll';
|
||||
request.path = '/_search/scroll';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
@ -61,7 +61,7 @@ function doScroll(params, callback) {
|
||||
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;
|
||||
@ -69,14 +69,10 @@ function doScroll(params, callback) {
|
||||
throw new TypeError('Invalid scroll_id: ' + params.scroll_id + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doScroll;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -44,71 +44,71 @@ var suggestModeOptions = ['missing', 'popular', 'always'];
|
||||
* @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, callback) {
|
||||
function doSearch(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'get' || params.method === 'post') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of GET, POST');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.type !== 'undefined') {
|
||||
switch (typeof params.type) {
|
||||
case 'string':
|
||||
url.type = params.type;
|
||||
parts.type = params.type;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.type)) {
|
||||
url.type = params.type.join(',');
|
||||
parts.type = params.type.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.type = !!params.type;
|
||||
parts.type = !!params.type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('type')) {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/' + encodeURIComponent(url.type) + '/_search';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('type')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/' + encodeURIComponent(parts.type) + '/_search';
|
||||
}
|
||||
else {
|
||||
request.url = '/' + encodeURIComponent(url.index || '_all') + '/_search';
|
||||
request.path = '/' + encodeURIComponent(parts.index || '_all') + '/_search';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.analyzer !== 'undefined') {
|
||||
@ -118,7 +118,7 @@ function doSearch(params, callback) {
|
||||
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')
|
||||
@ -128,7 +128,7 @@ function doSearch(params, callback) {
|
||||
query.analyze_wildcard = !!params.analyze_wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.default_operator !== 'undefined') {
|
||||
if (_.contains(defaultOperatorOptions, params.default_operator)) {
|
||||
query.default_operator = params.default_operator;
|
||||
@ -139,7 +139,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.df !== 'undefined') {
|
||||
if (typeof params.df !== 'object' && params.df) {
|
||||
query.df = '' + params.df;
|
||||
@ -147,7 +147,7 @@ function doSearch(params, callback) {
|
||||
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')
|
||||
@ -157,7 +157,7 @@ function doSearch(params, callback) {
|
||||
query.explain = !!params.explain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -174,7 +174,7 @@ function doSearch(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.from !== 'undefined') {
|
||||
if (_.isNumeric(params.from)) {
|
||||
query.from = params.from * 1;
|
||||
@ -182,7 +182,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -193,7 +193,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.indices_boost !== 'undefined') {
|
||||
switch (typeof params.indices_boost) {
|
||||
case 'string':
|
||||
@ -210,7 +210,7 @@ function doSearch(params, callback) {
|
||||
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')
|
||||
@ -220,7 +220,7 @@ function doSearch(params, callback) {
|
||||
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')
|
||||
@ -230,7 +230,7 @@ function doSearch(params, callback) {
|
||||
query.lowercase_expanded_terms = !!params.lowercase_expanded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -238,7 +238,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -246,7 +246,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid q: ' + params.q + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.routing !== 'undefined') {
|
||||
switch (typeof params.routing) {
|
||||
case 'string':
|
||||
@ -263,7 +263,7 @@ function doSearch(params, callback) {
|
||||
query.routing = !!params.routing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.scroll !== 'undefined') {
|
||||
if (_.isNumeric(params.scroll) || _.isInterval(params.scroll)) {
|
||||
query.scroll = params.scroll;
|
||||
@ -271,7 +271,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -282,7 +282,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.size !== 'undefined') {
|
||||
if (_.isNumeric(params.size)) {
|
||||
query.size = params.size * 1;
|
||||
@ -290,7 +290,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid size: ' + params.size + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.sort !== 'undefined') {
|
||||
switch (typeof params.sort) {
|
||||
case 'string':
|
||||
@ -307,7 +307,7 @@ function doSearch(params, callback) {
|
||||
query.sort = !!params.sort;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.source !== 'undefined') {
|
||||
if (typeof params.source !== 'object' && params.source) {
|
||||
query.source = '' + params.source;
|
||||
@ -315,7 +315,7 @@ function doSearch(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source !== 'undefined') {
|
||||
switch (typeof params._source) {
|
||||
case 'string':
|
||||
@ -332,7 +332,7 @@ function doSearch(params, callback) {
|
||||
query._source = !!params._source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_exclude !== 'undefined') {
|
||||
switch (typeof params._source_exclude) {
|
||||
case 'string':
|
||||
@ -349,7 +349,7 @@ function doSearch(params, callback) {
|
||||
query._source_exclude = !!params._source_exclude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params._source_include !== 'undefined') {
|
||||
switch (typeof params._source_include) {
|
||||
case 'string':
|
||||
@ -366,7 +366,7 @@ function doSearch(params, callback) {
|
||||
query._source_include = !!params._source_include;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.stats !== 'undefined') {
|
||||
switch (typeof params.stats) {
|
||||
case 'string':
|
||||
@ -383,7 +383,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -391,7 +391,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -402,7 +402,7 @@ function doSearch(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.suggest_size !== 'undefined') {
|
||||
if (_.isNumeric(params.suggest_size)) {
|
||||
query.suggest_size = params.suggest_size * 1;
|
||||
@ -410,7 +410,7 @@ function doSearch(params, callback) {
|
||||
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;
|
||||
@ -418,7 +418,7 @@ function doSearch(params, callback) {
|
||||
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();
|
||||
@ -428,7 +428,7 @@ function doSearch(params, callback) {
|
||||
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')
|
||||
@ -438,14 +438,10 @@ function doSearch(params, callback) {
|
||||
query.version = !!params.version;
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSearch;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
errors = require('../lib/errors'),
|
||||
q = require('q');
|
||||
|
||||
var ignoreIndicesOptions = ['none', 'missing'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [suggest](http://elasticsearch.org/guide/reference/api/search/suggest/) request
|
||||
*
|
||||
@ -16,54 +16,54 @@ var ignoreIndicesOptions = ['none', 'missing'];
|
||||
* @param {string} params.routing - Specific routing value
|
||||
* @param {string} params.source - The URL-encoded request definition (instead of using request body)
|
||||
*/
|
||||
function doSuggest(params, callback) {
|
||||
function doSuggest(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
if (params.method = _.toLowerString(params.method)) {
|
||||
if (params.method === 'post' || params.method === 'get') {
|
||||
|
||||
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');
|
||||
throw new TypeError('Invalid method: should be one of POST, GET');
|
||||
}
|
||||
} else {
|
||||
request.method = params.body ? 'post' : 'get';
|
||||
request.method = params.body ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
// find the url's params
|
||||
// find the paths's params
|
||||
if (typeof params.index !== 'undefined') {
|
||||
switch (typeof params.index) {
|
||||
case 'string':
|
||||
url.index = params.index;
|
||||
parts.index = params.index;
|
||||
break;
|
||||
case 'object':
|
||||
if (_.isArray(params.index)) {
|
||||
url.index = params.index.join(',');
|
||||
parts.index = params.index.join(',');
|
||||
} else {
|
||||
throw new TypeError('Invalid index: ' + params.index + ' should be a comma seperated list, array, or boolean.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
url.index = !!params.index;
|
||||
parts.index = !!params.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/_suggest';
|
||||
|
||||
// build the path
|
||||
if (parts.hasOwnProperty('index')) {
|
||||
request.path = '/' + encodeURIComponent(parts.index) + '/_suggest';
|
||||
}
|
||||
else {
|
||||
request.url = '/_suggest';
|
||||
request.path = '/_suggest';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// build the query string
|
||||
if (typeof params.ignore_indices !== 'undefined') {
|
||||
@ -76,7 +76,7 @@ function doSuggest(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.preference !== 'undefined') {
|
||||
if (typeof params.preference !== 'object' && params.preference) {
|
||||
query.preference = '' + params.preference;
|
||||
@ -84,7 +84,7 @@ function doSuggest(params, callback) {
|
||||
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;
|
||||
@ -92,7 +92,7 @@ function doSuggest(params, callback) {
|
||||
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;
|
||||
@ -100,14 +100,10 @@ function doSuggest(params, callback) {
|
||||
throw new TypeError('Invalid source: ' + params.source + ' should be a string.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doSuggest;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var _ = require('../lib/toolbelt')
|
||||
, paramHelper = require('../lib/param_helper');
|
||||
var _ = require('../lib/utils'),
|
||||
paramHelper = require('../lib/param_helper'),
|
||||
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
|
||||
*
|
||||
@ -28,47 +28,47 @@ var replicationOptions = ['sync', 'async'];
|
||||
* @param {number} params.version - Explicit version number for concurrency control
|
||||
* @param {number} params.version_type - Explicit version number for concurrency control
|
||||
*/
|
||||
function doUpdate(params, callback) {
|
||||
function doUpdate(params, cb) {
|
||||
params = params || {};
|
||||
|
||||
var request = {
|
||||
ignore: params.ignore,
|
||||
body: params.body || null
|
||||
}
|
||||
, url = {}
|
||||
, parts = {}
|
||||
, query = {}
|
||||
, responseOpts = {};
|
||||
|
||||
request.method = 'post';
|
||||
|
||||
// find the url's params
|
||||
request.method = 'POST';
|
||||
|
||||
// find the paths's params
|
||||
if (typeof params.id !== 'object' && params.id) {
|
||||
url.id = '' + 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) {
|
||||
url.index = '' + 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) {
|
||||
url.type = '' + params.type;
|
||||
parts.type = '' + params.type;
|
||||
} else {
|
||||
throw new TypeError('Invalid type: ' + params.type + ' should be a string.');
|
||||
}
|
||||
|
||||
|
||||
// build the url
|
||||
if (url.hasOwnProperty('index') && url.hasOwnProperty('type') && url.hasOwnProperty('id')) {
|
||||
request.url = '/' + encodeURIComponent(url.index) + '/' + encodeURIComponent(url.type) + '/' + encodeURIComponent(url.id) + '/_update';
|
||||
|
||||
// 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 url with those params. Supply at least [object Object], [object Object], [object Object]');
|
||||
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') {
|
||||
@ -81,7 +81,7 @@ function doUpdate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.fields !== 'undefined') {
|
||||
switch (typeof params.fields) {
|
||||
case 'string':
|
||||
@ -98,7 +98,7 @@ function doUpdate(params, callback) {
|
||||
query.fields = !!params.fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.lang !== 'undefined') {
|
||||
if (typeof params.lang !== 'object' && params.lang) {
|
||||
query.lang = '' + params.lang;
|
||||
@ -106,7 +106,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -114,7 +114,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -122,7 +122,7 @@ function doUpdate(params, callback) {
|
||||
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')
|
||||
@ -132,7 +132,7 @@ function doUpdate(params, callback) {
|
||||
query.refresh = !!params.refresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.replication !== 'undefined') {
|
||||
if (_.contains(replicationOptions, params.replication)) {
|
||||
query.replication = params.replication;
|
||||
@ -143,7 +143,7 @@ function doUpdate(params, callback) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof params.retry_on_conflict !== 'undefined') {
|
||||
if (_.isNumeric(params.retry_on_conflict)) {
|
||||
query.retry_on_conflict = params.retry_on_conflict * 1;
|
||||
@ -151,7 +151,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -159,11 +159,11 @@ function doUpdate(params, callback) {
|
||||
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();
|
||||
@ -173,7 +173,7 @@ function doUpdate(params, callback) {
|
||||
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();
|
||||
@ -183,7 +183,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -191,7 +191,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -199,7 +199,7 @@ function doUpdate(params, callback) {
|
||||
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;
|
||||
@ -207,14 +207,10 @@ function doUpdate(params, callback) {
|
||||
throw new TypeError('Invalid version_type: ' + params.version_type + ' should be a number.');
|
||||
}
|
||||
}
|
||||
|
||||
request.url = request.url + _.makeQueryString(query);
|
||||
|
||||
var reqPromise = this.client.request(request);
|
||||
if (callback) {
|
||||
reqPromise.then(_.bind(callback, null, null), callback);
|
||||
}
|
||||
return reqPromise;
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
this.client.request(request, cb);
|
||||
}
|
||||
|
||||
module.exports = doUpdate;
|
||||
|
||||
@ -1,14 +1,3 @@
|
||||
var _ = require('./toolbelt')
|
||||
, transports = _.requireClasses(module, './transports')
|
||||
, serializers = _.requireClasses(module, './serializers')
|
||||
, Log = require('./log')
|
||||
, api = _.reKey(_.requireDir(module, '../api'), _.camelCase);
|
||||
|
||||
// Many API commands are namespaced, like cluster.node_stats. 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 = [];
|
||||
|
||||
/**
|
||||
* A client that makes requests to Elasticsearch via a {{#crossLink "Transport"}}Transport{{/crossLink}}
|
||||
*
|
||||
@ -16,80 +5,126 @@ var namespaces = [];
|
||||
*
|
||||
* ```
|
||||
* var client = new Elasticsearch.Client({
|
||||
* transport: {
|
||||
* hosts: [
|
||||
* 'es1.net:9200',
|
||||
* 'es2.net:9200'
|
||||
* ],
|
||||
* sniff_on_start: true
|
||||
* },
|
||||
* hosts: [
|
||||
* 'es1.net:9200',
|
||||
* {
|
||||
* host: 'es2.net',
|
||||
* port: 9200
|
||||
* }
|
||||
* ],
|
||||
* sniffOnStart: true,
|
||||
* log: {
|
||||
* type: 'file',
|
||||
* level: 'warning'
|
||||
* }
|
||||
* })
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @class Client
|
||||
* @constructor
|
||||
* @param {Object} [config={}] - Configuration for the transport
|
||||
* @param {Object} [config.transport] - Transport settings passed to {{#crossLink "Transport"}}Transport Constructor{{/crossLink}}
|
||||
* @param {String|ArrayOfStrings>} [config.log] - Log output settings {{#crossLink "Log"}}Log Constructor{{/crossLink}}
|
||||
* @param {String|Array<String>} [config.log] - Log output settings {{#crossLink "Log"}}Log Constructor{{/crossLink}}
|
||||
* @param {Object} [config.trace=false] - Create a log output to stdio that only tracks trace logs
|
||||
*/
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
var _ = require('./utils'),
|
||||
ClientConfig = require('./client_config'),
|
||||
api = _.reKey(_.requireDir(module, '../api'), _.camelCase),
|
||||
q = require('q'),
|
||||
Transport = require('./transport'),
|
||||
ConnectionPool = require('./connection_pool'),
|
||||
Log = require('./log'),
|
||||
serializers = _.requireClasses(module, './serializers'),
|
||||
errors = require('./errors');
|
||||
|
||||
// Many API commands are namespaced, like cluster.node_stats. 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;
|
||||
this.config = !config || _.isPlainObject(config) ? new ClientConfig(config) : config;
|
||||
|
||||
for (var i = 0; i < namespaces.length; i++) {
|
||||
this[namespaces[i]] = new this[namespaces[i]](this);
|
||||
}
|
||||
|
||||
this.log = new Log(config && config.log, this);
|
||||
this.log = new Log(this);
|
||||
this.transport = new Transport(this);
|
||||
this.serializer = new serializers.Json(this);
|
||||
this.transport = new transports.NodeHttp(config.hosts || ['//localhost:9200'], this);
|
||||
this.connectionPool = new ConnectionPool(this);
|
||||
}
|
||||
|
||||
Client.prototype.ping = function () {
|
||||
return this.request({
|
||||
url: '/',
|
||||
method: 'HEAD',
|
||||
timeout: '100'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform a request with the client's transport
|
||||
*
|
||||
* @method request
|
||||
* @todo async body writing
|
||||
* @todo abort
|
||||
* @todo access to custom headers, modifying of request in general
|
||||
* @param {object} params
|
||||
* @param {String} params.url - The url for the request
|
||||
* @param {String} params.method - The HTTP method for the request
|
||||
* @param {String} params.body - The body of the HTTP request
|
||||
* @return {Promise} - A promise that will be resolved with the response
|
||||
* @param {Function} cb - A function to call back with (error, responseBody, responseStatus)
|
||||
*/
|
||||
Client.prototype.request = function (params) {
|
||||
|
||||
// serialize the body
|
||||
params.body = this.serializer.serialize(params.body);
|
||||
|
||||
// ensure that ignore is an array
|
||||
if (params.ignore && !_.isArray(params.ignore)) {
|
||||
params.ignore = [params.ignore];
|
||||
Client.prototype.request = function (params, cb) {
|
||||
if (typeof cb !== 'function') {
|
||||
cb = _.noop;
|
||||
}
|
||||
|
||||
// return the request's promise
|
||||
return this.transport.request(params);
|
||||
// get ignore and ensure that it's an array
|
||||
var ignore = params.ignore;
|
||||
if (ignore && !_.isArray(ignore)) {
|
||||
ignore = [ignore];
|
||||
}
|
||||
|
||||
this.transport.request(params, function (err, body, status) {
|
||||
if (err) {
|
||||
return cb(err, body, status);
|
||||
} else if ((status >= 200 && status < 300) || ignore && _.contains(ignore, status)) {
|
||||
return cb(void 0, body, status);
|
||||
} else {
|
||||
if (errors[status]) {
|
||||
return cb(new errors[status](body.error), body, status);
|
||||
} else {
|
||||
console.log({
|
||||
status: status,
|
||||
body: body
|
||||
});
|
||||
return cb(new errors.Generic('unknown error'), body, status);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* These namespaces will be instanciated
|
||||
* Ping some node to ensure that the cluster is available in some respect
|
||||
*
|
||||
* @param {Object} params - Currently just a placeholder, no params used at this time
|
||||
* @param {Function} cb - callback
|
||||
*/
|
||||
Client.prototype.ping = function (params, cb) {
|
||||
this.transport.request({
|
||||
method: 'HEAD',
|
||||
path: '/'
|
||||
}, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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) {
|
||||
|
||||
@ -112,5 +147,3 @@ _.extend(Client.prototype, _.map(api, function (action, name) {
|
||||
return makeNamespaceConstructor(action);
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
var _ = require('./toolbelt')
|
||||
, TransportAbstract = require('./transports/TransportAbstract');
|
||||
|
||||
function Interface(methods, properties) {
|
||||
this.methods = methods;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
Interface.properties.implementedBy = function (object) {
|
||||
var i;
|
||||
|
||||
if (this.methods) {
|
||||
for (i = 0; i < this.methods.length; i++) {
|
||||
if (!object[this.methods[i]] || typeof object[this.methods[i]] !== 'function') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var Transport = new Interface(
|
||||
[// methods
|
||||
''
|
||||
],
|
||||
{// properties
|
||||
'': ''
|
||||
}
|
||||
);
|
||||
|
||||
var Client = new Interface(
|
||||
[
|
||||
''
|
||||
],
|
||||
{
|
||||
transport: Transport
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
Transport: Transport,
|
||||
Client: Client
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
var _ = require('./toolbelt')
|
||||
, url = require('url')
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
var _ = require('./utils'),
|
||||
url = require('url'),
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
|
||||
@ -16,10 +16,11 @@ var _ = require('./toolbelt')
|
||||
* @param {string} output.level - One of the keys in Log.levels (error, warning, etc.)
|
||||
* @param {string} output.type - The name of the logger to use for this output
|
||||
*/
|
||||
function Log(output, client) {
|
||||
var i;
|
||||
function Log(client) {
|
||||
this.client = client;
|
||||
|
||||
output = output || 2;
|
||||
var i;
|
||||
var output = client.config.log || 2;
|
||||
|
||||
if (_.isString(output) || _.isFinite(output)) {
|
||||
output = [
|
||||
@ -39,7 +40,7 @@ function Log(output, client) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isArrayOfObjects(output)) {
|
||||
if (!_.isArrayOfPlainObjects(output)) {
|
||||
throw new TypeError('Invalid Logging output config');
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ Log.levels = [
|
||||
* @event error
|
||||
* @param {Error} error - The error object to log
|
||||
*/
|
||||
'error'
|
||||
'error',
|
||||
/**
|
||||
* Event fired for "warning" level log entries, which usually represent things
|
||||
* like correctly formatted error responses from ES (400, ...) and recoverable
|
||||
@ -72,7 +73,7 @@ Log.levels = [
|
||||
* @event warning
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'warning'
|
||||
'warning',
|
||||
/**
|
||||
* Event fired for "info" level log entries, which usually describe what a
|
||||
* client is doing (sniffing etc)
|
||||
@ -80,7 +81,7 @@ Log.levels = [
|
||||
* @event info
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'info'
|
||||
'info',
|
||||
/**
|
||||
* Event fired for "debug" level log entries, which will describe requests sent,
|
||||
* including their url (no data, response codes, or exec times)
|
||||
@ -88,7 +89,7 @@ Log.levels = [
|
||||
* @event debug
|
||||
* @param {String} message - A message to be logged
|
||||
*/
|
||||
, 'debug'
|
||||
'debug',
|
||||
/**
|
||||
* Event fired for "trace" level log entries, which provide detailed information
|
||||
* about each request made from a client, including reponse codes, execution times,
|
||||
@ -101,7 +102,7 @@ Log.levels = [
|
||||
* @param {Integer} responseStatus - The status code returned from the response
|
||||
* @param {String} responseBody - The body of the response
|
||||
*/
|
||||
, 'trace'
|
||||
'trace'
|
||||
];
|
||||
|
||||
/**
|
||||
@ -233,11 +234,11 @@ Log.prototype.debug = function (/* ...msg */) {
|
||||
* @param {String|Object} requestUrl - URL requested. If the value is an object,
|
||||
* it is expected to be the return value of Node's url.parse()
|
||||
* @param {String} body - The request's body
|
||||
* @param {Number} responseStatus - The status code returned
|
||||
* @param {String} responseBody - The body of the returned response
|
||||
* @param {String} responseBody - body returned from ES
|
||||
* @param {String} responseStatus - HTTP status code
|
||||
* @return {Boolean} - True if any outputs accepted the message
|
||||
*/
|
||||
Log.prototype.trace = function (method, requestUrl, body, responseStatus, responseBody) {
|
||||
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
|
||||
if (EventEmitter.listenerCount(this, 'trace')) {
|
||||
if (typeof requestUrl === 'object') {
|
||||
if (!requestUrl.protocol) {
|
||||
@ -245,7 +246,7 @@ Log.prototype.trace = function (method, requestUrl, body, responseStatus, respon
|
||||
}
|
||||
requestUrl = url.format(requestUrl);
|
||||
}
|
||||
return this.emit('trace', method, requestUrl, body, responseStatus, responseBody);
|
||||
return this.emit('trace', method, requestUrl, body, responseBody, responseStatus);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,59 +1,90 @@
|
||||
var _ = require('./toolbelt')
|
||||
, selectors = require('./selector');
|
||||
|
||||
var configDefaults = {
|
||||
hosts : [
|
||||
{
|
||||
host: 'localhost',
|
||||
port: 9200
|
||||
}
|
||||
],
|
||||
|
||||
//nodes_to_host_callback : construct_hosts_list,
|
||||
sniff_on_start : false,
|
||||
sniff_after_requests : 0,
|
||||
sniff_on_connection_fail : false,
|
||||
max_retries : 3,
|
||||
selector : 'roundRobin'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Abstract" class responsible for managing connection pools, sniffing for nodes, and serializing/
|
||||
* deserializing requests and ES errors.
|
||||
* 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.sniff_on_start=false] - inspect the cluster for a list of nodes upon startup
|
||||
* @param {Number} [config.sniff_after_requests=false] - Sniff after completing a certain number of request (disabled by default)
|
||||
* @param {Boolean} [config.sniff_on_connection_fail=false] - Sniff after a connection fails (disabled by default)
|
||||
* @param {Number} [config.max_retries=3] - The maximum number of time the client should retry connecting to a node
|
||||
* @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
|
||||
*/
|
||||
function Transport(config) {
|
||||
// These are all unique to each instance of client
|
||||
config = _.defaults(config || {}, configDefaults);
|
||||
|
||||
if (_.isFunction(this.opts.selector)) {
|
||||
this.selector = this.opts.selector;
|
||||
} else if (_.has(selectors, this.opts.selector)) {
|
||||
this.selector = selectors[this.opts.selector];
|
||||
} else {
|
||||
throw new Error('Invalid Selector, specify a function or selector name.');
|
||||
}
|
||||
module.exports = Transport;
|
||||
|
||||
var _ = require('./utils'),
|
||||
q = require('q'),
|
||||
ConnectionPool = require('./connection_pool'),
|
||||
errors = require('./errors');
|
||||
|
||||
function Transport(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the defaults for the Transport class
|
||||
*
|
||||
* @method defaults
|
||||
* @param {Object} update An object representing the changes to be made to the defaults.
|
||||
* @static
|
||||
* @return {undefined}
|
||||
*/
|
||||
Transport.defaults = function (update) {
|
||||
_.assign(configDefaults, update);
|
||||
|
||||
Transport.prototype.sniff = function (cb) {
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var connectionPool = this.client.connectionPool,
|
||||
nodesToHostCallback = _.bind(this.client.config.nodesToHostCallback, this);
|
||||
|
||||
this.client.request({
|
||||
path: '/_cluster/nodes'
|
||||
}, function (err, resp) {
|
||||
if (!err && resp && resp.nodes) {
|
||||
connectionPool.setHosts(nodesToHostCallback(resp.nodes));
|
||||
}
|
||||
cb(err, resp);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Transport.prototype.request = function (params, cb) {
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
var client = this.client,
|
||||
remainingRetries = client.config.maxRetries,
|
||||
connection;
|
||||
|
||||
// serialize the body
|
||||
params.body = client.serializer.serialize(params.body);
|
||||
|
||||
function sendRequestWithConnection(err, c) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
} else if (c) {
|
||||
connection = c;
|
||||
connection.request(params, checkRespForFailure);
|
||||
} else {
|
||||
cb(new errors.ConnectionError('No active nodes at this time.'));
|
||||
}
|
||||
}
|
||||
|
||||
function checkRespForFailure(err, body, status) {
|
||||
// check for posotive response
|
||||
if (err) {
|
||||
client.connectionPool.setStatus(connection, 'dead');
|
||||
checkForRetry(err, null, status);
|
||||
} else {
|
||||
client.connectionPool.setStatus(connection, 'alive');
|
||||
return cb(null, client.serializer.unserialize(body), status);
|
||||
}
|
||||
}
|
||||
|
||||
function checkForRetry(err, resp) {
|
||||
client.connectionPool.setStatus(connection, 'dead');
|
||||
if (remainingRetries) {
|
||||
remainingRetries--;
|
||||
client.connectionPool.select(sendRequestWithConnection);
|
||||
} else {
|
||||
return cb(err, null);
|
||||
}
|
||||
}
|
||||
|
||||
client.connectionPool.select(sendRequestWithConnection);
|
||||
};
|
||||
|
||||
86
src/lib/client_config.js
Normal file
86
src/lib/client_config.js
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Manages the configuration of the client.
|
||||
*
|
||||
* @class ClientConfig
|
||||
* @type {Function}
|
||||
*/
|
||||
module.exports = ClientConfig;
|
||||
|
||||
var url = require('url'),
|
||||
_ = require('./utils'),
|
||||
selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase),
|
||||
connections = _.requireClasses(module, './connections'),
|
||||
extractHostPartsRE = /\[([^:]+):(\d+)]/,
|
||||
hostProtocolRE = /^([a-z]+:)?\/\//;
|
||||
|
||||
var defaultConfig = {
|
||||
hosts: [
|
||||
{
|
||||
protocol: 'http:',
|
||||
host: 'localhost',
|
||||
port: 9200
|
||||
}
|
||||
],
|
||||
connectionConstructor: 'Http',
|
||||
selector: selectors.roundRobin,
|
||||
nodesToHostCallback: function (nodes) {
|
||||
var hosts = [];
|
||||
_.each(nodes, function (node, id) {
|
||||
var hostnameMatches = extractHostPartsRE.exec(node.hostname);
|
||||
hosts.push({
|
||||
hostname: hostnameMatches[1],
|
||||
port: hostnameMatches[2],
|
||||
id: id,
|
||||
name: node.name,
|
||||
servername: node.hostname,
|
||||
version: node.version
|
||||
});
|
||||
});
|
||||
return hosts;
|
||||
},
|
||||
sniffOnStart: false,
|
||||
sniffAfterRequests: null,
|
||||
sniffOnConnectionFail: false,
|
||||
maxRetries: 3
|
||||
};
|
||||
|
||||
function ClientConfig(config) {
|
||||
_.extend(this, defaultConfig, config);
|
||||
|
||||
if (typeof this.hosts !== 'object') {
|
||||
this.hosts = [this.hosts];
|
||||
}
|
||||
|
||||
this.hosts = _.map(this.hosts, this.transformHost);
|
||||
}
|
||||
|
||||
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 + ':';
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
if (!hostProtocolRE.test(host)) {
|
||||
host = 'http://' + host;
|
||||
}
|
||||
var urlInfo = url.parse(host, false, true);
|
||||
return {
|
||||
protocol: urlInfo.protocol,
|
||||
hostname: urlInfo.hostname,
|
||||
port: urlInfo.port
|
||||
};
|
||||
};
|
||||
45
src/lib/connection.js
Normal file
45
src/lib/connection.js
Normal file
@ -0,0 +1,45 @@
|
||||
module.exports = ConnectionAbstract;
|
||||
|
||||
var _ = require('./utils'),
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Abstract class used for Connection classes
|
||||
* @param client {Client} - The client that this connection belongs to
|
||||
* @param config {Object} - a map of configuration details for this connection
|
||||
* @param [config.hostname=localhost] {String} - The hostname for the node this connection connects to
|
||||
* @param [config.port=9200] {Integer} - The port on the server that ES is listening to
|
||||
* @class ConnectionAbstract
|
||||
* @constructor
|
||||
*/
|
||||
function ConnectionAbstract(client, config, id) {
|
||||
EventEmitter.call(this);
|
||||
this.client = client;
|
||||
this.id = id;
|
||||
this.hostname = config.hostname || 'localhost';
|
||||
this.port = config.port || 9200;
|
||||
this.timeout = config.timeout || 10000;
|
||||
}
|
||||
_.inherits(ConnectionAbstract, EventEmitter);
|
||||
|
||||
/**
|
||||
* Make a request using this connection. Must be overridden by Connection classes, which can add whatever keys to
|
||||
* params that they like. These are just the basics.
|
||||
*
|
||||
* @param [params] {Object} - The parameters for the request
|
||||
* @param params.path {String} - The path for which you are requesting
|
||||
* @param params.method {String} - The HTTP method for the request (GET, HEAD, etc.)
|
||||
* @param params.timeout {Integer} - The amount of time in milliseconds that this request should be allowed to run for.
|
||||
* @param cb {Function} - A callback to be called once with `cb(err, responseBody, responseStatus)`
|
||||
*/
|
||||
ConnectionAbstract.prototype.request = function () {
|
||||
throw new Error('Connection#request must be overwritten by the Connector');
|
||||
};
|
||||
|
||||
ConnectionAbstract.prototype.ping = function () {
|
||||
return this.request({
|
||||
path: '/',
|
||||
method: 'HEAD',
|
||||
timeout: '100'
|
||||
});
|
||||
};
|
||||
@ -3,9 +3,140 @@
|
||||
* before providing them to the application
|
||||
*
|
||||
* @class ConnectionPool
|
||||
* @constructor
|
||||
* @param {object} [config={}] - an object describing the configuration for the ConnectionPool
|
||||
* @param {Client} client - The client this pool belongs to
|
||||
*/
|
||||
function ConnectionPool(config) {
|
||||
|
||||
}
|
||||
module.exports = ConnectionPool;
|
||||
|
||||
var _ = require('./utils'),
|
||||
selectors = _.reKey(_.requireDir(module, './selectors'), _.camelCase),
|
||||
connectors = _.reKey(_.requireDir(module, './connections'), _.studlyCase),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
q = require('q'),
|
||||
errors = require('./errors');
|
||||
|
||||
function ConnectionPool(client) {
|
||||
this.client = client;
|
||||
this.index = {};
|
||||
this.connections = {
|
||||
alive: [],
|
||||
dead: []
|
||||
};
|
||||
|
||||
var config = client.config;
|
||||
|
||||
// validate connectionConstructor
|
||||
if (typeof config.connectionConstructor !== 'function') {
|
||||
if (_.has(connectors, config.connectionConstructor)) {
|
||||
config.connectionConstructor = connectors[config.connectionConstructor];
|
||||
} else {
|
||||
throw new TypeError('Invalid connectionConstructor ' + config.connectionConstructor +
|
||||
', specify a function or one of ' + _.keys(connectors).join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
this.connectionConstructor = config.connectionConstructor;
|
||||
this.setNodes(config.hosts);
|
||||
}
|
||||
|
||||
ConnectionPool.prototype.setNodes = function (nodes) {
|
||||
var client = this.client;
|
||||
|
||||
if (!_.isArrayOfObjects(nodes)) {
|
||||
throw new TypeError('Invalid hosts: specify an Array of Objects with host and port keys');
|
||||
}
|
||||
|
||||
var i, id, prevIndex = _.clone(this.index), connection;
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
id = nodes[i].host + ':' + nodes[i].port;
|
||||
if (prevIndex[id]) {
|
||||
delete prevIndex[id];
|
||||
} else {
|
||||
client.log.info('Creating connection to ' + id);
|
||||
connection = new this.connectionConstructor(this.client, nodes[i]);
|
||||
if (!(connection instanceof EventEmitter)) {
|
||||
throw new Error('ConnectionConstructor does not implement the event interface');
|
||||
} else if (!EventEmitter.listenerCount(connection, 'closed')) {
|
||||
throw new Error(
|
||||
'Connection Constructor ' + this.connectionConstructor.name +
|
||||
' does not listen for the closed event. No bueno.'
|
||||
);
|
||||
}
|
||||
this.index[id] = connection;
|
||||
this.setStatus(connection, 'alive');
|
||||
}
|
||||
}
|
||||
|
||||
var toRemove = _.keys(prevIndex);
|
||||
for (i = 0; i < toRemove.length; i++) {
|
||||
client.log.info('Closing connection to ' + toRemove[i]);
|
||||
this.index[toRemove[i]].isClosed();
|
||||
delete this.index[toRemove[i]];
|
||||
}
|
||||
|
||||
client.log.info('Nodes successfully changed');
|
||||
};
|
||||
|
||||
ConnectionPool.prototype.select = function (cb) {
|
||||
var config = this.client.config;
|
||||
|
||||
if (typeof config.selector !== 'function') {
|
||||
if (_.has(selectors, config.selector)) {
|
||||
config.selector = selectors[config.selector];
|
||||
} else {
|
||||
throw new TypeError('Invalid Selector ' + config.selector + '. specify a function or one of ' + _.keys(selectors).join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.connections.alive.length) {
|
||||
if (config.selector.length > 1) {
|
||||
config.selector(this.connections.alive, cb);
|
||||
} else {
|
||||
cb(null, config.selector(this.connections.alive));
|
||||
}
|
||||
} else {
|
||||
cb(new errors.ConnectionError('No living connections'));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ConnectionPool.prototype.setStatus = function (connection, status) {
|
||||
var origStatus = connection.status, from, to, index;
|
||||
|
||||
if (origStatus === status) {
|
||||
return true;
|
||||
} else {
|
||||
this.client.log.info('connection to', _.formatUrl(connection), 'is', status);
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 'alive':
|
||||
from = this.connections.dead;
|
||||
to = this.connections.alive;
|
||||
break;
|
||||
case 'dead':
|
||||
from = this.connections.alive;
|
||||
to = this.connections.dead;
|
||||
break;
|
||||
case 'closed':
|
||||
from = this.connections[origStatus];
|
||||
break;
|
||||
}
|
||||
|
||||
if (from && from.indexOf) {
|
||||
index = from.indexOf(connection);
|
||||
if (~index) {
|
||||
from.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (to && to.indexOf) {
|
||||
index = to.indexOf(connection);
|
||||
if (!~index) {
|
||||
to.push(connection);
|
||||
}
|
||||
}
|
||||
|
||||
connection.status = status;
|
||||
connection.emit(status, origStatus);
|
||||
};
|
||||
|
||||
15
src/lib/connections/angular.js
vendored
Normal file
15
src/lib/connections/angular.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Connection that registers a module with angular, using angular's $http service
|
||||
* to communicate with ES.
|
||||
*
|
||||
* @class connections.Angular
|
||||
*/
|
||||
module.exports = AngularConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function AngularConnection() {
|
||||
|
||||
}
|
||||
_.inherits(AngularConnection, ConnectionAbstract);
|
||||
117
src/lib/connections/http.js
Normal file
117
src/lib/connections/http.js
Normal file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* A Connection that operates using Node's http module
|
||||
*
|
||||
* @param client {Client} - The Client that this class belongs to
|
||||
* @param config {Object} - Configuration options
|
||||
* @param [config.protocol=http:] {String} - The HTTP protocol that this connection will use, can be set to https:
|
||||
* @class HttpConnection
|
||||
*/
|
||||
module.exports = HttpConnection;
|
||||
|
||||
var http = require('http'),
|
||||
_ = require('../utils'),
|
||||
q = require('q'),
|
||||
errors = require('../errors'),
|
||||
ConnectionAbstract = require('../connection'),
|
||||
defaultHeaders = {
|
||||
'connection': 'keep-alive'
|
||||
};
|
||||
|
||||
|
||||
function HttpConnection(client, config) {
|
||||
ConnectionAbstract.call(this, client, config);
|
||||
|
||||
this.protocol = config.protocol || 'http:';
|
||||
if (this.protocol[this.protocol.length - 1] !== ':') {
|
||||
this.protocol = this.protocol + ':';
|
||||
}
|
||||
|
||||
this.agent = new http.Agent({
|
||||
keepAlive: true,
|
||||
// delay between the last data packet received and the first keepalive probe
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: this.client.config.maxSockets,
|
||||
maxFreeSockets: this.client.config.maxFreeSockets
|
||||
});
|
||||
|
||||
this.on('closed', function () {
|
||||
this.agent.destroy();
|
||||
this.removeAllListeners();
|
||||
});
|
||||
}
|
||||
_.inherits(HttpConnection, ConnectionAbstract);
|
||||
|
||||
HttpConnection.prototype.request = function (params, cb) {
|
||||
var request,
|
||||
response,
|
||||
status = 0,
|
||||
timeout = params.timeout || this.timeout,
|
||||
timeoutId,
|
||||
log = this.client.log;
|
||||
|
||||
var reqParams = _.defaults({
|
||||
protocol: this.protocol,
|
||||
hostname: this.hostname,
|
||||
port: this.port,
|
||||
path: params.path,
|
||||
method: _.toUpperString(params.method) || (params.body ? 'POST' : 'GET'),
|
||||
headers: _.defaults(params.headers || {}, defaultHeaders)
|
||||
});
|
||||
|
||||
// general clean-up procedure to run after the request, can only run once
|
||||
var cleanUp = function (err) {
|
||||
cleanUp = _.noop;
|
||||
|
||||
if (err) {
|
||||
log.error(err);
|
||||
}
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
if (request) {
|
||||
request.removeAllListeners();
|
||||
}
|
||||
_.nextTick(cb, err, response, status);
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
request.on('response', function (incoming) {
|
||||
status = incoming.statusCode;
|
||||
incoming.setEncoding('utf8');
|
||||
|
||||
incoming.on('data', function (d) {
|
||||
response += d;
|
||||
});
|
||||
|
||||
incoming.on('close', function (err) {
|
||||
console.log('closed');
|
||||
cleanUp(err);
|
||||
});
|
||||
|
||||
incoming.on('end', function requestComplete() {
|
||||
incoming.removeAllListeners();
|
||||
log.trace(reqParams.method, reqParams, params.body, response, status);
|
||||
cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', function (err) {
|
||||
request.abort();
|
||||
cleanUp(err);
|
||||
});
|
||||
|
||||
// timeout for the entire request, req.setTimeout only set the socket level timeout
|
||||
timeoutId = setTimeout(function () {
|
||||
request.emit('error', new errors.RequestTimeout('Request timed out at ' + timeout + 'ms'));
|
||||
}, timeout);
|
||||
|
||||
request.end(params.body);
|
||||
};
|
||||
9
src/lib/connections/jquery.js
vendored
Normal file
9
src/lib/connections/jquery.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = JqueryConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function JqueryConnection() {
|
||||
|
||||
}
|
||||
_.inherits(JqueryConnection, ConnectionAbstract);
|
||||
15
src/lib/connections/xhr.js
Normal file
15
src/lib/connections/xhr.js
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generic Transport for the browser, using the XmlHttpRequest object
|
||||
*
|
||||
* @class connections.Xhr
|
||||
*/
|
||||
|
||||
module.exports = XhrConnection;
|
||||
|
||||
var _ = require('../utils'),
|
||||
ConnectionAbstract = require('../connection');
|
||||
|
||||
function XhrConnection() {
|
||||
|
||||
}
|
||||
_.inherits(XhrConnection, ConnectionAbstract);
|
||||
@ -0,0 +1,105 @@
|
||||
var _ = require('./utils'),
|
||||
errors = module.exports;
|
||||
|
||||
function ErrorAbstract(msg) {
|
||||
Error.call(this, msg);
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
|
||||
this.message = msg;
|
||||
}
|
||||
_.inherits(ErrorAbstract, Error);
|
||||
|
||||
/**
|
||||
* Connection Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.ConnectionError = function ConnectionError(msg) {
|
||||
return new Error(msg || 'Connection Failure');
|
||||
ErrorAbstract.call(this, msg || 'Connection Failure');
|
||||
};
|
||||
_.inherits(errors.ConnectionError, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Generic Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.Generic = function Generic(msg) {
|
||||
return new Error(msg || 'Generic Error');
|
||||
ErrorAbstract.call(this, msg || 'Generic Error');
|
||||
};
|
||||
_.inherits(errors.Generic, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Request Timeout Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
errors.RequestTimeout = function RequestTimeout(msg) {
|
||||
return new Error(msg || 'RequestTimeout');
|
||||
ErrorAbstract.call(this, msg || 'Request Timeout');
|
||||
};
|
||||
_.inherits(errors.RequestTimeout, ErrorAbstract);
|
||||
|
||||
|
||||
var statusCodes = {
|
||||
|
||||
/**
|
||||
* Service Unavailable
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
503: 'Service Unavailable',
|
||||
|
||||
/**
|
||||
* Internal Server Error
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
500: 'Internal Server Error',
|
||||
|
||||
/**
|
||||
* Precondition Failed
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
412: 'Precondition Failed',
|
||||
|
||||
/**
|
||||
* Conflict
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
409: 'Conflict',
|
||||
|
||||
/**
|
||||
* Forbidden
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
403: 'Forbidden',
|
||||
|
||||
/**
|
||||
* Not Found
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
404: 'Not Found',
|
||||
|
||||
/**
|
||||
* Bad Request
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
400: 'Bad Request',
|
||||
|
||||
/**
|
||||
* Moved Permanently
|
||||
* @param {String} [msg] - An error message that will probably end up in a log.
|
||||
*/
|
||||
301: 'Moved Permanently'
|
||||
};
|
||||
|
||||
_.each(statusCodes, function (name, status) {
|
||||
var className = _.studlyCase(name);
|
||||
|
||||
function StatusCodeError(msg) {
|
||||
return new Error(msg || name);
|
||||
ErrorAbstract.call(this, msg || name);
|
||||
}
|
||||
|
||||
_.inherits(StatusCodeError, ErrorAbstract);
|
||||
errors[className] = StatusCodeError;
|
||||
errors[status] = StatusCodeError;
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user