All Projects → brucewar → egg-elasticsearch

brucewar / egg-elasticsearch

Licence: MIT license
elasticsearch client for egg.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to egg-elasticsearch

egg-grpc
grpc plugin for egg
Stars: ✭ 79 (+259.09%)
Mutual labels:  egg, egg-plugin
egg-weapp-sdk
Egg的微信小程序登录会话管理SDK
Stars: ✭ 111 (+404.55%)
Mutual labels:  egg, egg-plugin
Egg Socket.io
socket.io plugin for eggjs.
Stars: ✭ 209 (+850%)
Mutual labels:  egg, egg-plugin
egg-sentry
Sentry Plugin For Egg.js
Stars: ✭ 18 (-18.18%)
Mutual labels:  egg, egg-plugin
egg-session-redis
redis store for egg session
Stars: ✭ 41 (+86.36%)
Mutual labels:  egg, egg-plugin
Egg Security
Security plugin for egg, force performance too.
Stars: ✭ 204 (+827.27%)
Mutual labels:  egg, egg-plugin
egg-mailer
🥚 mailer plugin for egg
Stars: ✭ 23 (+4.55%)
Mutual labels:  egg, egg-plugin
Egg Multipart
multipart plugin for egg
Stars: ✭ 145 (+559.09%)
Mutual labels:  egg, egg-plugin
egg-exporter
Egg.js 的 Prometheus 指标收集插件,附带 Grafana 看板。
Stars: ✭ 24 (+9.09%)
Mutual labels:  egg, egg-plugin
egg-kafka-node
kafka plugin for egg.js
Stars: ✭ 36 (+63.64%)
Mutual labels:  egg, egg-plugin
egg-aop
AOP plugin for eggjs, add DI, AOP support.
Stars: ✭ 44 (+100%)
Mutual labels:  egg, egg-plugin
egg-view-react
egg view plugin for react
Stars: ✭ 89 (+304.55%)
Mutual labels:  egg, egg-plugin
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+754.55%)
Mutual labels:  egg, egg-plugin
egg-kafkajs
☎️kafka plugin for eggjs
Stars: ✭ 26 (+18.18%)
Mutual labels:  egg, egg-plugin
Egg Oauth2 Server
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Stars: ✭ 174 (+690.91%)
Mutual labels:  egg, egg-plugin
Egg Validate
validate plugin for egg
Stars: ✭ 224 (+918.18%)
Mutual labels:  egg, egg-plugin
Egg Router Plus
The missing router feature for eggjs
Stars: ✭ 117 (+431.82%)
Mutual labels:  egg, egg-plugin
Egg View Vue
vue view plugin for egg
Stars: ✭ 136 (+518.18%)
Mutual labels:  egg, egg-plugin
Egg Redis
redis plugin for egg
Stars: ✭ 234 (+963.64%)
Mutual labels:  egg, egg-plugin
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (+45.45%)
Mutual labels:  egg, egg-plugin

egg-es

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

Install

$ npm i egg-es --save

Usage

// {app_root}/config/plugin.js
exports.elasticsearch = {
  enable: true,
  package: 'egg-es',
};

Configuration

// {app_root}/config/config.default.js
exports.elasticsearch = {
  host: 'localhost:9200',
  apiVersion: '6.3'
};

Refer to elasticsearch doc for more options;

Example

// app/controller/post.js
module.exports = app => {
  return class PostController extends app.Controller {
    async index(){
      const pageNum = this.ctx.params.page;
      const perPage = this.ctx.params.per_page;
      const userQuery = this.ctx.request.body.search_query;
      const userId = this.ctx.session.userId;
      const posts = await app.elasticsearch.search({
        index: 'posts',
        from: (pageNum - 1) * perPage,
        size: perPage,
        body: {
          query: {
            filtered: {
              query: {
                match: {
                  _all: userQuery
                }
              },
              filter: {
                or: [
                  {
                    term: { privacy: 'public' }
                  }, {
                    term: { owner: userId }
                  }
                ]
              }
            }
          }
        }
      });
      this.ctx.body = posts;
    }
  }
};

Questions & Suggestions

Please open an issue here.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].