es
Version:
API around the ElasticSearch RESTful API -- mostly convenience.
291 lines (226 loc) • 11.6 kB
JavaScript
"use strict";
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
var utils = _interopRequireWildcard(require("./utils"));
var _reqlib = require("reqlib");
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var Cluster = /*#__PURE__*/function () {
function Cluster(config, request) {
var _context;
(0, _classCallCheck2["default"])(this, Cluster);
this.config = config;
this.paramExcludes = (0, _concat["default"])(_context = (0, _keys["default"])(config)).call(_context, ['field', 'fields', 'node', 'nodes']);
this.request = request || new _reqlib.Request(this.config);
} // http://www.elasticsearch.org/guide/reference/river/
(0, _createClass2["default"])(Cluster, [{
key: "deleteRiver",
value: function deleteRiver() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
if (!options.name) {
return callback(new Error('name is required'));
}
options.path = utils.pathAppend('_river', options.name);
return this.request["delete"](options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/
}, {
key: "fieldStats",
value: function fieldStats() {
var _context2;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
if (!options.field && !options.fields) {
return callback(new Error('fields are required'));
}
var fields = utils.getFieldSyntax(options); // specific exclude of indices param for this operation only
options.query = utils.exclude(options, (0, _concat["default"])(_context2 = this.paramExcludes).call(_context2, 'indices'));
options.query.fields = fields;
options.path = utils.pathAppend(options.indices ? '_nodes/stats/indices' : '_stats/fielddata');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-health/
}, {
key: "health",
value: function health() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_cluster/health');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/
// Warning: API is an experiment as documented on ES.org
}, {
key: "hotThreads",
value: function hotThreads() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
var node = utils.getNodeSyntax(options, this.config);
options.path = utils.pathAppend('_nodes', node, 'hot_threads');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/
}, {
key: "nodesInfo",
value: function nodesInfo() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
var node = utils.getNodeSyntax(options, this.config);
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_nodes', node);
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/
}, {
key: "nodesStats",
value: function nodesStats() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
var node = utils.getNodeSyntax(options, this.config);
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_nodes', node, 'stats');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/river/
}, {
key: "putRiver",
value: function putRiver() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var meta = arguments.length > 1 ? arguments[1] : undefined;
var callback = arguments.length > 2 ? arguments[2] : undefined;
if (!callback && typeof meta === 'function') {
callback = meta;
meta = options;
options = {};
}
if (!options.name) {
return callback(new Error('name is required'));
}
options.path = utils.pathAppend('_river', options.name, '_meta');
return this.request.put(options, meta, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-reroute/
}, {
key: "reroute",
value: function reroute() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var commands = arguments.length > 1 ? arguments[1] : undefined;
var callback = arguments.length > 2 ? arguments[2] : undefined;
if (!callback && typeof commands === 'function') {
callback = commands;
commands = options;
options = {};
}
if (!commands && options && options.commands) {
commands = options;
options = {};
}
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_cluster/reroute');
return this.request.post(options, commands, callback);
} // http://www.elasticsearch.org/guide/reference/river/
}, {
key: "rivers",
value: function rivers() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
if (!options.name) {
return callback(new Error('name is required'));
}
options.path = utils.pathAppend('_river', options.name, '_meta');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
}, {
key: "settings",
value: function settings() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
options.path = utils.pathAppend('_cluster/settings');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/
}, {
key: "shutdown",
value: function shutdown() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
var node = utils.getNodeSyntax(options, this.config);
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_cluster', 'nodes', node, '_shutdown');
return this.request.post(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-state/
}, {
key: "state",
value: function state() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments.length > 1 ? arguments[1] : undefined;
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
options.query = utils.exclude(options, this.paramExcludes);
options.path = utils.pathAppend('_cluster/state');
return this.request.get(options, callback);
} // http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
}, {
key: "updateSettings",
value: function updateSettings() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var data = arguments.length > 1 ? arguments[1] : undefined;
var callback = arguments.length > 2 ? arguments[2] : undefined;
if (!callback && typeof data === 'function') {
callback = data;
data = options;
options = {};
}
if (!data && options && (options.persistent || options["transient"])) {
data = options;
options = {};
}
options.path = utils.pathAppend('_cluster/settings');
return this.request.put(options, data, callback);
}
}]);
return Cluster;
}();
module.exports = {
Cluster: Cluster
};
//# sourceMappingURL=cluster.js.map