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.
16 lines
844 B
Go
16 lines
844 B
Go
package esquery
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMatch(t *testing.T) {
|
|
runTests(t, []queryTest{
|
|
{"simple match", Match("title", "sample text"), "{\"match\":{\"title\":{\"query\":\"sample text\"}}}\n"},
|
|
{"match with more params", Match("issue_number").Query(16).Transpositions(false).MaxExpansions(32).Operator(AND), "{\"match\":{\"issue_number\":{\"query\":16,\"max_expansions\":32,\"transpositions\":false,\"operator\":\"and\"}}}\n"},
|
|
{"match_bool_prefix", MatchBoolPrefix("title", "sample text"), "{\"match_bool_prefix\":{\"title\":{\"query\":\"sample text\"}}}\n"},
|
|
{"match_phrase", MatchPhrase("title", "sample text"), "{\"match_phrase\":{\"title\":{\"query\":\"sample text\"}}}\n"},
|
|
{"match_phrase_prefix", MatchPhrasePrefix("title", "sample text"), "{\"match_phrase_prefix\":{\"title\":{\"query\":\"sample text\"}}}\n"},
|
|
})
|
|
}
|