lazy initializing es client

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2020-07-02 19:54:16 +08:00
parent 78159e9636
commit 4df7ae2636
5 changed files with 114 additions and 70 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/elastic/go-elasticsearch/v5"
"github.com/elastic/go-elasticsearch/v5/esapi"
"io/ioutil"
"k8s.io/klog"
"time"
)
@@ -17,16 +16,12 @@ type Elastic struct {
index string
}
func New(address string, index string) *Elastic {
func New(address string, index string) (*Elastic, error) {
client, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
})
if err != nil {
klog.Error(err)
return nil
}
return &Elastic{client: client, index: index}
return &Elastic{client: client, index: index}, err
}
func (e *Elastic) Search(body []byte, scroll bool) ([]byte, error) {