32 lines
744 B
Go
Raw Permalink Normal View History

2024-10-23 19:33:15 +08:00
package test
import (
"github.com/elastic/go-elasticsearch/v8"
)
var (
ElasticClient *elasticsearch.Client
StudentIndex string = "student_index"
)
func InitElastic() {
var err error
ElasticClient, err = elasticsearch.NewClient(elasticsearch.Config{
// Addresses: []string{"http://113.44.68.213:9200"},
2024-11-12 12:41:57 +08:00
Addresses: []string{"http://localhost:9200"}, // TIP 用 localhost 可以127.0.0.1 无效...
2024-10-23 19:33:15 +08:00
// Username: "elastic",
// Password: "U8n61yn*Sp4Kvbuqo_K8",
})
if err != nil {
panic(err)
}
}
type Student struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Age int `json:"age,omitempty"`
Address string `json:"address,omitempty"`
School string `json:"school,omitempty"`
}