Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phambanhan/egg-elasticsearch-js
elasticsearch client for egg framework
https://github.com/phambanhan/egg-elasticsearch-js
egg egg-plugin eggjs elasticsearch
Last synced: 29 days ago
JSON representation
elasticsearch client for egg framework
- Host: GitHub
- URL: https://github.com/phambanhan/egg-elasticsearch-js
- Owner: phambanhan
- License: mit
- Created: 2019-09-24T09:57:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T03:09:41.000Z (over 5 years ago)
- Last Synced: 2024-12-03T17:04:37.952Z (about 1 month ago)
- Topics: egg, egg-plugin, eggjs, elasticsearch
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-elasticsearch-js
## Install
```bash
$ npm i egg-elasticsearch-js --save
```## Usage
```js
// {app_root}/config/plugin.js
exports.elasticsearch = {
enable: true,
package: 'egg-elasticsearch-js',
};
```## Configuration
#### Single instance```js
// {app_root}/config/config.default.js
exports.elasticsearch = {
client: {
node: 'host:port'
}
// more options: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html
};
```#### Multiple instances
```js
exports.elasticsearch = {
clients: {
es1: {
node: 'host1:port',
},
es2: {
node: 'host2:port',
}
}
};
```see [config/config.default.js](config/config.default.js) for more detail.
## Example
#### Single instance
```js
'use strict';module.exports = app => {
app.get('/', async function () {
try {
const result = await app.elasticsearch.info();
this.body = result;
} catch (error) {
this.status = 500;
this.body = error;
}
});
};
```#### Multiple instances
```js
'use strict';module.exports = app => {
app.get('/', async function () {
try {
const result1 = await app.elasticsearch.get('es1').info();
const result2 = await app.elasticsearch.get('es2').info();
this.body = {result1, result2};
} catch (error) {
this.status = 500;
this.body = error;
}
});
};
```## License
[MIT](LICENSE)