Bugfix: Run() fails for queries, add MarshalJSON()
The `Run()` method on the `QueryRequest` type would fail, since it would
encode the _inner_ body of the query to JSON and not the complete, outer
body (i.e. including the "body: {}" portion).
The commit also adds `MarshalJSON()` methods to both `QueryRequest` and
`AggregationRequest`, allowing them to implement the `json.Marshaller`
interface, and providing easier debugging of the library. A test
skeleton for this is also added.
This commit is contained in:
+15
-1
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQueries(t *testing.T) {
|
||||
func TestQueryMaps(t *testing.T) {
|
||||
runMapTests(t, []mapTest{
|
||||
{
|
||||
"a simple match_all query",
|
||||
@@ -66,3 +66,17 @@ func TestQueries(t *testing.T) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestQueryJSONs(t *testing.T) {
|
||||
runJSONTests(t, []jsonTest{
|
||||
{
|
||||
"simple query",
|
||||
Query(
|
||||
Bool().
|
||||
Must(Term("account_id", "bla")),
|
||||
),
|
||||
`{"query":{"bool":{"must":[{"term":{"account_id":{"value":"bla"}}}]}}}`,
|
||||
nil,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user