forked from ncb000gt/node-es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 976 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var
cluster = require('./lib/cluster'),
core = require('./lib/core'),
indices = require('./lib/indices'),
// defaults applied to request if
// not supplied on instantiation
defaults = {
server : {
host : 'localhost',
port : 9200
}
};
// let the magic begin
function createClient (options) {
'use strict';
options = options || {};
Object.keys(defaults).forEach(function (key) {
if (!options[key]) {
options[key] = defaults[key];
}
});
// backwards compatibility helper... remaps 'index' to '_index'
if (options.index) {
options._index = options.index;
delete options.index;
}
var
request =
(options.request || require('./lib/request'))
.initialize(options.server),
client = core(options, request);
client.cluster = cluster(options, request);
client.indices = indices(options, request);
client.request = request;
return client;
}
// exports
exports = module.exports = createClient;
exports.createClient = createClient;