From 69f4f91445311ca46ce00ca3e362891508f1fe0b Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Fri, 24 Apr 2020 22:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84elasticsearch=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=B8=AD=E6=96=87=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E5=8C=B9=E9=85=8D=E8=BD=AF=E4=BB=B6=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/elasticEngine.go | 19 ++++++++++++++++++- main.go | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/db/elasticEngine.go b/db/elasticEngine.go index a11e5d9..57b08bd 100644 --- a/db/elasticEngine.go +++ b/db/elasticEngine.go @@ -117,7 +117,7 @@ func (p *ElkEngine)Update(index string,types string,id string,data map[string]in } func (p *ElkEngine)CreateIndex(index string,typemaping string) error{ if nil != p { - exists, err := p.cli.IndexExists("elastic_index").Do(context.Background()) + exists, err := p.cli.IndexExists(index).Do(context.Background()) if err != nil { // Handle error log.Print(err) @@ -137,4 +137,21 @@ func (p *ElkEngine)CreateIndex(index string,typemaping string) error{ } } return errors.New(ERROR_PTR) +} + +func (p *ElkEngine)IndexExisted(index string) (bool,error ){ + if nil != p { + exists, err := p.cli.IndexExists(index).Do(context.Background()) + if exists{ + return true,nil + } + if err != nil { + // Handle error + log.Print(err) + return false,err + } + return false,nil + + } + return false,nil } \ No newline at end of file diff --git a/main.go b/main.go index 258d6e8..0e76d9f 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func InitRedis() { func InitElasticSearch(){ e := db.GetElastic().CreateIndex("hardware",model.HardwareTypeMapping()) if nil != e{ - log.Print(e.Error()) + } } func InitLogs() {