Exemple #1
0
func (ec *elasticConnection) Delete(key datastore.Key) error {
	//func Delete(pretty bool, index string, _type string, id string, version int, routing string) (api.BaseResponse, error) {
	resp, err := core.Delete(false, ec.index, key.Kind(), key.ID(), 0, "")
	indices.Refresh(ec.index)
	glog.V(4).Infof("Delete response: %v", resp)
	if err != nil {
		return err
	}
	return nil
}
Exemple #2
0
func (ec *elasticConnection) Put(key datastore.Key, msg datastore.JSONMessage) error {
	//func Index(pretty bool, index string, _type string, id string, data interface{}) (api.BaseResponse, error) {

	glog.V(4).Infof("Put for {kind:%s, id:%s} %v", key.Kind(), key.ID(), string(msg.Bytes()))
	var raw json.RawMessage
	raw = msg.Bytes()
	resp, err := core.IndexWithParameters(false, ec.index, key.Kind(), key.ID(), "", msg.Version(), "", "", "", 0, "", "", false, &raw)
	if err != nil {
		glog.Errorf("Put err: %+v", err)
		if eserr, iseserror := err.(api.ESError); iseserror && eserr.Code == 409 {
			// Conflict
			return fmt.Errorf("Your changes conflict with those made by another user. Please reload and try your changes again.")
		}
		return err
	}
	indices.Refresh(ec.index)
	glog.V(4).Infof("Put response: %v", resp)
	if !resp.Ok {
		return fmt.Errorf("non OK response: %v", resp)
	}
	return nil
}