npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

brook-midway-elasticsearch

v1.0.2

Published

elasticsearch 8.x component for midwayjs

Readme

简介

这个是 midway 3.0 elasticsearch 8.x 组件 模块

安装依赖

$ npm i brook-midway-elasticsearch --save

引入组件

首先,引入 组件,在 src/configuration.ts 中导入

import { Configuration } from '@midwayjs/decorator';
import * as elasticsearch from 'midway-elasticsearch';
import { join } from 'path';

@Configuration({
  imports: [
    // ...
    elasticsearch, // 导入 elasticsearch 组件
  ],
  importConfigs: [join(__dirname, 'config')],
})
export class ContainerLifeCycle {}

配置

单客户端配置

// src/config/config.default.ts
export default {
  // ...
  config.elasticsearch = {
    client: {
      node: {
        url: new URL('http://localhost:1200'),
      },
      auth: {
        username: 'elastic',
        password: '123456',
      },
    },
  };
};

更多参数可以查看 elasticsearch 文档。

使用

我们可以在任意的代码中注入使用。

import { Provide, Controller, Inject, Get } from '@midwayjs/decorator';
import { ElasticsearchService } from 'midway-elasticsearch';

@Provide()
export class UserService {
  @Inject()
  elasticsearchService: ElasticsearchService;

  //创建或更新索引中的文档,如果目标是索引并且文档已经存在,则请求更新文档并增加其版本
  async index() {
    await this.elasticsearchService.index({
      index: 'students',
      body: {
        name: 'John Doe',
        age: 17,
        hobby: 'basketball',
      },
    });
  }

  // 返回匹配查询的结果
  async search() {
    await this.elasticsearchService.search({
      index: 'students',
      type: '_doc',
    });
  }

  // 使用脚本或部分文档更新文档。
  async update() {
    await this.elasticsearchService.update({
      index: 'students',
      id: '1',
      body: {
        doc: {
          hobby: 'swimming',
        },
      },
    });
  }

  // 删除文档
  async del() {
    await this.elasticsearchService.delete({
      index: 'students',
      id: '1',
    });
  }
}