package main
import (
"fmt"
"gopkg.in/olivere/elastic.v2"
)
type Ess struct {
name string
Xq string
}
func main() {client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL("http://127.0.0.1:9200/"))
if err != nil {fmt.Println("connect es error", err)
return
}
fmt.Println("conn es succ")
for i := 0; i < 20; i++ {es := Ess{name: "text", Xq: "phone"}
_, err = client.Index().
Index("es").
Type("es").
Id(fmt.Sprintf("%d", i)).
BodyJson(es).
Do()
if err != nil {panic(err)
return
}
}
fmt.Println("save ok")
}
运行结果
PS D:\goLang\test1> go run main.go
conn es ok
save ok