Zinc

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

与需要几十个旋钮才能理解和调整的 elasticsearch 不同,它非常简单且易于操作。

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

为什么Zinc

唯一可行的搜索解决方案是 elasticsearch,它虽然是一个非常好的产品,但它很复杂,需要大量资源,而且已经有十多年的历史了。我构建了这个工具,因此人们可以更轻松地使用全文搜索索引,而无需做很多工作。

特征:

  1. 提供全文索引功能
  2. 用于安装和运行的单个二进制文件。二进制文件适用于多个平台的发行版。
  3. 用于查询用 Vue 编写的数据的 Web UI
  4. 与用于摄取数据的 elasticsearch API 兼容(单条记录和批量 API)
  5. 开箱即用的身份验证
  6. Schema less – 无需预先定义 schema,同一索引中的不同文档可以有不同的字段。

缺少的功能:

  1. 集群和高可用性

截图

搜索画面

搜索画面 1


游戏搜索画面

用户管理画面

用户画面

入门

下载/安装/运行

可以从相应平台的发布页面下载二进制文件。

创建将存储数据的数据文件夹

$ mkdir 数据

$ FIRST_ADMIN_USER=admin FIRST_ADMIN_PASSWORD=Complexpass#123 锌

现在将浏览器指向http://localhost:4080并登录

数据摄取

Python示例

import base64, json
import requests

user = "admin"
password = "Complexpass#123"
bas64encoded_creds = base64.b64encode(bytes(user + ":" + password, "utf-8")).decode("utf-8")


data = {
    "Athlete": "DEMTSCHENKO, Albert",
    "City": "Turin",
    "Country": "RUS",
    "Discipline": "Luge",
    "Event": "Singles",
    "Gender": "Men",
    "Medal": "Silver",
    "Season": "winter",
    "Sport": "Luge",
    "Year": 2006
  }

headers = {"Content-type": "application/json", "Authorization": "Basic " + bas64encoded_creds}
index = "games3"
zinc_host = "http://localhost:4080"
zinc_url = zinc_host + "/api/" + index + "/document"

res = requests.put(zinc_url, headers=headers, data=json.dumps(data))

批量摄取 API 遵循与文档中定义的 elasticsearch API 相同的接口。

搜索

Python 示例

import base64
import json
import requests

user = "admin"
password = "Complexpass#123"
bas64encoded_creds = base64.b64encode(
    bytes(user + ":" + password, "utf-8")).decode("utf-8")


params = {
    "search_type": "match",
    "query":
    {
        "term": "DEMTSCHENKO",
        "start_time": "2021-06-02T14:28:31.894Z",
        "end_time": "2021-12-02T15:28:31.894Z"
    },
    "fields": ["_all"]
}

# params = {
#     "search_type": "querystring",
#     "query":
#     {
#         "term": "+City:Turin +Silver",
#         "start_time": "2021-06-02T14:28:31.894Z",
#         "end_time": "2021-12-02T15:28:31.894Z"
#     },
#     "fields": ["_all"]
# }

headers = {"Content-type": "application/json",
           "Authorization": "Basic " + bas64encoded_creds}
index = "games3"
zinc_host = "http://localhost:4080"
zinc_url = zinc_host + "/api/" + index + "/_search"

res = requests.post(zinc_url, headers=headers, data=json.dumps(params))

print(res.text)

输出

{"took":0,"timed_out":false,"max_score":7.6978611753656345,"hits":{"total":{"value":3},"hits":[{"_index":"games3","_type":"games3","_id":"bd3e67f0-679b-4aa4-b0f5-81b9dc86a26a","_score":7.6978611753656345,"@timestamp":"2021-10-20T04:56:39.000871Z","_source":{"Athlete":"DEMTSCHENKO, Albert","City":"Turin","Country":"RUS","Discipline":"Luge","Event":"Singles","Gender":"Men","Medal":"Silver","Season":"winter","Sport":"Luge","Year":2006}},{"_index":"games3","_type":"games3","_id":"230349d9-72b3-4225-bac7-a8ab31af046d","_score":7.6978611753656345,"@timestamp":"2021-10-20T04:56:39.215124Z","_source":{"Athlete":"DEMTSCHENKO, Albert","City":"Sochi","Country":"RUS","Discipline":"Luge","Event":"Singles","Gender":"Men","Medal":"Silver","Season":"winter","Sport":"Luge","Year":2014}},{"_index":"games3","_type":"games3","_id":"338fea31-81f2-4b56-a096-b8294fb6cc92","_score":7.671309826309841,"@timestamp":"2021-10-20T04:56:39.215067Z","_source":{"Athlete":"DEMTSCHENKO, Albert","City":"Sochi","Country":"RUS","Discipline":"Luge","Event":"Mixed Relay","Gender":"Men","Medal":"Silver","Season":"winter","Sport":"Luge","Year":2014}}]},"buckets":null,"error":""}

search_type 可以具有以下值:

  1. 所有文件
  2. 通配符
  3. 模糊
  4. 学期
  5. 日期范围
  6. 火柴
  7. 比赛
  8. 匹配短语
  9. 复句
  10. 请求参数

GitHub

查看 Github

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐