elasticsearch
Advanced tools
Comparing version 0.3.1 to 0.3.10
16
index.js
@@ -5,3 +5,2 @@ var | ||
indices = require('./lib/indices'), | ||
request = require('./lib/request'), | ||
@@ -19,3 +18,3 @@ // defaults applied to request if | ||
// let the magic begin | ||
function createClient (options) { | ||
function createClient (options, requestLogger) { | ||
'use strict'; | ||
@@ -25,3 +24,3 @@ | ||
Object.keys(defaults).forEach(function (key) { | ||
if (!options.hasOwnProperty(key)) { | ||
if (!options[key]) { | ||
options[key] = defaults[key]; | ||
@@ -38,7 +37,10 @@ } | ||
var | ||
req = request.initialize(options.server), | ||
client = core(options, req); | ||
request = | ||
(options.request || require('./lib/request')) | ||
.initialize(options.server, requestLogger), | ||
client = core(options, request); | ||
client.cluster = cluster(options, req); | ||
client.indices = indices(options, req); | ||
client.cluster = cluster(options, request); | ||
client.indices = indices(options, request); | ||
client.request = request; | ||
@@ -45,0 +47,0 @@ return client; |
@@ -23,4 +23,4 @@ var utils = require('./utils'); | ||
options.path = req.pathAppend('_river') + | ||
req.pathAppend(options.name); | ||
options.pathname = utils.pathAppend('_river') + | ||
utils.pathAppend(options.name); | ||
@@ -41,12 +41,11 @@ return req.delete(options, callback); | ||
var | ||
field = utils.getFieldSyntax(options), | ||
// specific exclude of indices param for this operation only | ||
params = req.formatParameters(options, paramExcludes.concat(['indices'])), | ||
path = req.pathAppend(options.indices ? '_stats' : '_nodes/stats/indices') + | ||
req.pathAppend('fielddata') + | ||
req.pathAppend(field); | ||
var field = utils.getFieldSyntax(options); | ||
options.path = path + (params ? '?' + params : ''); | ||
// specific exclude of indices param for this operation only | ||
options.query = utils.exclude(options, paramExcludes.concat(['indices'])); | ||
options.pathname = utils.pathAppend(options.indices ? '_stats' : '_nodes/stats/indices') + | ||
utils.pathAppend('fielddata') + | ||
utils.pathAppend(field); | ||
return req.get(options, callback); | ||
@@ -62,8 +61,5 @@ }; | ||
var | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster/health'); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster/health'); | ||
options.path = path + (params ? '?' + params : ''); | ||
return req.get(options, callback); | ||
@@ -80,9 +76,7 @@ }; | ||
var | ||
node = utils.getNodeSyntax(options, config), | ||
path = req.pathAppend('_nodes') + | ||
req.pathAppend(node) + | ||
req.pathAppend('hot_threads'); | ||
var node = utils.getNodeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend('_nodes') + | ||
utils.pathAppend(node) + | ||
utils.pathAppend('hot_threads'); | ||
@@ -99,10 +93,9 @@ return req.get(options, callback); | ||
var | ||
node = utils.getNodeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster/nodes') + | ||
req.pathAppend(node); | ||
var node = utils.getNodeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster/nodes') + | ||
utils.pathAppend(node); | ||
return req.get(options, callback); | ||
@@ -118,11 +111,10 @@ }; | ||
var | ||
node = utils.getNodeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster/nodes') + | ||
req.pathAppend(node) + | ||
req.pathAppend('stats'); | ||
var node = utils.getNodeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster/nodes') + | ||
utils.pathAppend(node) + | ||
utils.pathAppend('stats'); | ||
return req.get(options, callback); | ||
@@ -143,5 +135,5 @@ }; | ||
options.path = req.pathAppend('_river') + | ||
req.pathAppend(options.name) + | ||
req.pathAppend('_meta'); | ||
options.pathname = utils.pathAppend('_river') + | ||
utils.pathAppend(options.name) + | ||
utils.pathAppend('_meta'); | ||
@@ -159,7 +151,5 @@ return req.put(options, meta, callback); | ||
var | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster/reroute'); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster/reroute'); | ||
@@ -180,5 +170,5 @@ return req.post(options, commands, callback); | ||
options.path = req.pathAppend('_river') + | ||
req.pathAppend(options.name) + | ||
req.pathAppend('_meta'); | ||
options.pathname = utils.pathAppend('_river') + | ||
utils.pathAppend(options.name) + | ||
utils.pathAppend('_meta'); | ||
@@ -195,3 +185,3 @@ return req.get(options, callback); | ||
options.path = req.pathAppend('_cluster/settings'); | ||
options.pathname = utils.pathAppend('_cluster/settings'); | ||
@@ -208,12 +198,11 @@ return req.get(options, callback); | ||
var | ||
node = utils.getNodeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster') + | ||
req.pathAppend('nodes') + | ||
req.pathAppend(node) + | ||
req.pathAppend('_shutdown'); | ||
var node = utils.getNodeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster') + | ||
utils.pathAppend('nodes') + | ||
utils.pathAppend(node) + | ||
utils.pathAppend('_shutdown'); | ||
return req.post(options, callback); | ||
@@ -229,8 +218,5 @@ }; | ||
var | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend('_cluster/state'); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend('_cluster/state'); | ||
options.path = path + (params ? '?' + params : ''); | ||
return req.get(options, callback); | ||
@@ -247,3 +233,3 @@ }; | ||
options.path = req.pathAppend('_cluster/settings'); | ||
options.pathname = utils.pathAppend('_cluster/settings'); | ||
@@ -250,0 +236,0 @@ return req.put(options, data, callback); |
273
lib/core.js
@@ -34,18 +34,49 @@ var utils = require('./utils'); | ||
type = utils.getTypeSyntax(options, null), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
(index ? req.pathAppend(type) : '') + | ||
req.pathAppend('_bulk'), | ||
serializedCommands = ''; | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
(index ? utils.pathAppend(type) : '') + | ||
utils.pathAppend('_bulk'); | ||
commands.forEach(function (command) { | ||
serializedCommands += JSON.stringify(command); | ||
serializedCommands += '\n'; | ||
serializedCommands += JSON.stringify(command) + '\n'; | ||
}); | ||
options.path = path + (params ? '?' + params : ''); | ||
return req.post(options, serializedCommands, callback); | ||
}; | ||
// convenience method for bulk that specifies index action | ||
// and automatically creates appropriate action/meta entries | ||
// for the documents passed | ||
self.bulkIndex = function (options, documents, callback) { | ||
if (!callback && typeof documents === 'function') { | ||
callback = documents; | ||
documents = options; | ||
options = {}; | ||
} | ||
if (!Array.isArray(documents)) { | ||
return callback(new Error('documents provided must be in array format')); | ||
} | ||
var | ||
commands = [], | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config); | ||
documents.forEach(function (document) { | ||
commands.push({ | ||
index : { | ||
_index : index, | ||
_type : type | ||
} | ||
}); | ||
commands.push(document); | ||
}); | ||
return self.bulk(options, commands, callback); | ||
}; | ||
// http://www.elasticsearch.org/guide/reference/api/count/ | ||
@@ -67,10 +98,10 @@ self.count = function (options, query, callback) { | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
(index ? req.pathAppend(type) : '') + | ||
req.pathAppend('_count'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
(index ? utils.pathAppend(type) : '') + | ||
utils.pathAppend('_count'); | ||
if (query) { | ||
@@ -97,10 +128,10 @@ return req.post(options, query, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id); | ||
return req.delete(options, callback); | ||
@@ -124,12 +155,10 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend('_query'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
// documentation indicates DELETE method... | ||
// sending POST data via DELETE not typical | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend('_query'); | ||
return req.delete(options, query, callback); | ||
@@ -152,12 +181,20 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id); | ||
return req.head(options, function (err, data) { | ||
if (err) { | ||
if (err.statusCode && err.statusCode === 404) { | ||
data = { | ||
exists : false, | ||
statusCode : err.statusCode | ||
}; | ||
return callback(null, data); | ||
} | ||
return callback(err); | ||
@@ -186,14 +223,14 @@ } | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id) + | ||
req.pathAppend('_explain'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id) + | ||
utils.pathAppend('_explain'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, query, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, query, callback); | ||
}; | ||
@@ -225,11 +262,11 @@ | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id) + | ||
(options._source ? req.pathAppend('_source') : ''); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id) + | ||
(options._source ? utils.pathAppend('_source') : ''); | ||
return req.get(options, callback); | ||
@@ -254,11 +291,11 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id) + | ||
req.pathAppend(options.create ? '_create' : ''); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id) + | ||
utils.pathAppend(options.create ? '_create' : ''); | ||
if (options._id) { | ||
@@ -285,11 +322,11 @@ return req.put(options, doc, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id) + | ||
req.pathAppend('_mlt'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id) + | ||
utils.pathAppend('_mlt'); | ||
return req.get(options, callback); | ||
@@ -335,7 +372,7 @@ }; | ||
options.path = req.pathAppend('_mget'); | ||
options.pathname = utils.pathAppend('_mget'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, docs, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, {docs: docs}, callback); | ||
}; | ||
@@ -364,8 +401,10 @@ | ||
type = utils.getTypeSyntax(options, null), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
(index ? req.pathAppend(type) : '') + | ||
req.pathAppend('_msearch'), | ||
serializedQueries = ''; | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
(index ? utils.pathAppend(type) : '') + | ||
utils.pathAppend('_msearch'); | ||
queries.forEach(function (query) { | ||
@@ -376,7 +415,5 @@ serializedQueries += JSON.stringify(query); | ||
options.path = path + (params ? '?' + params : ''); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, serializedQueries, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, serializedQueries, callback); | ||
}; | ||
@@ -399,13 +436,13 @@ | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend('_percolate'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend('_percolate'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, doc, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, doc, callback); | ||
}; | ||
@@ -427,10 +464,10 @@ | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes.concat(['name'])), | ||
path = req.pathAppend('_percolator') + | ||
req.pathAppend(index) + | ||
req.pathAppend(options.name); | ||
index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes.concat(['name'])); | ||
options.pathname = utils.pathAppend('_percolator') + | ||
utils.pathAppend(index) + | ||
utils.pathAppend(options.name); | ||
return req.put(options, query, callback); | ||
@@ -455,13 +492,13 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend('_search'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend('_search'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, query, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, query, callback); | ||
}; | ||
@@ -482,10 +519,10 @@ | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes.concat(['name'])), | ||
path = req.pathAppend('_percolator') + | ||
req.pathAppend(index) + | ||
req.pathAppend(options.name); | ||
index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes.concat(['name'])); | ||
options.pathname = utils.pathAppend('_percolator') + | ||
utils.pathAppend(index) + | ||
utils.pathAppend(options.name); | ||
return req.delete(options, callback); | ||
@@ -513,11 +550,11 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend(options._id) + | ||
req.pathAppend('_update'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend(options._id) + | ||
utils.pathAppend('_update'); | ||
return req.post(options, doc, callback); | ||
@@ -541,13 +578,13 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend('_validate/query'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend('_validate/query'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, query, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, query, callback); | ||
}; | ||
@@ -554,0 +591,0 @@ |
@@ -20,11 +20,10 @@ var utils = require('./utils'); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = (options.alias && index ? req.pathAppend(index) : '') + | ||
(options.alias && index ? req.pathAppend('_alias') : req.pathAppend('_aliases')) + | ||
(options.alias && index ? req.pathAppend(options.alias) : ''); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = (options.alias && index ? utils.pathAppend(index) : '') + | ||
(options.alias && index ? utils.pathAppend('_alias') : utils.pathAppend('_aliases')) + | ||
(options.alias && index ? utils.pathAppend(options.alias) : ''); | ||
if (options.alias && index) { | ||
@@ -46,13 +45,13 @@ return req.put(options, data, callback); | ||
if (!options.alias) { | ||
return callback(new Error('alias is required')); | ||
options.alias = '*'; | ||
} | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_alias') + | ||
req.pathAppend(options.alias); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_alias') + | ||
utils.pathAppend(options.alias); | ||
return req.get(options, callback); | ||
@@ -69,13 +68,12 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_analyze'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_analyze'); | ||
// documentation indicates GET method... | ||
// sending POST data via GET not typical | ||
return req.get(options, data, callback); | ||
// sending POST data via GET not typical, using POST instead | ||
return req.post(options, data, callback); | ||
}; | ||
@@ -90,10 +88,9 @@ | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_cache/clear'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_cache/clear'); | ||
return req.post(options, callback); | ||
@@ -114,8 +111,6 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_close'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_close'); | ||
@@ -143,7 +138,5 @@ return req.post(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index); | ||
@@ -170,7 +163,5 @@ if (data && data.mappings) { | ||
var path = req.pathAppend('_template') + | ||
req.pathAppend(options.name); | ||
options.pathname = utils.pathAppend('_template') + | ||
utils.pathAppend(options.name); | ||
options.path = path; | ||
return req.put(options, template, callback); | ||
@@ -191,9 +182,7 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_alias') + | ||
req.pathAppend(options.alias); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_alias') + | ||
utils.pathAppend(options.alias); | ||
@@ -215,7 +204,5 @@ return req.delete(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index); | ||
@@ -239,7 +226,6 @@ return req.delete(options, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type); | ||
@@ -261,7 +247,5 @@ return req.delete(options, callback); | ||
var path = req.pathAppend('_template') + | ||
req.pathAppend(options.name); | ||
options.pathname = utils.pathAppend('_template') + | ||
utils.pathAppend(options.name); | ||
options.path = path; | ||
return req.delete(options, callback); | ||
@@ -282,9 +266,7 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_warmer') + | ||
req.pathAppend(options.name); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_warmer') + | ||
utils.pathAppend(options.name); | ||
@@ -310,10 +292,18 @@ return req.delete(options, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type); | ||
return req.head(options, function (err, data) { | ||
if (err) { | ||
if (err.statusCode && err.statusCode === 404) { | ||
data = { | ||
exists : false, | ||
statusCode : err.statusCode | ||
}; | ||
return callback(null, data); | ||
} | ||
return callback(err); | ||
@@ -333,10 +323,9 @@ } | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_flush'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_flush'); | ||
return req.post(options, callback); | ||
@@ -354,8 +343,7 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
(index ? req.pathAppend(type) : '') + | ||
req.pathAppend('_mapping'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
(index ? utils.pathAppend(type) : '') + | ||
utils.pathAppend('_mapping'); | ||
@@ -377,8 +365,6 @@ return req.get(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_open'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_open'); | ||
@@ -395,10 +381,9 @@ return req.post(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_optimize'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_optimize'); | ||
return req.post(options, callback); | ||
@@ -422,8 +407,7 @@ }; | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
(index ? req.pathAppend(type) : '') + | ||
req.pathAppend('_mapping'); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
(index ? utils.pathAppend(type) : '') + | ||
utils.pathAppend('_mapping'); | ||
@@ -448,9 +432,8 @@ return req.put(options, mapping, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type = utils.getTypeSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend(type) + | ||
req.pathAppend('_warmer') + | ||
req.pathAppend(options.name); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend(type) + | ||
utils.pathAppend('_warmer') + | ||
utils.pathAppend(options.name); | ||
@@ -467,8 +450,6 @@ return req.put(options, warmer, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_refresh'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_refresh'); | ||
@@ -485,8 +466,6 @@ return req.post(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_segments'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_segments'); | ||
@@ -508,8 +487,6 @@ return req.get(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_settings'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_settings'); | ||
@@ -526,8 +503,6 @@ return req.get(options, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_gateway/snapshot'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_gateway/snapshot'); | ||
@@ -546,10 +521,10 @@ return req.post(options, callback); | ||
index = utils.getIndexSyntax(options, config), | ||
type= utils.getTypeSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_stats') + | ||
req.pathAppend(type); | ||
type = utils.getTypeSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_stats') + | ||
utils.pathAppend(type); | ||
return req.get(options, callback); | ||
@@ -565,10 +540,9 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
params = req.formatParameters(options, paramExcludes), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_status'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path + (params ? '?' + params : ''); | ||
options.query = utils.exclude(options, paramExcludes); | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_status'); | ||
return req.get(options, callback); | ||
@@ -589,7 +563,5 @@ }; | ||
var path = req.pathAppend('_template') + | ||
req.pathAppend(options.name); | ||
options.pathname = utils.pathAppend('_template') + | ||
utils.pathAppend(options.name); | ||
options.path = path; | ||
return req.get(options, callback); | ||
@@ -606,8 +578,6 @@ }; | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_settings'); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_settings'); | ||
@@ -629,9 +599,7 @@ return req.put(options, settings, callback); | ||
var | ||
index = utils.getIndexSyntax(options, config), | ||
path = req.pathAppend(index) + | ||
req.pathAppend('_warmer') + | ||
req.pathAppend(options.name); | ||
var index = utils.getIndexSyntax(options, config); | ||
options.path = path; | ||
options.pathname = utils.pathAppend(index) + | ||
utils.pathAppend('_warmer') + | ||
utils.pathAppend(options.name); | ||
@@ -638,0 +606,0 @@ return req.get(options, callback); |
var | ||
http = require('http'), | ||
https = require('https'); | ||
https = require('https'), | ||
qs = require('querystring'), | ||
DEFAULT_TIMEOUT = 30000; | ||
/* | ||
@@ -10,9 +13,33 @@ A closure that enables basic configuration of the request | ||
*/ | ||
exports.initialize = function (options, self) { | ||
exports.initialize = function (settings, logger, self) { | ||
'use strict'; | ||
self = self || {}; | ||
self.defaults = options || {}; | ||
self.failover = { | ||
count : 0, | ||
index : 0, | ||
key : '', | ||
values : [] | ||
}; | ||
self.settings = settings || {}; | ||
/* | ||
If failover information is provided, store the options for use | ||
in the event of a connection failure. | ||
*/ | ||
['hosts', 'hostnames'].forEach(function (hostsKey) { | ||
if (self.settings[hostsKey] && Array.isArray(self.settings[hostsKey])) { | ||
// remove the "s" from the key | ||
self.failover.key = hostsKey.slice(0, -1); | ||
self.failover.values = self.settings[hostsKey]; | ||
// set the current default host/hostname | ||
self.settings[self.failover.key] = self.failover.values[self.failover.index]; | ||
// clear the failover settings from the default settings | ||
delete self.settings[hostsKey]; | ||
} | ||
}); | ||
/* | ||
Actually executes a request given the supplied options, | ||
@@ -26,2 +53,17 @@ writing the specified data and returning the result to the | ||
function exec (options, data, callback) { | ||
options = self.getRequestOptions(options); | ||
data = data || ''; | ||
if (typeof data !== 'string') { | ||
data = JSON.stringify(data); | ||
} | ||
if (!options.headers) { | ||
options.headers = {}; | ||
} | ||
options.headers['Content-Length'] = Buffer.byteLength(data); | ||
// issue #23 - ability to log http(s) requests | ||
if (logger) { | ||
logger(options); | ||
} | ||
var req = | ||
@@ -62,2 +104,3 @@ (options.secure ? https : http).request(options, function (res) { | ||
self.failover.count = 0; | ||
return callback(null, json); | ||
@@ -68,7 +111,47 @@ }); | ||
req.on('error', function (err) { | ||
var | ||
failover = | ||
self.failover.values.length > 1 && | ||
err.code && | ||
(err.code === 'ENOTFOUND' || | ||
err.code === 'ECONNREFUSED' || | ||
err.code === 'ECONNRESET'), | ||
hostOverridden = | ||
(options.hostname || options.host) !== | ||
(self.settings.hostname || self.settings.host); | ||
// if there is a connection error and the host/hostname settings | ||
// weren't overridden in the options, let's failover to the | ||
// next host/hostname if one is available | ||
if (failover && !hostOverridden) { | ||
self.failover.count++; | ||
self.failover.index = | ||
self.failover.index === self.failover.values.length - 1 ? | ||
0 : | ||
self.failover.index + 1; | ||
if (self.failover.count <= self.failover.values.length) { | ||
self.settings[self.failover.key] = self.failover.values[self.failover.index]; | ||
options[self.failover.key] = self.settings[self.failover.key]; | ||
return exec(options, data, callback); | ||
} | ||
} | ||
self.failover.count = 0; | ||
return callback(err, null); | ||
}); | ||
// timeout the connection | ||
if (options.timeout) { | ||
req.on('socket', function (socket) { | ||
socket.setTimeout(options.timeout); | ||
socket.on('timeout', function () { | ||
req.abort(); | ||
}); | ||
}); | ||
} | ||
if (data) { | ||
req.write(JSON.stringify(data)); | ||
req.write(data); | ||
} | ||
@@ -98,4 +181,8 @@ | ||
*/ | ||
function getRequestOptions (options) { | ||
var returnOptions = self.defaults; | ||
self.getRequestOptions = function (options) { | ||
var returnOptions = {}; | ||
Object.keys(self.settings).forEach(function (field) { | ||
returnOptions[field] = self.settings[field]; | ||
}); | ||
Object.keys(options).forEach(function (field) { | ||
@@ -105,4 +192,15 @@ returnOptions[field] = options[field]; | ||
// ensure default timeout is applied if one is not supplied | ||
if (typeof returnOptions.timeout === 'undefined') { | ||
returnOptions.timeout = DEFAULT_TIMEOUT; | ||
} | ||
// create `path` from pathname and query. | ||
returnOptions.path = returnOptions.pathname; | ||
if (returnOptions.query && Object.keys(returnOptions.query).length) { | ||
returnOptions.path += '?' + qs.stringify(returnOptions.query); | ||
} | ||
return returnOptions; | ||
} | ||
}; | ||
@@ -125,27 +223,6 @@ /* | ||
options.method = 'DELETE'; | ||
return exec(getRequestOptions(options), data, callback); | ||
return exec(options, data, callback); | ||
}; | ||
/* | ||
Used to format any options NOT specified in excludes as a | ||
querystring. | ||
formatParameters({ test : true, excludeMe : 'yes', other : 'kitteh' }, ['excludeMe']); | ||
Outputs: 'test=true&other=ktteh' | ||
*/ | ||
self.formatParameters = function (options, excludes) { | ||
var params; | ||
Object.keys(options).forEach(function (key) { | ||
if (excludes.indexOf(key) === -1) { | ||
params = (params || '') + key + '=' + options[key] + '&'; | ||
delete options[key]; | ||
} | ||
}); | ||
return params ? params.substring(0, params.length - 1) : ''; | ||
}; | ||
/* | ||
Issues a GET request with data (if supplied) to the server | ||
@@ -170,3 +247,3 @@ | ||
options.method = 'GET'; | ||
return exec(getRequestOptions(options), data, callback); | ||
return exec(options, data, callback); | ||
}; | ||
@@ -191,26 +268,6 @@ | ||
options.method = 'HEAD'; | ||
return exec(getRequestOptions(options), data, callback); | ||
return exec(options, data, callback); | ||
}; | ||
/* | ||
Convenience method used for building path string used | ||
when issuing the HTTP/HTTPS request. If the resource param | ||
is undefined, empty or false an empty sting is returned. | ||
If the input resource string has a value, it is returned | ||
with a '/' prepend. | ||
pathAppend('kitteh') | ||
Outputs: '/kitteh' | ||
*/ | ||
self.pathAppend = function (resource) { | ||
if (resource) { | ||
return '/' + resource; | ||
} | ||
return ''; | ||
}; | ||
/* | ||
Issues a POST request with data (if supplied) to the server | ||
@@ -225,3 +282,3 @@ */ | ||
options.method = 'POST'; | ||
return exec(getRequestOptions(options), data, callback); | ||
return exec(options, data, callback); | ||
}; | ||
@@ -239,6 +296,6 @@ | ||
options.method = 'PUT'; | ||
return exec(getRequestOptions(options), data, callback); | ||
return exec(options, data, callback); | ||
}; | ||
return self; | ||
}; | ||
}; |
@@ -152,1 +152,40 @@ /* | ||
}; | ||
/* | ||
Exclude keys from an object. | ||
*/ | ||
exports.exclude = function (obj, excludes) { | ||
'use strict'; | ||
var result = {}; | ||
Object.keys(obj).forEach(function (key) { | ||
if (excludes.indexOf(key) === -1) { | ||
result[key] = obj[key]; | ||
} | ||
}); | ||
return result; | ||
}; | ||
/* | ||
Convenience method used for building path string used | ||
when issuing the HTTP/HTTPS request. If the resource param | ||
is undefined, empty or false an empty sting is returned. | ||
If the input resource string has a value, it is returned | ||
with a '/' prepend. | ||
pathAppend('kitteh') | ||
Outputs: '/kitteh' | ||
*/ | ||
exports.pathAppend = function (resource) { | ||
'use strict'; | ||
if (resource) { | ||
return '/' + resource; | ||
} | ||
return ''; | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"main" : "index.js", | ||
"version" : "0.3.1", | ||
"version" : "0.3.10", | ||
"author" : "Nick Campbell (http://github.com/ncb000gt)", | ||
@@ -12,7 +12,9 @@ "contributors" : [ | ||
"Richard Marr (http://github.com/richmarr)", | ||
"Joshua Thomas (http://github.com/brozeph)"], | ||
"engines" : { | ||
"node" : ">= 0.8.0" | ||
"Joshua Thomas (http://github.com/brozeph)", | ||
"Brian Link (https://github.com/cpsubrian)" | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"keywords" : [ | ||
"keywords": [ | ||
"elastic", | ||
@@ -24,20 +26,21 @@ "search", | ||
], | ||
"repository" : "git://github.com/ncb000gt/node-elasticsearch.git", | ||
"license" : "MIT", | ||
"homepage" : "http://github.com/ncb000gt/node-elasticsearch", | ||
"bugs" : "http://github.com/ncb000gt/node-elasticsearch/issues", | ||
"devDependencies" : { | ||
"chai" : "*", | ||
"coveralls" : "*", | ||
"jscoverage" : "*", | ||
"jshint" : "*", | ||
"mocha" : "*", | ||
"mocha-lcov-reporter" : "*" | ||
"repository": "git://github.com/ncb000gt/node-elasticsearch.git", | ||
"license": "MIT", | ||
"homepage": "http://github.com/ncb000gt/node-elasticsearch", | ||
"bugs": "http://github.com/ncb000gt/node-elasticsearch/issues", | ||
"devDependencies": { | ||
"chai": "~1.7.2", | ||
"coveralls": "~2.0.16", | ||
"jscoverage": "~0.3.7", | ||
"jshint": "~2.1.4", | ||
"mocha": "~1.12.0", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"stact": "~0.0.11" | ||
}, | ||
"scripts" : { | ||
"coverage" : "rm -rf ./reports ; mkdir -p ./reports ; NODE_ELASTICSEARCH_COVERAGE=true mocha -R html-cov -r ./test/common.js -u bdd ./test/lib > reports/coverage.html", | ||
"pretest" : "jshint *.js ./lib/*.js ./test/*.js ; jscoverage ./lib ./lib-cov", | ||
"test" : "mocha --check-leaks -R spec -r ./test/common.js -u bdd ./test/lib", | ||
"posttest" : "NODE_ELASTICSEARCH_COVERAGE=true mocha -R mocha-lcov-reporter -r ./test/common.js -u bdd ./test/lib | ./node_modules/coveralls/bin/coveralls.js" | ||
"scripts": { | ||
"coverage": "rm -rf ./reports ; mkdir -p ./reports ; NODE_ELASTICSEARCH_COVERAGE=true mocha -R html-cov -r ./test/common.js -u bdd ./test/lib > reports/coverage.html", | ||
"pretest": "jshint *.js ./lib/*.js ./test/*.js ; jscoverage ./lib ./lib-cov", | ||
"test": "mocha --check-leaks -R spec -r ./test/common.js -u bdd ./test/lib ./test/functional", | ||
"posttest": "NODE_ELASTICSEARCH_COVERAGE=true mocha -R mocha-lcov-reporter -r ./test/common.js -u bdd ./test/lib | ./node_modules/coveralls/bin/coveralls.js" | ||
} | ||
} |
116
README.md
@@ -50,2 +50,10 @@ # node-elasticsearch | ||
You may also supply a logger for each request by passing in an optional second argument to `elasticsearch.createClient(config, requestLogger)`. This will result in every http(s) request being logged via the callback supplied to the `requestLogger` parameter. | ||
```Javascript | ||
var | ||
elasticsearch = require('elasticsearch'), | ||
es = elasticsearch.createClient(config, console.log); | ||
``` | ||
##### config._index | ||
@@ -83,3 +91,3 @@ | ||
es.indices.exist({ _index : 'canine' }, function (err, data) { | ||
// will result in a HEAD request to /canine instead of /kitteh | ||
// will result in a HEAD request to /canine instead of /kitteh | ||
}); | ||
@@ -93,3 +101,3 @@ ``` | ||
```Javascript | ||
var config = | ||
var config = { | ||
// optional - when not supplied, defaults to the following: | ||
@@ -114,6 +122,51 @@ server : { | ||
secure : true // toggles between https and http | ||
} | ||
} | ||
}; | ||
``` | ||
#### cluster support and failover | ||
Elasticsearch is pretty much rad at clustering. If you want to specify multiple servers to failover to, you may do so by either supplying an array as the value for the property `hosts` or `hostnames`: | ||
```Javascript | ||
var elasticsearch = require('elasticsearch'); | ||
var config = { | ||
_index : 'bawss', | ||
server : { | ||
hostnames : ['es1.myhost.com', 'es2.myhost.com', 'es3.myhost.com'] | ||
secure : true | ||
} | ||
}; | ||
var es = elasticsearch(config); | ||
``` | ||
If you run on different ports for each server, use the `hosts` property: | ||
```Javascript | ||
var elasticsearch = require('elasticsearch'); | ||
var config = { | ||
_index : 'bawss', | ||
server : { | ||
hosts : ['localhost:9200', 'localhost:9201', 'localhost:9202'] | ||
} | ||
}; | ||
var es = elasticsearch(config); | ||
``` | ||
#### operation timeout | ||
The default timeout for any operation against Elasticsearch is set at 30 seconds. You can override this value by specifying a timeout property in the options for the operation: | ||
```Javascript | ||
var options = { | ||
timeout : 60000 // 60 seconds | ||
}; | ||
es.bulk(options, commands, function (err, data) { | ||
// teh datas | ||
}); | ||
``` | ||
#### options for any operation | ||
@@ -146,2 +199,28 @@ | ||
*Please Note:* The default timeout is set at 30 seconds... if you are performing a large bulk insert you may need to increase this limit by specifying a higher value for `timeout` in the options parameter. | ||
This method doesn't take into account the underlying config that was used when instantiating the client. It requires index and type to be specified via the commands array or via the options parameter. Conflict will occur if one specifies a different index and type in the options than what is specified via the commands parameter. | ||
At a high level, when performing a bulk update, you must supply an array with an action object followed by the object that the action will use during execution. In the following example, the first item in the array specifies the action is `index` and the second item represents the data to index: | ||
```Javascript | ||
[ | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'hamish', breed : 'manx', color : 'tortoise' } | ||
] | ||
``` | ||
In this example, two `index` actions will be performed on the 'dieties' index and 'kitteh' type in ElasticSearch: | ||
```Javascript | ||
[ | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'dugald', breed : 'siamese', color : 'white' }, | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'keelin', breed : 'domestic long-hair', color : 'russian blue' } | ||
] | ||
``` | ||
For more information regarding bulk, please see the ElasticSearch documentation at <http://www.elasticsearch.org/guide/reference/api/bulk/> | ||
`es.bulk(options, commands, callback)` | ||
@@ -168,2 +247,29 @@ | ||
##### Bulk Index | ||
This is not a core action for ElasticSearch, but is a convenience method added to this ElasticSearch client to make bulk indexing more straight forward. Simply supply an array of documents you wish to bulk index in ElasticSearch and the method will take of the details for you. | ||
`es.bulkIndex(options, documents, callback)` | ||
```Javascript | ||
var | ||
elasticsearch = require('elasticsearch'), | ||
es = elasticsearch(); | ||
var documents = [ | ||
{ name : 'hamish', breed : 'manx', color : 'tortoise' }, | ||
{ name : 'dugald', breed : 'siamese', color : 'white' }, | ||
{ name : 'keelin', breed : 'domestic long-hair', color : 'russian blue' } | ||
]; | ||
var options = { | ||
_index : 'dieties', | ||
_type : 'kitteh' | ||
} | ||
es.bulkIndex(options, documents, function (err, data) { | ||
// teh datas | ||
}); | ||
``` | ||
##### Count | ||
@@ -197,3 +303,3 @@ | ||
`es.count(options, callback)` | ||
`es.delete(options, callback)` | ||
@@ -205,3 +311,3 @@ ```Javascript | ||
core.count(function (err, data) { | ||
core.delete({ _id : 'mbQZc_XhQDWmNCQX5KwPeA' }, function (err, data) { | ||
// teh datas | ||
@@ -208,0 +314,0 @@ }); |
@@ -11,3 +11,3 @@ var stubMethod = function (method, options, data, callback) { | ||
inputData : data, | ||
options : options | ||
options : global.req.getRequestOptions(options) | ||
}); | ||
@@ -97,1 +97,2 @@ }; | ||
global.should = chai.should(); | ||
global.assert = chai.assert; |
var clusterLib = requireWithCoverage('cluster'); | ||
describe('cluster', function () { | ||
describe('API: cluster', function () { | ||
var | ||
@@ -6,0 +6,0 @@ cluster, |
var coreLib = requireWithCoverage('core'); | ||
describe('core', function () { | ||
describe('API: core', function () { | ||
var | ||
@@ -176,2 +176,60 @@ core, | ||
describe('#bulkIndex', function () { | ||
var commands = [ | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'hamish', breed : 'manx', color : 'tortoise' }, | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'dugald', breed : 'siamese', color : 'white' }, | ||
{ index : { _index : 'dieties', _type : 'kitteh' } }, | ||
{ name : 'keelin', breed : 'domestic long-hair', color : 'russian blue' } | ||
]; | ||
var documents = [ | ||
{ name : 'hamish', breed : 'manx', color : 'tortoise' }, | ||
{ name : 'dugald', breed : 'siamese', color : 'white' }, | ||
{ name : 'keelin', breed : 'domestic long-hair', color : 'russian blue' } | ||
]; | ||
it('should allow options to be optional', function (done) { | ||
core.bulkIndex(documents, function (err, data) { | ||
should.not.exist(err); | ||
should.exist(data); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/_bulk'); | ||
done(); | ||
}); | ||
}); | ||
it('should require documents to be an array', function (done) { | ||
core.bulkIndex(documents[0], function (err, data) { | ||
should.exist(err); | ||
should.not.exist(data); | ||
done(); | ||
}); | ||
}); | ||
it('should only apply type to url when index and type are passed with options or config', function (done) { | ||
core.bulkIndex({ _index : 'test', _type : 'test' }, documents, function (err, data) { | ||
should.not.exist(err); | ||
should.exist(data); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/test/test/_bulk'); | ||
done(); | ||
}); | ||
}); | ||
it('should properly format out as newline delimited text', function (done) { | ||
core.bulkIndex(documents, function (err, data) { | ||
should.not.exist(err); | ||
should.exist(data); | ||
data.inputData.match(/\n/g).should.have.length(6); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('#count', function () { | ||
@@ -398,3 +456,3 @@ var query = { | ||
data.options.path.should.equals('/dieties/kitteh/1/_explain'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -451,3 +509,3 @@ done(); | ||
data.options.path.should.equals('/_mget'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -632,5 +690,5 @@ done(); | ||
data.options.path.should.equals('/_mget'); | ||
data.options.method.should.equals('GET'); | ||
data.inputData[0]._index.should.equals('testIndex'); | ||
data.inputData[0]._type.should.equals('testType'); | ||
data.options.method.should.equals('POST'); | ||
data.inputData.docs[0]._index.should.equals('testIndex'); | ||
data.inputData.docs[0]._type.should.equals('testType'); | ||
@@ -647,5 +705,5 @@ done(); | ||
data.options.path.should.equals('/_mget'); | ||
data.options.method.should.equals('GET'); | ||
data.inputData[0]._index.should.equals('dieties'); | ||
data.inputData[0]._type.should.equals('kitteh'); | ||
data.options.method.should.equals('POST'); | ||
data.inputData.docs[0]._index.should.equals('dieties'); | ||
data.inputData.docs[0]._type.should.equals('kitteh'); | ||
@@ -669,3 +727,3 @@ done(); | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/_msearch'); | ||
@@ -690,3 +748,3 @@ | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/dieties/_msearch'); | ||
@@ -702,3 +760,3 @@ | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/dieties/kitteh/_msearch'); | ||
@@ -752,3 +810,3 @@ | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/dieties/kitteh/_percolate'); | ||
@@ -773,3 +831,3 @@ | ||
data.options.path.should.equals('/dieties/kitteh/_search'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -843,3 +901,3 @@ done(); | ||
data.options.path.should.equals('/dieties/kitteh/_search'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -856,3 +914,3 @@ done(); | ||
data.options.path.should.equals('/dieties/_search'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -996,3 +1054,3 @@ done(); | ||
data.options.path.should.equals('/dieties/kitteh/_validate/query'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -1009,3 +1067,3 @@ done(); | ||
data.options.path.should.equals('/dieties/_validate/query'); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
@@ -1012,0 +1070,0 @@ done(); |
var indicesLib = requireWithCoverage('indices'); | ||
describe('indices', function () { | ||
describe('API: indices', function () { | ||
var | ||
@@ -64,7 +64,6 @@ indices, | ||
describe('#aliases', function () { | ||
it('should require alias to retrieve alias details', function (done) { | ||
it('should default alias to wildcard if not specified', function (done) { | ||
indices.aliases(function (err, data) { | ||
should.exist(err); | ||
should.not.exist(data); | ||
should.not.exist(err); | ||
data.options.alias.should.equals('*'); | ||
done(); | ||
@@ -112,3 +111,3 @@ }); | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/dieties/_analyze?tokenizer=keyword'); | ||
@@ -129,3 +128,3 @@ | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/_analyze?analyzer=standard'); | ||
@@ -141,3 +140,3 @@ | ||
should.exist(data); | ||
data.options.method.should.equals('GET'); | ||
data.options.method.should.equals('POST'); | ||
data.options.path.should.equals('/dieties/_analyze'); | ||
@@ -144,0 +143,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
169164
19
4497
657
2
7
6