Commit Graph

50 Commits

Author SHA1 Message Date
Maxim Yanchuk 313fe61951 Merge pull request 'search-collapse' (#6) from search-collapse into master
Reviewed-on: #6
2023-11-01 21:11:51 +00:00
Maxim Yanchuk 40cf057ca5 Merge remote-tracking branch 'origin/master' into search-collapse 2023-11-02 00:11:13 +03:00
Maxim Yanchuk 1dc40acff9 Merge pull request 'Add support for combined_fields query' (#5) from combined-fields-query into master
Reviewed-on: #5
2023-10-30 12:08:39 +00:00
Maxim Yanchuk f1e864f6fe Merge pull request 'boost support added into match statement' (#4) from match-boost into master
Reviewed-on: #4
2023-10-30 12:08:17 +00:00
Maxim Yanchuk 237a7c8fe5 Merge pull request 'date-histogram-agg' (#3) from date-histogram-agg into master
Reviewed-on: #3
2023-10-30 12:07:00 +00:00
Maxim Yanchuk 0ccce02135 Merge pull request 'add support for geo_distance' (#2) from geo-distance into master
Reviewed-on: #2
2023-10-30 12:06:35 +00:00
Maxim Yanchuk 99537b589e Merge pull request 'Update query_multi_match.go' (#1) from query_multi_match into master
Reviewed-on: #1
2023-10-30 12:00:22 +00:00
Bin 37bbc43bba
Update query_multi_match.go
MultiMatchType eq MatchTypeBestFields, field Can be empty
2023-07-12 10:44:59 +08:00
aliheydarabadii a8129fde5a add support for geo_distance 2023-05-12 18:41:47 +03:30
Jacky Wu 2a3074fe89 doc: add date histogram agg in supported agg function list. 2022-01-21 14:15:54 +08:00
Jacky Wu c2693c6401 feat: add date_histogram agg. 2022-01-21 14:09:06 +08:00
PesTospertnyj 5bad0e6d3e boost support added into match statement 2022-01-06 22:54:24 +02:00
k-yomo 11bb2b31eb Add support for combined_fields query 2021-12-21 22:00:39 +09:00
danta 4951f7774d feat: add support for collapse 2021-06-11 10:18:13 +08:00
Hardy 00431fc79f feat: Support Nested for joining queries. 2021-05-27 22:06:02 +08:00
Hardy 49a92fc25e
Features: SearchAfter、Term Aggregation Order、Aggregation Include Filter Values (#14)
* 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>
2021-03-15 09:43:59 +02:00
Oran Moshai 0064054bc7
Update go.mod 2021-03-15 09:20:44 +02:00
Hardy ca0cfb3224
Update aggregations_test.go
Fix conflict.
2021-03-15 10:42:44 +08:00
Hardy c2b5f62823
Merge branch 'master' into master 2021-03-15 10:32:29 +08:00
Caleb Champlin fc16427405
Features: Filter Aggregations, Nested Aggregations, Multi Match Queries, Highlights (#12)
* Add support for multi_match queries

* Add support for highlights

* Add support for nested aggregations and filtered aggregations

* Update README

* Fix formatting
2021-03-14 09:50:22 +02:00
Hardy 12616dd9d3 Feat: Support include filter for termAggs 2021-03-12 20:54:48 +08:00
Hardy cc685d325e feat:Support for term aggs order 2021-03-12 19:37:19 +08:00
Hardy e3c77e0849 fix:add .gitignore 2021-03-02 17:09:29 +08:00
Hardy bdfe2df171 fix:set search after []string to []interface 2021-03-02 13:30:39 +08:00
Hardy 09acfd6a3d feat: add support for search after 2021-03-02 11:51:41 +08:00
Hardy 8661572bd5 fix 2021-03-01 16:21:23 +08:00
Caleb Champlin 37dac903cc Fix formatting 2020-10-17 13:46:37 -06:00
Caleb Champlin 52ccf20965 Update README 2020-10-17 13:43:02 -06:00
Caleb Champlin 39f0dd59c1 Add support for nested aggregations and filtered aggregations 2020-10-17 13:42:50 -06:00
Caleb Champlin f7d496389e Add support for highlights 2020-10-17 13:42:23 -06:00
Caleb Champlin cf3d8d5827 Add support for multi_match queries 2020-10-17 13:41:45 -06:00
Ido Perlmuter 259a3cd818
Add support for the "Delete by Query" API (#11)
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),
        )
2020-05-27 14:35:40 +03:00
Ido Perlmuter b3b6dff2be
Support _source, sort and post_filter in search requests (#10)
* 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.
2020-05-21 15:44:53 +03:00
Ido Perlmuter 7fa767fc28
Add support for Count requests (#8)
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)
2020-04-06 12:24:44 +03:00
Ido Perlmuter 8e5dea816b
Add Search() function, two new aggregations (#7)
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.
2020-04-06 12:03:42 +03:00
Ido Perlmuter d07b4e2126
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:56 +02:00
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
Oran Moshai 7d175c8f0d
Rename travis.yml to .travis.yml 2020-02-23 13:01:54 +02:00
Oran Moshai 395914da98
Add travis-ci (#4) 2020-02-23 12:48:13 +02:00
Oran Moshai 0f20f2f5e3
Merge pull request #3 from oranmoshai/master
Add trvis-ci
2020-02-23 12:33:28 +02:00
oranmoshai 36e63bac30 Add trvis-ci 2020-02-23 12:29:45 +02:00
Oran Moshai 42eaef3f2c
Merge pull request #2 from ido50/master
Bugfix: Run() fails for queries, add MarshalJSON()
2020-02-20 16:54:57 +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
Oran Moshai abbec7e12d
Merge pull request #1 from ido50/master
Merge initial version of the project
2020-02-20 12:01:36 +02:00
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