1.0.1 • Published 6 years ago

@jxl/egg-elastic-search v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

egg-elastic-search

elastic-search 插件是为 egg 提供 elasticsearch 数据库访问的功能

此插件基于 elasticsearch-js 实现一个简单的配置封装,具体使用方法你还需要阅读elasticsearch-js的文档。

安装

$ npm i @jxl/egg-elastic-search --save

配置

通过 config/plugin.js 配置启动 MySQL 插件:

exports.elastic = {
  enable: true,
  package: '@jxl/egg-elastic-search'
}

config/config.${env}.js 配置各个环境的数据库连接信息:

单库

config.elastic = {
    client: [
      {
        host: 'myelastcisearch.com',
        auth: 'elastic_user:elastic_password',
        protocol: 'http',
        port: 9201
      }
    ]
  }

使用方式:

app.elastic.index({
  index: 'test',
  // ......
})

集群

config.elastic = {
    client: [
      {
        host: 'myelastcisearch.com1',
        auth: 'elastic_user:elastic_password',
        protocol: 'http',
        port: 9200
      },
      {
        host: 'myelastcisearch.com2',
        auth: 'elastic_user:elastic_password',
        protocol: 'http',
        port: 9200
      },
      {
        host: 'myelastcisearch.com3',
        auth: 'elastic_user:elastic_password',
        protocol: 'http',
        port: 9200
      }
    ]
  }

MIT