Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "json: error calling MarshalJSON for type json.RawMessage" #61

Merged
merged 1 commit into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed "json: error calling MarshalJSON for type json.RawMessage"
  • Loading branch information
Duke committed Feb 28, 2014
commit 48595f26603636cec754c1c805a0935a61686ede
12 changes: 6 additions & 6 deletions core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func (h *Hits) Len() int {
}

type Hit struct {
Index string `json:"_index"`
Type string `json:"_type,omitempty"`
Id string `json:"_id"`
Score Float32Nullable `json:"_score,omitempty"` // Filters (no query) dont have score, so is null
Source json.RawMessage `json:"_source"` // marshalling left to consumer
Fields json.RawMessage `json:"fields"` // when a field arg is passed to ES, instead of _source it returns fields
Index string `json:"_index"`
Type string `json:"_type,omitempty"`
Id string `json:"_id"`
Score Float32Nullable `json:"_score,omitempty"` // Filters (no query) dont have score, so is null
Source *json.RawMessage `json:"_source"` // marshalling left to consumer
Fields *json.RawMessage `json:"fields"` // when a field arg is passed to ES, instead of _source it returns fields
}

// Elasticsearch returns some invalid (according to go) json, with floats having...
Expand Down
20 changes: 20 additions & 0 deletions core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package core

import (
"encoding/json"
"fmt"
"github.com/bmizerany/assert"
"testing"
Expand All @@ -29,3 +30,22 @@ func TestSearchRequest(t *testing.T) {
assert.T(t, out.Hits.Len() == 10, fmt.Sprintf("Should have 10 docs but was %v", out.Hits.Len()))
assert.T(t, CloseInt(out.Hits.Total, 588), fmt.Sprintf("Should have 588 hits but was %v", out.Hits.Total))
}

func TestSearchResultToJSON(t *testing.T) {
qry := map[string]interface{}{
"query": map[string]interface{}{
"wildcard": map[string]string{"actor": "a*"},
},
}
out, err := SearchRequest(true, "github", "", qry, "", 0)

if err != nil {
t.Error(err)
}

_, err = json.Marshal(out.Hits.Hits)

if err != nil {
t.Error(err)
}
}