Commit Graph

56 Commits

Author SHA1 Message Date
Ido Perlmuter 8de6de1468 Improve README
Add shields, TOC and more information to the README file.
2020-02-20 11:58:45 +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
Ido Perlmuter 55000abc77 Add Search() function, README and fix some lint errors
This commit changes the internal `search()` function into an exposed
`Search()` function that can be used to execute queries against an
instance of an ElasticSearch client. The per-query-type methods of
`Run()` are removed for now to prevent having to create them for every
type. `Search()` is agnostic.

A README.md file is added with some information, and a few lingering
lint errors are fixed.
2020-02-20 11:50:11 +02:00
Ido Perlmuter 6c8e71c188 Add support for compound queries
This commit adds support for the compound queries "bool", "boosting",
"constant_score" and "dis_max". The "function_score" query is not
supported yet.

Compound queries are simple. They act just like simple queries, except
that they are recursive, wrapping other simple/compound queries.

For example:

    esquery.Bool().
        Must(Term("user", "kimchy"), Term("author", "kimchy")).
        Filter(Term("tag", "tech"))
2020-02-20 11:50:11 +02:00
Ido Perlmuter 9ef149ec94 Initial commit
This commit is the initial commit for a Go library providing an
idiomatic, easy-to-use query builder for ElasticSearch. The library can
build queries and execute them using the structures from the official Go
SDK provided by the ES project (https://github.com/elastic/go-elasticsearch).

The library currently provides the capabilities to create and execute
simple ElasticSearch queries, specifically Match queries (match,
match_bool_prefix, match_phrase and match_phrase_prefix), Match All
queries (match_all, match_none), and all of the Term-level queries (e.g.
range, regexp, etc.).

Unit tests are included for each support query, and the code is linted
using golangci-lint (see enabled linters in .golangci-lint). The unit
tests currently only verify the builder creates valid JSON queries and
does not attempt to actually run queries against a (mock) ES instance.
2020-02-20 11:50:11 +02:00
Oran Moshai b6dbef6245
Create LICENSE 2020-02-20 11:46:34 +02:00