elastic.go 680 B

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