search_queries_boosting_test.go 811 B

1234567891011121314151617181920212223242526
  1. // Copyright 2012-2015 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. package elastic
  5. import (
  6. "encoding/json"
  7. "testing"
  8. )
  9. func TestBoostingQuery(t *testing.T) {
  10. q := NewBoostingQuery()
  11. q = q.Positive(NewTermQuery("tag", "wow"))
  12. q = q.Negative(NewRangeQuery("age").From(10).To(20))
  13. q = q.NegativeBoost(0.2)
  14. data, err := json.Marshal(q.Source())
  15. if err != nil {
  16. t.Fatalf("marshaling to JSON failed: %v", err)
  17. }
  18. got := string(data)
  19. expected := `{"boosting":{"negative":{"range":{"age":{"from":10,"include_lower":true,"include_upper":true,"to":20}}},"negative_boost":0.2,"positive":{"term":{"tag":"wow"}}}}`
  20. if got != expected {
  21. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  22. }
  23. }