Commit Graph

3 Commits

Author SHA1 Message Date
Ido Perlmuter 73b274a13b
Add documentation, fix small bugs, improve CustomQuery (#6)
This commit performs the following modifications:

- The library is properly documented in Godoc format.

- The CustomQuery function is made to be a bit more versatile by
  allowing it to also be used standalone (i.e. instead of passing a
  `CustomQuery` as a parameter to the `Query` function, they now have
  their own `Run` method).

- Queries and aggregations can now also be executed using the
  `RunSearch` method. This method is the same as the `Run` method,
  except that instead of an `*elasticSearch.Client` value, it accepts an
  `esapi.Search` value. This is provided for consuming code that needs
  to implement mock clients of ElasticSearch (e.g. for test purposes).
  The ElasticSearch client does not provide an interface type describing
  its API, so its Search function (which is actually a field of a
  function type) can be used instead.

- Bugfix: the CustomAgg function was unusable as it did not accept a
  name parameter and thus did not implement the Aggregation interface.

- Bugfix: the enumeration types are rewritten according to Go standards,
  and the `RangeRelation` type's default value is now empty.

- The golint and godox linters are added.
2020-02-27 16:19:07 +02:00
Ido Perlmuter 48ad6f919c 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.
2020-02-20 16:46:27 +02:00
Ido Perlmuter 1dd88421a2 Refactor API, add aggregations and custom queries
This commit introduces a refactor of the codebase and the API, to make
it more user friendly. Queries can now directly be executed via the
`Run()` method. Internally, the library no longer uses JSON generation
as a major mechanism, instead all types need to implement a `Mappable`
interface which simply turns each type in a `map[string]interface{}`,
which is what the ElasticSearch client expects. This makes the code
easier to write, and makes writing tests less error prone, as JSON need
not be written directly.

Support for metrics aggregations is also added. However, aggregations of
type bucket, pipeline and matrix are not supported yet.

To make the library more useful in its current state, support is added
for running custom queries and aggregations, via the `CustomQuery()` and
`CustomAgg()` functions, which both accepts an arbitrary
`map[string]interface{}`.
2020-02-20 11:50:11 +02:00