|
@@ -1,4 +1,4 @@
|
|
|
-package elasticsearch
|
|
|
+package elastic
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
@@ -8,7 +8,6 @@ import (
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
- "util"
|
|
|
|
|
|
es "gopkg.in/olivere/elastic.v1"
|
|
|
)
|
|
@@ -24,7 +23,7 @@ type Elastic struct {
|
|
|
}
|
|
|
|
|
|
func (e *Elastic) InitElasticSize() {
|
|
|
- defer util.Catch()
|
|
|
+ defer Catch()
|
|
|
e.Pool = make(chan *es.Client, e.I_size)
|
|
|
for _, s := range strings.Split(e.S_esurl, ",") {
|
|
|
e.Addrs = append(e.Addrs, s)
|
|
@@ -127,7 +126,7 @@ func (e *Elastic) Get(index, itype, query string) *[]map[string]interface{} {
|
|
|
|
|
|
//关闭elastic
|
|
|
func (e *Elastic) Close() {
|
|
|
- defer util.Catch()
|
|
|
+ defer Catch()
|
|
|
for i := 0; i < e.I_size; i++ {
|
|
|
cli := <-e.Pool
|
|
|
cli.Stop()
|
|
@@ -139,7 +138,7 @@ func (e *Elastic) Close() {
|
|
|
|
|
|
//获取连接
|
|
|
//func (e *Elastic) GetEsConn() (c *es.Client) {
|
|
|
-// defer util.Catch()
|
|
|
+// defer Catch()
|
|
|
// select {
|
|
|
// case c = <-e.Pool:
|
|
|
// if c == nil || !c.IsRunning() {
|
|
@@ -160,7 +159,7 @@ func (e *Elastic) Close() {
|
|
|
//}
|
|
|
|
|
|
func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
|
|
|
- defer util.Catch()
|
|
|
+ defer Catch()
|
|
|
client := e.GetEsConn()
|
|
|
defer e.DestoryEsConn(client)
|
|
|
if client != nil {
|
|
@@ -180,14 +179,14 @@ func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, i
|
|
|
|
|
|
//先删除后增
|
|
|
func (e *Elastic) UpdateNewDoc(index, itype string, obj ...interface{}) bool {
|
|
|
- defer util.Catch()
|
|
|
+ defer Catch()
|
|
|
client := e.GetEsConn()
|
|
|
defer e.DestoryEsConn(client)
|
|
|
b := false
|
|
|
if client != nil {
|
|
|
var err error
|
|
|
for _, v := range obj {
|
|
|
- tempObj := util.ObjToMap(v)
|
|
|
+ tempObj := ObjToMap(v)
|
|
|
id := fmt.Sprintf("%v", (*tempObj)["_id"])
|
|
|
client.Delete().Index(index).Type(itype).Id(id).Do()
|
|
|
_, err = client.Index().Index(index).Type(itype).BodyJson(tempObj).Do()
|
|
@@ -204,7 +203,7 @@ func (e *Elastic) UpdateNewDoc(index, itype string, obj ...interface{}) bool {
|
|
|
|
|
|
//根据id删除索引对象
|
|
|
func (e *Elastic) DelById(index, itype, id string) bool {
|
|
|
- defer util.Catch()
|
|
|
+ defer Catch()
|
|
|
client := e.GetEsConn()
|
|
|
defer e.DestoryEsConn(client)
|
|
|
b := false
|