func (ie *ItemElastic) MultiGet(indexType string, itemIds []string) ([]*model.Item, error) { endpoint, err := ie.funcEndpoint(ie.index, indexType, "_mget") result := make([]*model.Item, len(itemIds)) if err != nil { return nil, err } mget := map[string][]string{ "ids": itemIds, } response := struct { Docs []ElasticModel `json:"docs"` }{} err = ie.handler.SendRAW("GET", endpoint, &mget, &response) if err != nil { return nil, err } eitem := response.Docs for i, _ := range eitem { if eitem[i].Found { var item model.Item err = NewModelFromRaw(eitem[i].Source, &item) item.Id = eitem[i].Id item.Version = eitem[i].Version result[i] = &item } } return result, nil }
func (ie *ItemElastic) Get(indexType string, itemId string) (*model.Item, error) { var item model.Item endpoint, err := ie.funcEndpoint(ie.index, indexType, itemId) if err != nil { return nil, err } es, err := ie.handler.Get(endpoint) if err != nil { return nil, err } err = NewModelFromRaw(es.Source, &item) if err != nil { return nil, err } // populate Id and Version from ElasticSearch item.Id = es.Id item.Version = es.Version return &item, nil }