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
+4
View File
@@ -40,6 +40,10 @@ func (req *AggregationRequest) Map() map[string]interface{} {
}
}
func (req *AggregationRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(req.Map())
}
func (req *AggregationRequest) Run(
api *elasticsearch.Client,
o ...func(*esapi.SearchRequest),