1234567891011121314151617181920212223242526 |
- package utils
- import (
- "github.com/olivere/elastic/v7"
- )
- var EsClient *elastic.Client
- const (
- ES_URL = "http://es-cn-nif227b580019rgw6.public.elasticsearch.aliyuncs.com:9200" //<1>
- ES_USERNAME = "elastic" //<2>
- ES_PASSWORD = "hongze@2021" //<3>
- )
- func init() {
- client, err := elastic.NewClient(
- elastic.SetURL(ES_URL),
- elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
- elastic.SetSniff(false))
- EsClient = client
- if err != nil {
- panic("ElasticSearch连接失败")
- //go alarm_msg.SendAlarmMsg("ElasticSearch连接失败", 2)
- }
- return
- }
|