add es package

This commit is contained in:
Jay
2018-10-05 16:36:16 +08:00
parent 83e786967d
commit ac8284b7e3
264 changed files with 48779 additions and 1 deletions
+4
View File
@@ -43,6 +43,10 @@ type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"redis"`
Elasticsearch struct{
Host string `yaml:"host"`
Index string `yaml:"index"`
} `yaml:"elasticsearch"`
}
var conf *Config
+30
View File
@@ -0,0 +1,30 @@
package es
import (
"context"
"fmt"
"git.trj.tw/golang/mtfosbot/module/config"
"github.com/olivere/elastic"
)
var client *elastic.Client
func NewClient () (err error) {
conf := config.GetConf()
client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(conf.Elasticsearch.Host))
fmt.Println("host ", conf.Elasticsearch.Host)
if err != nil {
fmt.Println(err)
return
}
return
}
func PutLog () (err error) {
conf := config.GetConf()
ctx := context.Background()
_, err = client.Index().Index(conf.Elasticsearch.Index).Type("type").BodyJson(map[string]interface{}{
"key1": "value1",
}).Do(ctx)
return
}