🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] > [github](https://github.com/zincsearch/zincsearch) > [文档](https://zincsearch-docs.zinc.dev/api/index/create/) ## 概述 一个轻量级的替代elasticsearch的方法,只需要最少的资源,用Go编写。 特点 * 无模式索引 * 资源利用率低 * 易于使用的轻量级 GUI * 内置身份验证 * 用于编程使用的简单 API * 与希望从 Elasticsearch 迁移到 Zinc 的应用程序兼容的 Elasticsearch API(摄取 - 单记录和批量 API)。 ## 安装 [releases](https://github.com/zincsearch/zincsearch/releases) 下载对应的安装包 运行 ``` set ZINC_FIRST_ADMIN_USER=admin set ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123 mkdir data zincsearch.exe ``` ## 快速入门 ### 导入测试数据 ``` curl -L https://github.com/zincsearch/zincsearch/releases/download/v0.1.1/olympics.ndjson.gz -o olympics.ndjson.gz gzip -d olympics.ndjson.gz curl http://localhost:4080/api/_bulk -i -u admin:Complexpass#123 --data-binary "@olympics.ndjson" ``` ### 使用go的示例 ``` package main import ( "fmt" "io" "log" "net/http" "os" "strings" ) func main() { query := ` { "index" : "hello1", "records": [ {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HAJOS, Alfred", "Country": "HUN", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Gold", "Season": "summer"}, {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HERSCHMANN, Otto", "Country": "AUT", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Silver", "Season": "summer"}, {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "CHASAPIS, Spiridon", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Silver", "Season": "summer"} ] } ` _ = query req, err := http.NewRequest("POST", "http://localhost:4080/api/_bulkv2", strings.NewReader(query)) //req, err := http.NewRequest("POST", "http://localhost:4080/api/olympics/_search", strings.NewReader(query)) if err != nil { log.Fatal(err) } req.SetBasicAuth("admin", "Complexpass#123") req.Header.Set("Content-Type", "application/json") req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36") resp, err := http.DefaultClient.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() log.Println(resp.StatusCode) body, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", body) os.WriteFile("res.txt", []byte(body), 0777) } ```