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.
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package esquery
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMatch(t *testing.T) {
|
|
runMapTests(t, []mapTest{
|
|
{
|
|
"simple match",
|
|
Match("title", "sample text"),
|
|
map[string]interface{}{
|
|
"match": map[string]interface{}{
|
|
"title": map[string]interface{}{
|
|
"query": "sample text",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"match with more params",
|
|
Match("issue_number").Query(16).Transpositions(false).MaxExpansions(32).Operator(OperatorAnd),
|
|
map[string]interface{}{
|
|
"match": map[string]interface{}{
|
|
"issue_number": map[string]interface{}{
|
|
"query": 16,
|
|
"max_expansions": 32,
|
|
"transpositions": false,
|
|
"operator": "AND",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"match_bool_prefix",
|
|
MatchBoolPrefix("title", "sample text"),
|
|
map[string]interface{}{
|
|
"match_bool_prefix": map[string]interface{}{
|
|
"title": map[string]interface{}{
|
|
"query": "sample text",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"match_phrase",
|
|
MatchPhrase("title", "sample text"),
|
|
map[string]interface{}{
|
|
"match_phrase": map[string]interface{}{
|
|
"title": map[string]interface{}{
|
|
"query": "sample text",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"match_phrase_prefix",
|
|
MatchPhrasePrefix("title", "sample text"),
|
|
map[string]interface{}{
|
|
"match_phrase_prefix": map[string]interface{}{
|
|
"title": map[string]interface{}{
|
|
"query": "sample text",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|