elastic.go 349 B

12345678910111213141516171819
  1. package utils
  2. import (
  3. "github.com/olivere/elastic/v7"
  4. )
  5. var EsClient *elastic.Client
  6. func initEs() {
  7. client, err := elastic.NewClient(
  8. elastic.SetURL(ES_URL),
  9. elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
  10. elastic.SetSniff(false))
  11. EsClient = client
  12. if err != nil {
  13. panic("ElasticSearch连接失败,err:" + err.Error())
  14. }
  15. return
  16. }