Skip to content

Commit

Permalink
Better to not unmarshal the schema dependent source.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkirb committed Nov 3, 2014
1 parent c57bd86 commit b80e615
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package main
import (
"encoding/json"
"flag"
elastigo "github.com/mattbaird/elastigo/lib"
"log"
"time"

elastigo "github.com/mattbaird/elastigo/lib"
)

var (
Expand Down
20 changes: 10 additions & 10 deletions lib/baseresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
)

type BaseResponse struct {
Ok bool `json:"ok"`
Index string `json:"_index,omitempty"`
Type string `json:"_type,omitempty"`
Id string `json:"_id,omitempty"`
Source interface{} `json:"_source,omitempty"` // depends on the schema you've defined
Version int `json:"_version,omitempty"`
Found bool `json:"found,omitempty"`
Exists bool `json:"exists,omitempty"`
Created bool `json:"created,omitempty"`
Matches []string `json:"matches,omitempty"` // percolate matches
Ok bool `json:"ok"`
Index string `json:"_index,omitempty"`
Type string `json:"_type,omitempty"`
Id string `json:"_id,omitempty"`
Source *json.RawMessage `json:"_source,omitempty"` // depends on the schema you've defined
Version int `json:"_version,omitempty"`
Found bool `json:"found,omitempty"`
Exists bool `json:"exists,omitempty"`
Created bool `json:"created,omitempty"`
Matches []string `json:"matches,omitempty"` // percolate matches
}

// StatusInt is required because /_optimize, at least, returns its status as
Expand Down
11 changes: 7 additions & 4 deletions lib/corebulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/araddon/gou"
"github.com/bmizerany/assert"
"log"
"strconv"
"testing"
"time"

"github.com/araddon/gou"
"github.com/bmizerany/assert"
)

// go test -bench=".*"
Expand Down Expand Up @@ -135,9 +136,11 @@ func XXXTestBulkUpdate(t *testing.T) {

response, err := c.Get("users", "user", "5", nil)
assert.T(t, err == nil, fmt.Sprintf("Should not have any errors %v", err))
newCount := response.Source.(map[string]interface{})["count"]
m := make(map[string]interface{})
json.Unmarshal([]byte(*response.Source), &m)
newCount := m["count"]
assert.T(t, newCount.(float64) == 3,
fmt.Sprintf("Should have update count: %#v ... %#v", response.Source.(map[string]interface{})["count"], response))
fmt.Sprintf("Should have update count: %#v ... %#v", m["count"], response))
}

func TestBulkSmallBatch(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions lib/coreget.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// HEAD - checks for existence of the doc
// http://www.elasticsearch.org/guide/reference/api/get.html
// TODO: make this implement an interface
func (c *Conn) get(index string, _type string, id string, args map[string]interface{}, source interface{}) (BaseResponse, error) {
func (c *Conn) get(index string, _type string, id string, args map[string]interface{}, source *json.RawMessage) (BaseResponse, error) {
var url string
retval := BaseResponse{Source: source}
if len(_type) > 0 {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (c *Conn) Get(index string, _type string, id string, args map[string]interf
}

// Same as Get but with custom source type.
func (c *Conn) GetCustom(index string, _type string, id string, args map[string]interface{}, source interface{}) (BaseResponse, error) {
func (c *Conn) GetCustom(index string, _type string, id string, args map[string]interface{}, source *json.RawMessage) (BaseResponse, error) {
return c.get(index, _type, id, args, source)
}

Expand Down

0 comments on commit b80e615

Please sign in to comment.