修复elasticsearch根据id删除文档,改用querydelete的形式,测试ok
parent
69f4f91445
commit
3909f2052c
|
@ -43,6 +43,7 @@ func DeleteHardWare(c *gin.Context) {
|
|||
e := model.DeleteHardware(name)
|
||||
if nil != e{
|
||||
logs.Error(e.Error())
|
||||
return
|
||||
}
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
|
|
|
@ -43,18 +43,15 @@ func (p *ElkEngine)Create(index string,types string,id string,data interface{})
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *ElkEngine)Delete(index string,types string,id string) error{
|
||||
func (p *ElkEngine)Delete(query elastic.Query,index string) error{
|
||||
if nil != p{
|
||||
res, err := p.cli.Delete().Index(index).
|
||||
Id(id).
|
||||
_, err := p.cli.DeleteByQuery().Index(index).Query(query).
|
||||
Do(context.Background())
|
||||
if err != nil {
|
||||
print(err)
|
||||
log.Print(err)
|
||||
return err
|
||||
}
|
||||
if !res.ForcedRefresh{
|
||||
return errors.New(DELETE_ERROR)
|
||||
}
|
||||
|
||||
}else{
|
||||
return errors.New(ERROR_PTR)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func (this *Hardware )CreateHardware( ) error{
|
|||
return errors.New(ERR_COLUMN_EXISTED)
|
||||
}
|
||||
}
|
||||
e = db.GetElastic().Create("hardware","0","",*this)
|
||||
e = db.GetElastic().Create("hardware_data","0","",*this)
|
||||
if nil != e{
|
||||
log.Print("shit1")
|
||||
log.Print(e.Error())
|
||||
|
@ -62,7 +62,7 @@ func (this *Hardware )CreateHardware( ) error{
|
|||
|
||||
func GetHardwares(limit int,size int) ([]Hardware,error){
|
||||
var ret []Hardware
|
||||
data,ids,e := db.GetElastic().Query("hardware",nil,Hardware{},limit,size)
|
||||
data,ids,e := db.GetElastic().Query("hardware_data",nil,Hardware{},limit,size)
|
||||
if nil != e{
|
||||
return nil,e
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func GetHardwares(limit int,size int) ([]Hardware,error){
|
|||
|
||||
func QueryHardwares(query elastic.Query,limit int,offset int) ([]Hardware,error){
|
||||
var ret []Hardware
|
||||
data,ids,e := db.GetElastic().Query("hardware",query,Hardware{},limit,offset)
|
||||
data,ids,e := db.GetElastic().Query("hardware_data",query,Hardware{},limit,offset)
|
||||
log.Print(data)
|
||||
if nil != e{
|
||||
return nil,e
|
||||
|
@ -92,17 +92,10 @@ func QueryHardwares(query elastic.Query,limit int,offset int) ([]Hardware,error)
|
|||
}
|
||||
|
||||
func DeleteHardware(name string) error{
|
||||
matchPhraseQuery := elastic.NewMatchQuery("name", "stm32开发板")
|
||||
existedHardware,e := QueryHardwares(matchPhraseQuery,10,0)
|
||||
log.Print(e,existedHardware)
|
||||
|
||||
for _,v := range existedHardware{
|
||||
if v.Name == name{
|
||||
err := db.GetElastic().Delete("hardware","",v.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
query := elastic.NewTermQuery("name",name)
|
||||
err := db.GetElastic().Delete(query,"hardware_data")
|
||||
if err != nil{
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue