|
@@ -55,7 +55,7 @@ func (e *Elastic) GetEsConn() *es.Client {
|
|
|
case c := <-e.Pool:
|
|
|
if c == nil || !c.IsRunning() {
|
|
|
log.Println("new esclient.", len(e.Pool))
|
|
|
- client, err := es.NewClient(es.SetURL(e.Addrs...),
|
|
|
+ client, err := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password),
|
|
|
es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
if err == nil && client.IsRunning() {
|
|
|
return client
|
|
@@ -72,10 +72,10 @@ func (e *Elastic) GetEsConn() *es.Client {
|
|
|
if c > 12 {
|
|
|
e.lastTime = time.Now().Unix()
|
|
|
log.Println("add client..", len(e.Pool))
|
|
|
- c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
+ c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
go func() {
|
|
|
for i := 0; i < 2; i++ {
|
|
|
- client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
+ client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
e.Pool <- client
|
|
|
}
|
|
|
}()
|