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-18 12:00:15 +00:00
|
|
|
package esquery
|
|
|
|
|
|
|
|
import (
|
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-19 11:35:21 +00:00
|
|
|
"github.com/fatih/structs"
|
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-18 12:00:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type matchType uint8
|
|
|
|
|
|
|
|
const (
|
2020-02-27 14:19:07 +00:00
|
|
|
// TypeMatch denotes a query of type "match"
|
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-18 12:00:15 +00:00
|
|
|
TypeMatch matchType = iota
|
2020-02-27 14:19:07 +00:00
|
|
|
|
2023-11-01 21:30:33 +00:00
|
|
|
// TypeMatchBoolPrefix denotes a query of type "match_bool_prefix"
|
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-18 12:00:15 +00:00
|
|
|
TypeMatchBoolPrefix
|
2020-02-27 14:19:07 +00:00
|
|
|
|
|
|
|
// TypeMatchPhrase denotes a query of type "match_phrase"
|
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-18 12:00:15 +00:00
|
|
|
TypeMatchPhrase
|
2020-02-27 14:19:07 +00:00
|
|
|
|
|
|
|
// TypeMatchPhrasePrefix denotes a query of type "match_phrase_prefix"
|
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-18 12:00:15 +00:00
|
|
|
TypeMatchPhrasePrefix
|
|
|
|
)
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MatchQuery represents a query of type "match", "match_bool_prefix",
|
|
|
|
// "match_phrase" and "match_phrase_prefix". While all four share the same
|
|
|
|
// general structure, they don't necessarily support all the same options. The
|
|
|
|
// library does not attempt to verify provided options are supported.
|
|
|
|
// See the ElasticSearch documentation for more information:
|
|
|
|
// - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
|
|
|
|
// - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-bool-prefix-query.html
|
|
|
|
// - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html
|
|
|
|
// - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html
|
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-18 12:00:15 +00:00
|
|
|
type MatchQuery struct {
|
|
|
|
field string
|
|
|
|
mType matchType
|
|
|
|
params matchParams
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Map returns a map representation of the query, thus implementing the
|
|
|
|
// Mappable interface.
|
|
|
|
func (q *MatchQuery) Map() map[string]interface{} {
|
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-18 12:00:15 +00:00
|
|
|
var mType string
|
2020-02-27 14:19:07 +00:00
|
|
|
switch q.mType {
|
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-18 12:00:15 +00:00
|
|
|
case TypeMatch:
|
|
|
|
mType = "match"
|
|
|
|
case TypeMatchBoolPrefix:
|
|
|
|
mType = "match_bool_prefix"
|
|
|
|
case TypeMatchPhrase:
|
|
|
|
mType = "match_phrase"
|
|
|
|
case TypeMatchPhrasePrefix:
|
|
|
|
mType = "match_phrase_prefix"
|
|
|
|
}
|
|
|
|
|
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-19 11:35:21 +00:00
|
|
|
return map[string]interface{}{
|
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-18 12:00:15 +00:00
|
|
|
mType: map[string]interface{}{
|
2020-02-27 14:19:07 +00:00
|
|
|
q.field: structs.Map(q.params),
|
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-18 12:00:15 +00:00
|
|
|
},
|
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-19 11:35:21 +00:00
|
|
|
}
|
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-18 12:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type matchParams struct {
|
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-19 11:35:21 +00:00
|
|
|
Qry interface{} `structs:"query"`
|
|
|
|
Anl string `structs:"analyzer,omitempty"`
|
|
|
|
AutoGenerate *bool `structs:"auto_generate_synonyms_phrase_query,omitempty"`
|
|
|
|
Fuzz string `structs:"fuzziness,omitempty"`
|
|
|
|
MaxExp uint16 `structs:"max_expansions,omitempty"`
|
|
|
|
PrefLen uint16 `structs:"prefix_length,omitempty"`
|
|
|
|
Trans *bool `structs:"transpositions,omitempty"`
|
|
|
|
FuzzyRw string `structs:"fuzzy_rewrite,omitempty"`
|
|
|
|
Lent bool `structs:"lenient,omitempty"`
|
|
|
|
Op MatchOperator `structs:"operator,string,omitempty"`
|
|
|
|
MinMatch string `structs:"minimum_should_match,omitempty"`
|
|
|
|
ZeroTerms ZeroTerms `structs:"zero_terms_query,string,omitempty"`
|
|
|
|
Slp uint16 `structs:"slop,omitempty"` // only relevant for match_phrase query
|
2022-01-06 20:54:24 +00:00
|
|
|
Boost float32 `structs:"boost,omitempty"`
|
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-18 12:00:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Match creates a new query of type "match" with the provided field name.
|
|
|
|
// A comparison value can optionally be provided to quickly create a simple
|
|
|
|
// query such as { "match": { "message": "this is a test" } }
|
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-18 12:00:15 +00:00
|
|
|
func Match(fieldName string, simpleQuery ...interface{}) *MatchQuery {
|
|
|
|
return newMatch(TypeMatch, fieldName, simpleQuery...)
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MatchBoolPrefix creates a new query of type "match_bool_prefix" with the
|
|
|
|
// provided field name. A comparison value can optionally be provided to quickly
|
|
|
|
// create a simple query such as { "match": { "message": "this is a test" } }
|
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-18 12:00:15 +00:00
|
|
|
func MatchBoolPrefix(fieldName string, simpleQuery ...interface{}) *MatchQuery {
|
|
|
|
return newMatch(TypeMatchBoolPrefix, fieldName, simpleQuery...)
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MatchPhrase creates a new query of type "match_phrase" with the
|
|
|
|
// provided field name. A comparison value can optionally be provided to quickly
|
|
|
|
// create a simple query such as { "match": { "message": "this is a test" } }
|
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-18 12:00:15 +00:00
|
|
|
func MatchPhrase(fieldName string, simpleQuery ...interface{}) *MatchQuery {
|
|
|
|
return newMatch(TypeMatchPhrase, fieldName, simpleQuery...)
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MatchPhrasePrefix creates a new query of type "match_phrase_prefix" with the
|
|
|
|
// provided field name. A comparison value can optionally be provided to quickly
|
|
|
|
// create a simple query such as { "match": { "message": "this is a test" } }
|
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-18 12:00:15 +00:00
|
|
|
func MatchPhrasePrefix(fieldName string, simpleQuery ...interface{}) *MatchQuery {
|
|
|
|
return newMatch(TypeMatchPhrasePrefix, fieldName, simpleQuery...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMatch(mType matchType, fieldName string, simpleQuery ...interface{}) *MatchQuery {
|
|
|
|
var qry interface{}
|
2020-02-18 16:43:19 +00:00
|
|
|
if len(simpleQuery) > 0 {
|
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-18 12:00:15 +00:00
|
|
|
qry = simpleQuery[len(simpleQuery)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MatchQuery{
|
|
|
|
field: fieldName,
|
|
|
|
mType: mType,
|
|
|
|
params: matchParams{
|
|
|
|
Qry: qry,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Query sets the data to find in the query's field (it is the "query" component
|
|
|
|
// of the query).
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Query(data interface{}) *MatchQuery {
|
|
|
|
q.params.Qry = data
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Analyzer sets the analyzer used to convert the text in the "query" value into
|
|
|
|
// tokens.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Analyzer(a string) *MatchQuery {
|
|
|
|
q.params.Anl = a
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// AutoGenerateSynonymsPhraseQuery sets the "auto_generate_synonyms_phrase_query"
|
|
|
|
// boolean.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) AutoGenerateSynonymsPhraseQuery(b bool) *MatchQuery {
|
|
|
|
q.params.AutoGenerate = &b
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Fuzziness set the maximum edit distance allowed for matching.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Fuzziness(f string) *MatchQuery {
|
|
|
|
q.params.Fuzz = f
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MaxExpansions sets the maximum number of terms to which the query will expand.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) MaxExpansions(e uint16) *MatchQuery {
|
|
|
|
q.params.MaxExp = e
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// PrefixLength sets the number of beginning characters left unchanged for fuzzy
|
|
|
|
// matching.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) PrefixLength(l uint16) *MatchQuery {
|
|
|
|
q.params.PrefLen = l
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Transpositions sets whether edits for fuzzy matching include transpositions
|
|
|
|
// of two adjacent characters.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Transpositions(b bool) *MatchQuery {
|
|
|
|
q.params.Trans = &b
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// FuzzyRewrite sets the method used to rewrite the query.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) FuzzyRewrite(s string) *MatchQuery {
|
|
|
|
q.params.FuzzyRw = s
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Lenient sets whether format-based errors should be ignored.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Lenient(b bool) *MatchQuery {
|
|
|
|
q.params.Lent = b
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Operator sets the boolean logic used to interpret text in the query value.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Operator(op MatchOperator) *MatchQuery {
|
|
|
|
q.params.Op = op
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MinimumShouldMatch sets the minimum number of clauses that must match for a
|
|
|
|
// document to be returned.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) MinimumShouldMatch(s string) *MatchQuery {
|
|
|
|
q.params.MinMatch = s
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// Slop sets the maximum number of positions allowed between matching tokens.
|
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-18 12:00:15 +00:00
|
|
|
func (q *MatchQuery) Slop(n uint16) *MatchQuery {
|
|
|
|
q.params.Slp = n
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// ZeroTermsQuery sets the "zero_terms_query" option to use. This indicates
|
|
|
|
// whether no documents are returned if the analyzer removes all tokens, such as
|
|
|
|
// when using a stop filter.
|
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-19 11:35:21 +00:00
|
|
|
func (q *MatchQuery) ZeroTermsQuery(s ZeroTerms) *MatchQuery {
|
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-18 12:00:15 +00:00
|
|
|
q.params.ZeroTerms = s
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2022-01-06 20:54:24 +00:00
|
|
|
// Boost sets the boost value of the query.
|
2023-11-01 21:30:33 +00:00
|
|
|
func (q *MatchQuery) Boost(b float32) *MatchQuery {
|
|
|
|
q.params.Boost = b
|
|
|
|
return q
|
2022-01-06 20:54:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// MatchOperator is an enumeration type representing supported values for a
|
|
|
|
// match query's "operator" parameter.
|
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-18 12:00:15 +00:00
|
|
|
type MatchOperator uint8
|
|
|
|
|
|
|
|
const (
|
2020-02-27 14:19:07 +00:00
|
|
|
// OperatorOr is the "or" operator
|
|
|
|
OperatorOr MatchOperator = iota
|
|
|
|
|
|
|
|
// OperatorAnd is the "and" operator
|
|
|
|
OperatorAnd
|
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-18 12:00:15 +00:00
|
|
|
)
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// String returns a string representation of the match operator, as known to
|
|
|
|
// ElasticSearch.
|
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-19 11:35:21 +00:00
|
|
|
func (a MatchOperator) String() string {
|
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-18 12:00:15 +00:00
|
|
|
switch a {
|
2020-02-27 14:19:07 +00:00
|
|
|
case OperatorOr:
|
|
|
|
return "OR"
|
|
|
|
case OperatorAnd:
|
|
|
|
return "AND"
|
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-18 12:00:15 +00:00
|
|
|
default:
|
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-19 11:35:21 +00:00
|
|
|
return ""
|
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-18 12:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// ZeroTerms is an enumeration type representing supported values for a match
|
|
|
|
// query's "zero_terms_query" parameter.
|
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-18 12:00:15 +00:00
|
|
|
type ZeroTerms uint8
|
|
|
|
|
|
|
|
const (
|
2020-02-27 14:19:07 +00:00
|
|
|
// ZeroTermsNone is the "none" value
|
|
|
|
ZeroTermsNone ZeroTerms = iota
|
|
|
|
|
|
|
|
// ZeroTermsAll is the "all" value
|
|
|
|
ZeroTermsAll
|
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-18 12:00:15 +00:00
|
|
|
)
|
|
|
|
|
2020-02-27 14:19:07 +00:00
|
|
|
// String returns a string representation of the zero_terms_query parameter, as
|
|
|
|
// known to ElasticSearch.
|
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-19 11:35:21 +00:00
|
|
|
func (a ZeroTerms) String() string {
|
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-18 12:00:15 +00:00
|
|
|
switch a {
|
2020-02-27 14:19:07 +00:00
|
|
|
case ZeroTermsNone:
|
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-19 11:35:21 +00:00
|
|
|
return "none"
|
2020-02-27 14:19:07 +00:00
|
|
|
case ZeroTermsAll:
|
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-19 11:35:21 +00:00
|
|
|
return "all"
|
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-18 12:00:15 +00:00
|
|
|
default:
|
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-19 11:35:21 +00:00
|
|
|
return ""
|
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-18 12:00:15 +00:00
|
|
|
}
|
|
|
|
}
|