elastic.go 751 B

123456789101112131415161718192021222324252627
  1. package utils
  2. import (
  3. "github.com/olivere/elastic/v7"
  4. "time"
  5. )
  6. var Client *elastic.Client
  7. const (
  8. ES_URL = "http://es-cn-nif227b580019rgw6.public.elasticsearch.aliyuncs.com:9200" //<1>
  9. ES_USERNAME = "elastic" //<2>
  10. ES_PASSWORD = "hongze@2021" //<3>
  11. )
  12. func init() {
  13. client, err := elastic.NewClient(
  14. elastic.SetURL(ES_URL),
  15. elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
  16. elastic.SetSniff(false))
  17. Client = client
  18. if err != nil {
  19. go SendAlarmMsg("ElasticSearch连接失败", 2)
  20. go SendEmail("ElasticSearch连接失败"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), EmailSendToUsers)
  21. }
  22. return
  23. }