🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
* [ElasticSearch 介绍及应用场景](https://www.jianshu.com/p/8494ae9a53a7) * [ElasticSearch使用场景](https://www.cnblogs.com/cdchencw/p/12449500.html) * [查询操作文档](https://www.elastic.co/guide/cn/elasticsearch/guide/current/_empty_search.html) * [英文文档](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-replication.html#docs-replication) * [golang操作Elasticsearch](https://blog.csdn.net/tflasd1157/article/details/81981915) //或者不用库直接掉方法 * term 只能匹配中文的 ![](/D:/%E6%AD%A3%E5%BC%8F%E6%A1%8C%E9%9D%A2/Golang%E5%B7%A5%E4%BD%9C%E7%AC%94%E8%AE%B0/book/Go%E4%B8%80%E7%99%BE%E4%BE%8B/images/QQ%E6%88%AA%E5%9B%BE20200515155334.png) ~~~ package main import ( "context" "fmt" "github.com/olivere/elastic" "log" "os" ) type Employee struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` Age int `json:"age"` About string `json:"about"` Interests []string `json:"interests"` } func main() { esURL := "http://192.168.28.126:9200" errLog := log.New(os.Stdout, "app ", log.LstdFlags) client, err := elastic.NewClient(elastic.SetErrorLog(errLog), elastic.SetURL(esURL)) if err != nil { fmt.Println(err) } info, code, err := client.Ping(esURL).Do(context.Background()) if err != nil { fmt.Println(err) } fmt.Println(info, code) e1 := Employee{"Jane5", "Smith", 32, "I like to collect rock albums", []string{"music"}} put1, err := client.Index(). Index("megacorp"). Type("employee"). Id("1"). BodyJson(e1). // - [查询操作文档](https://www.elastic.co/guide/cn/elasticsearch/guide/current/_empty_search.html) Source(`{"query":{"match":{"first_name":"zhang1"}}}`). Do(context.Background()) if err != nil { panic(err) } fmt.Printf("Indexed tweet %s to index s%s, type %s\n", put1.Id, put1.Index, put1.Type) reslut, err := client.Search().Index("megacorp").Type("employee").Do(context.Background()) if err != nil { fmt.Println(err.Error()) } for k, v := range reslut.Hits.Hits { fmt.Println(k, string(*v.Source)) } } ~~~