func (i *uploadController) ReadMany(c context.Context) error { var results []types.Upload qry := elastigo.Search(iname).Pretty().Query( elastigo.Query().All(), ) out, err := qry.Result(types.ElasticConnection) if err != nil { fmt.Println("err querying elastic connection:%v", err) return goweb.API.RespondWithError(c, http.StatusInternalServerError, err.Error()) } for _, elem := range out.Hits.Hits { bytes, err := elem.Source.MarshalJSON() if err != nil { log.Println("err calling marshalJson:%v", err) return goweb.API.RespondWithError(c, http.StatusInternalServerError, err.Error()) } var t types.Upload json.Unmarshal(bytes, &t) results = append(results, t) } return goweb.API.RespondWithData(c, results) }
func (c *Configuration) fetchLastIndexFromES() int64 { var results []Upload qry := elastigo.Search(iname).Pretty().Query( elastigo.Query().All(), ) out, err := qry.Result(ElasticConnection) if err != nil { log.Println("No record found") return 0 } if out.Hits.Total == 0 { log.Println("No indice data for updating fetch information") return 0 } for _, elem := range out.Hits.Hits { bytes, err := elem.Source.MarshalJSON() if err != nil { log.Fatalf("err calling marshalJson:%v", err) } var t Upload json.Unmarshal(bytes, &t) results = append(results, t) } var highestId int64 = 0 for _, p := range results { if p.Id >= highestId { highestId = p.Id } } return highestId }