package main
import (
"context"
"fmt"
"github.com/olivere/elastic"
)
func main(){
Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))
fmt.Println(Client, err)
name := "people2"
Client.CreateIndex(name).Do(context.Background())
}
func main(){
Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))
fmt.Println(Client, err)
name := "people2"
data := `{
"name": "wali",
"country": "Chian",
"age": 30,
"date": "1987-03-07"
}`
_, err = Client.Index().Index(name).Type("man1").Id("1").BodyJson(data).Do(context.Background())
}
通过id查找
func main(){
Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))
fmt.Println(Client, err)
name := "people2"
get, err := Client.Get().Index(name).Type("man1").Id("1").Do(context.Background())
fmt.Println(get, err)
}
func main() {
Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))
res, err := client.Update().
Index("megacorp").
Type("employee").
Id("2").
Doc(map[string]interface{}{"age": 88}).
Do(context.Background())
if err != nil {
println(err.Error())
}
fmt.Printf("update age %s\n", res.Result)
}
func main(){
Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))
//使用结构体
e1 := Employee{"Jane", "Smith", 32, "I like to collect rock albums", []string{"music"}}
//创建
put1, err := client.Index().
Index("megacorp").
Type("employee").
Id("1").
BodyJson(e1).
Do(context.Background())
if err != nil {
panic(err)
}
//删除
get, err := Client.Get().Index("megacorp").Type("employee").Id("1").Do(context.Background())
fmt.Println(get, err)
}
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8