From 9f36826bc09d7a30e4bb8ef3d1baa279c3b05ecd Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Wed, 25 Mar 2020 11:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8Eelasticsearch=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8=E7=9A=84=E7=A1=AC?= =?UTF-8?q?=E4=BB=B6=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/elasticEngine.go | 7 ++++--- db/sqlManager.go | 1 - model/hardware.go | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/db/elasticEngine.go b/db/elasticEngine.go index 5828e70..499a41a 100644 --- a/db/elasticEngine.go +++ b/db/elasticEngine.go @@ -4,6 +4,7 @@ import ( "github.com/pkg/errors" "gopkg.in/olivere/elastic.v3" + "qiniupkg.com/x/log.v7" "reflect" ) const( @@ -21,21 +22,21 @@ type ElkEngine struct { func (p *ElkEngine)Create(index string,types string,id string,data interface{}) (error) { if nil != p{ - if (reflect.TypeOf(data).Kind() != reflect.String) && (reflect.TypeOf(data).Kind() != reflect.Struct){ + if (reflect.TypeOf(data).Kind() == reflect.String) || (reflect.TypeOf(data).Kind() == reflect.Struct){ resp, err := p.cli.Index(). Index(index). Type(types). - Id(id). BodyJson(data). Do() if !resp.Created{ return errors.New(CREATED_ERROR) } if err != nil { - print(err) + log.Print(err) return err } }else{ + log.Print(reflect.TypeOf(data).Kind()) return errors.New(INPUT_TYPE_ERROR) } }else{ diff --git a/db/sqlManager.go b/db/sqlManager.go index 7962bd3..8184528 100644 --- a/db/sqlManager.go +++ b/db/sqlManager.go @@ -149,6 +149,5 @@ func InitMongoDb() { } } func GetElastic() *ElkEngine{ - return &gElkEngine } \ No newline at end of file diff --git a/model/hardware.go b/model/hardware.go index b217af9..e3c460b 100644 --- a/model/hardware.go +++ b/model/hardware.go @@ -4,13 +4,12 @@ import ( "background/db" "github.com/pkg/errors" "qiniupkg.com/x/log.v7" - "time" ) // this api is based on elasticsearch type Hardware struct { ID int32 `json:"id"` - BuyDate time.Time `json:"buy_date"` //购入时间 + BuyDate string `json:"buy_date"` //购入时间 Name string `json:"name"` // 名字 Desc string `json:"desc"` // 描述 Pic string `json:"pic"` // 图片 @@ -21,7 +20,7 @@ func (this *Hardware )CreateHardware( ) error{ if nil == this{ return errors.New("null pointer") } - e := db.GetElastic().Create("hardware","0","",*this) + e := db.GetElastic().Create("hardware","0","sdfasdfasd",*this) if nil != e{ log.Print(e.Error()) return e