@eggplugin/es

Elasticsearch plugin for Egg.js

Usage no npm install needed!

<script type="module">
  import eggpluginEs from 'https://cdn.skypack.dev/@eggplugin/es';
</script>

README

egg-es

Elasticsearch plugin for Egg.js

NOTE: This plugin just for integrate Elasticsearch into Egg.js, more documentation please visit https://ela.st/js-client.

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Elasticsearch plugin for Egg.js

Install

$ npm i @eggplugin/es --save

Configuration

// {app_root}/config/plugin.js
exports.es = {
  enable: true,
  package: '@eggplugin/es',
};

see config/config.default.js for more detail.

Simple instance

// {app_root}/config/config.default.js
exports.es = {
  client: {
    node: 'http://localhost:9200',
    checkConnection: true, // default: true, in app.beforeStart check connection
    // ...
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Usage:

(async () => {
  // you can access to simple aws es instance using app.es.
  const es = app.es;
  const data = await es.ping();
  console.log(data);
  const result = await client.search({
    index: 'my-index',
    body: { foo: 'bar' }
  });
  console.log(result);
}).catch(console.error);

Multiple instance

exports.es = {
  // default configuration for all clients
  default: {
    // maxRetries: 5,
    // requestTimeout: 60000,
    // sniffOnStart: true
    // ...
  },
  clients: {
    // clientId, access the client instance by app.es.get('clientId')
    client1: {
      node: 'http://localhost:9200',
      // ...
    },
    client2: {
      node: 'http://localhost:9200',
      // ...
    },
    // ...
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Usage:

(async () => {
  const client1 = app.es.get('client1'); 
  const client2 = app.es.get('client2'); 
  const data1 = await client1.ping();
  const data2 = await client2.ping();
}).catch(console.error);

Questions & Suggestions

Please open an issue here.

License

MIT