egg plugin for elasticsearch
$ npm i egg-elasticsearch2 --save
// {app_root}/config/plugin.js
exports.elasticsearch2 = {
enable: true,
package: 'egg-elasticsearch2',
};
// {app_root}/config/config.default.js
exports.elasticsearch = {
host: 'host:port',
// more options: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html
};
exports.elasticsearch = {
clients: {
es1: {
host: 'host1:port',
},
es2: {
host: 'host2:port',
}
}
};
see config/config.default.js for more detail.
'use strict';
module.exports = app => {
app.get('/', function* () {
try {
const result = yield app.elasticsearch.search();
this.body = result;
} catch (error) {
this.status = 500;
this.body = error;
}
});
};
'use strict';
module.exports = app => {
app.get('/', function* () {
try {
const result1 = yield app.elasticsearch.get('es1').search();
const result2 = yield app.elasticsearch.get('es2').search();
this.body = {result1, result2};
} catch (error) {
this.status = 500;
this.body = error;
}
});
};
Please open an issue here.