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:
Ido Perlmuter
2020-02-20 16:46:27 +02:00
parent 8de6de1468
commit 48ad6f919c
6 changed files with 49 additions and 2 deletions
+15 -1
View File
@@ -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,
},
})
}