1.0.5 • Published 4 years ago

egg-zzes v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

egg-zzes

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

egg plugin for elasticsearch

目前支持API

search 搜索

count 统计

get 获取详细

sql.query SQL语句查询

Install

$ npm i egg-zzes --save

Usage

// {app_root}/config/plugin.js
exports.zzes = {
  enable: true,
  package: "egg-zzes",
};

Configuration

单实例

// {app_root}/config/config.default.js
exports.zzes = {
  client: {
    node: "host:port",
  },
  // more options: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html
};

多实例

exports.elasticsearch = {
  clients: {
    es1: {
      node: "host1:port",
    },
    es2: {
      node: "host2:port",
    },
  },
};

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

Example

单实例

"use strict";

class HomeController extends Controller {
  async index() {
    try {
      const res = await this.app.zzes.search({ index: "t_dict" });
      ctx.body = res;
    } catch (e) {
      ctx.body = e;
    }
  }
}

多实例

"use strict";

class HomeController extends Controller {
  async index() {
    try {
      const res1 = await this.app.zzes.get("es1").search({ index: "t_dict" });
      const res2 = await this.app.zzes.get("es2").search({ index: "t_dict" });
      ctx.body = { res1, res2 };
    } catch (e) {
      ctx.body = e;
    }
  }
}

Questions & Suggestions

Please open an issue here.

License

MIT

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago