search_queries_query_string_test.go 663 B

123456789101112131415161718192021222324
  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 TestQueryStringQuery(t *testing.T) {
  10. q := NewQueryStringQuery(`this AND that OR thus`)
  11. q = q.DefaultField("content")
  12. data, err := json.Marshal(q.Source())
  13. if err != nil {
  14. t.Fatalf("marshaling to JSON failed: %v", err)
  15. }
  16. got := string(data)
  17. expected := `{"query_string":{"default_field":"content","query":"this AND that OR thus"}}`
  18. if got != expected {
  19. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  20. }
  21. }