终于有 Go 版的 Elasticsearch 了

开发 后端
企业内部搭建搜索引擎常用 Solr、Elasticsearch,它们都是使用 Java 实现的,底层依赖 Lucene,Java 相对来说占用较多内存。而今天要介绍的这个项目,目标就是作为 ES 的替代者,一个轻量级搜索引擎:Zinc。

[[440189]]

本文转载自微信公众号「polarisxu」,作者站长polaris  。转载本文请联系polarisxu公众号。

大家好,我是 polarisxu。

企业内部搭建搜索引擎常用 Solr、Elasticsearch,它们都是使用 Java 实现的,底层依赖 Lucene,Java 相对来说占用较多内存。而今天要介绍的这个项目,目标就是作为 ES 的替代者,一个轻量级搜索引擎:Zinc。

项目地址:https://github.com/prabhatsharma/zinc,该项目开源十来天,目前 Star 数 3.4k+。

Zinc 是一个全文索引的搜索引擎。它是 Elasticsearch 的轻量级替代品,可以在不到 100 MB 的 RAM 中运行。它使用 bluge 作为底层索引库。

而且,Zinc 使用 Vue 打造了一个比 Elasticsearch 更简单、更易于操作的界面。

zinc

如果你只是使用 API 获取数据并使用 kibana 进行搜索(Kibana 不支持 Zinc。Zinc 提供了自己的 UI),那么它是 Elasticsearch 的直接替代品。

Zinc 主要有如下特性:

  • 提供全文索引功能
  • 单个二进制文件即可安装、运行,支持多平台。这得益于 Go 语言
  • 用 Vue 编写的用于查询数据的 Web UI
  • 与 Elasticsearch 兼容的数据获取 API(单记录和批量 API)
  • 开箱即用的身份验证
  • Schema less - 无需预先定义 schema,同一索引中的不同文档可以有不同的字段

不过,目前 Zinc 还处于 alpha 阶段,而且缺少集群,可用性也没得到很好的验证。

关于如何安装使用,项目首页有说明,支持普通安装(可以直接下载编译好的二进制文件),也支持 Docker 和 K8S 安装使用。

我根据说明,在本地搭建后,根据提供的示例数据构建索引:

  1. $ FIRST_ADMIN_USER=admin FIRST_ADMIN_PASSWORD=Complexpass#123 ./zinc 
  2. {"level":"debug","time":"2021-12-12T22:53:51+08:00","message":"Loading indexes..."
  3. {"level":"debug","time":"2021-12-12T22:53:51+08:00","message":"Loading system indexes..."
  4. {"level":"debug","time":"2021-12-12T22:53:51+08:00","message":"Index loaded: _users"
  5. {"level":"debug","time":"2021-12-12T22:53:51+08:00","message":"Index loaded: _index_mapping"
  6. {"level":"debug","time":"2021-12-12T22:53:51+08:00","message":"Error loading .env file"
  7. [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. 
  8.  - using env: export GIN_MODE=release 
  9.  - using code: gin.SetMode(gin.ReleaseMode) 
  10.  
  11. [GIN-debug] GET    /healthz                  --> github.com/prabhatsharma/zinc/pkg/meta/v1.GetHealthz (3 handlers) 
  12. [GIN-debug] GET    /                         --> github.com/prabhatsharma/zinc/pkg/meta/v1.GUI (3 handlers) 
  13. [GIN-debug] GET    /ui/*filepath             --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers) 
  14. [GIN-debug] HEAD   /ui/*filepath             --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers) 
  15. [GIN-debug] POST   /api/login                --> github.com/prabhatsharma/zinc/pkg/handlers.ValidateCredentials (3 handlers) 
  16. [GIN-debug] PUT    /api/user                 --> github.com/prabhatsharma/zinc/pkg/handlers.CreateUpdateUser (4 handlers) 
  17. [GIN-debug] DELETE /api/user/:userID         --> github.com/prabhatsharma/zinc/pkg/handlers.DeleteUser (4 handlers) 
  18. [GIN-debug] GET    /api/users                --> github.com/prabhatsharma/zinc/pkg/handlers.GetUsers (4 handlers) 
  19. [GIN-debug] PUT    /api/index                --> github.com/prabhatsharma/zinc/pkg/handlers.CreateIndex (4 handlers) 
  20. [GIN-debug] GET    /api/index                --> github.com/prabhatsharma/zinc/pkg/handlers.ListIndexes (4 handlers) 
  21. [GIN-debug] PUT    /api/:target/document     --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  22. [GIN-debug] POST   /api/:target/_search      --> github.com/prabhatsharma/zinc/pkg/handlers.SearchIndex (4 handlers) 
  23. [GIN-debug] PUT    /es/:target/_doc/:id      --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  24. [GIN-debug] DELETE /es/:target/_doc/:id      --> github.com/prabhatsharma/zinc/pkg/handlers.DeleteDocument (4 handlers) 
  25. [GIN-debug] POST   /es/:target/_doc          --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  26. [GIN-debug] PUT    /es/:target/_create/:id   --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  27. [GIN-debug] POST   /es/:target/_create/:id   --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  28. [GIN-debug] POST   /es/:target/_update/:id   --> github.com/prabhatsharma/zinc/pkg/handlers.UpdateDocument (4 handlers) 
  29. [GIN-debug] POST   /es/_bulk                 --> github.com/prabhatsharma/zinc/pkg/handlers.BulkHandler (4 handlers) 
  30. [GIN-debug] POST   /es/:target/_bulk         --> github.com/prabhatsharma/zinc/pkg/handlers.BulkHandler (4 handlers) 
  31. [GIN-debug] Listening and serving HTTP on :4080 

访问 https://localhost:4080 即可看到上面的界面。

 

目前 Go 语言中文网的搜索使用的是 Solr,抽空尝试验证 Zinc,如果稳定、成熟,考虑迁移到 Zinc。

 

责任编辑:武晓燕 来源: polarisxu
相关推荐

2023-11-02 08:43:08

protocgo兼容

2015-09-21 09:38:48

Spotlight锁屏Windows 10

2015-07-27 18:23:13

google

2022-11-08 08:29:43

Goslog 库工具

2021-12-06 12:48:40

Gosyncatomic

2013-01-22 10:54:51

HTML5App移动应用

2015-06-25 18:58:36

Win10

2017-02-08 16:14:32

Chrome浏览器IOS

2012-05-18 11:36:21

Firefox浏览器

2022-11-02 15:35:35

Condition代码线程

2019-04-08 12:14:59

Elasticsear程序员Lucene

2019-07-24 09:59:21

iPhoneiOS 12.4数据迁移

2020-08-06 16:55:37

虚拟化底层计算机

2024-03-25 07:45:00

AI视频

2021-07-26 05:00:16

算法DfsBfs

2023-10-31 07:40:15

EslintJSHint

2021-09-16 12:10:24

物联网互联网应用

2021-03-15 13:58:42

微软开源Go

2021-10-29 15:44:11

鸿蒙HarmonyOS应用

2022-12-31 08:17:02

点赞
收藏

51CTO技术栈公众号