* Add support for multi_match queries
* Add support for highlights
* Add support for nested aggregations and filtered aggregations
* Update README
* Fix formatting
* fix
* feat: add support for search after
* fix:set search after []string to []interface
* fix:add .gitignore
* feat:Support for term aggs order
* Feat: Support include filter for termAggs
* Update aggregations_test.go
Fix conflict.
* Update go.mod
Co-authored-by: Caleb Champlin <caleb.champlin@gmail.com>
Co-authored-by: Hardy <caoxiaozhen@secnium.com>
Co-authored-by: Oran Moshai <12291998+oranmoshai@users.noreply.github.com>
* Add support for multi_match queries
* Add support for highlights
* Add support for nested aggregations and filtered aggregations
* Update README
* Fix formatting
This commit adds support for ElasticSearch's Delete by Query API. Usage
is very similar to that of Search and Count requests:
esquery.Delete().
Index("index_1, "index_2").
Query(esquery.Bool()...).
Run(
es,
esapi.WithAnalyzeWildcard(true),
)
* Add support for post filter in Search
Search requests can now accept a post filter applied after all hits were
returned from the database. For example:
esquery.Search().
Query(...).
Aggs(...).
PostFilter(esquery.Range(field).Gt(0)).
Run(...)
* Add support for _source and sort in search requests
This commit adds the ability to use the "sort" and "_source" attributes
in search requests, via the new methods Sort, SourceIncludes and
SourceExcludes.
This commit adds initial support for Count requests, which are simple
search requests asking to get the number of matches for a query.
The functionality is provided by the Count() function, which accepts a
query object (implementing the Mappable interface), and can be executed
just like a search request.
res, err := esquery.
Count(esquery.Match("user", "someone")).
Run(es)
This commit implements a Search() function, which allow for running
search requests with both a query and aggregations. This function is
meant to more accurately implement the structure of search requests
accepted by ElasticSearch's Search API.
The Query() and Aggregate() functions are still included by the library,
but now simply call Search() internally, making them simple shortcuts.
Two new aggregations are also added: "terms" and "top_hits". These are
implemented a bit differently than previously implemented ones. The
structs and methods for ElasticSearch queries and aggregations will
eventually be auto-generated from a specification file, and will look
more like the new implementations of these new aggregations.
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.
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.
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 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{}`.
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.
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"))
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.