2024-11-12 12:41:57 +08:00

32 lines
744 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"},
Addresses: []string{"http://localhost:9200"}, // TIP 用 localhost 可以127.0.0.1 无效...
// 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"`
}