elastic.go 435 B

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