| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
package elastic |
| 6 |
|
| 7 |
import ( |
| 8 |
"encoding/json" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func TestBoostingQuery(t *testing.T) { |
| 13 |
q := NewBoostingQuery() |
| 14 |
q = q.Positive(NewTermQuery("tag", "wow")) |
| 15 |
q = q.Negative(NewRangeQuery("age").From(10).To(20)) |
| 16 |
q = q.NegativeBoost(0.2) |
| 17 |
src, err := q.Source() |
| 18 |
if err != nil { |
| 19 |
t.Fatal(err) |
| 20 |
} |
| 21 |
data, err := json.Marshal(src) |
| 22 |
if err != nil { |
| 23 |
t.Fatalf("marshaling to JSON failed: %v", err) |
| 24 |
} |
| 25 |
got := string(data) |
| 26 |
expected := `{"boosting":{"negative":{"range":{"age":{"from":10,"include_lower":true,"include_upper":true,"to":20}}},"negative_boost":0.2,"positive":{"term":{"tag":"wow"}}}}` |
| 27 |
if got != expected { |
| 28 |
t.Errorf("expected\n%s\n,got:\n%s", expected, got) |
| 29 |
} |
| 30 |
} |