elastic.go 888 B

123456789101112131415161718192021222324252627282930313233
  1. package elastic
  2. import (
  3. "github.com/olivere/elastic/v7"
  4. "hongze/hongze_yb_en_api/global"
  5. )
  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. //Grafana pwd-> 20521bb9
  11. //Grafana username-> emon
  12. )
  13. // es相关
  14. var (
  15. EsEnglishReportIndexName string
  16. )
  17. func init() {
  18. if global.CONFIG.Serve.RunMode == "debug" {
  19. EsEnglishReportIndexName = "test_english_report_v1" //报告
  20. }else{
  21. EsEnglishReportIndexName = "english_report_v1" //报告
  22. }
  23. }
  24. func NewClient() (client *elastic.Client, err error) {
  25. client, err = elastic.NewClient(
  26. elastic.SetURL(ES_URL),
  27. elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
  28. elastic.SetSniff(false))
  29. return
  30. }