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{}`.
37 lines
706 B
Go
37 lines
706 B
Go
package esquery
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestBoosting(t *testing.T) {
|
|
runMapTests(t, []mapTest{
|
|
{
|
|
"boosting query",
|
|
Boosting().
|
|
Positive(Term("text", "apple")).
|
|
Negative(Term("text", "pie tart")).
|
|
NegativeBoost(0.5),
|
|
map[string]interface{}{
|
|
"boosting": map[string]interface{}{
|
|
"positive": map[string]interface{}{
|
|
"term": map[string]interface{}{
|
|
"text": map[string]interface{}{
|
|
"value": "apple",
|
|
},
|
|
},
|
|
},
|
|
"negative": map[string]interface{}{
|
|
"term": map[string]interface{}{
|
|
"text": map[string]interface{}{
|
|
"value": "pie tart",
|
|
},
|
|
},
|
|
},
|
|
"negative_boost": 0.5,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|