Debian Codegraph @

search_queries_match_phrase_test.go

raw
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 TestMatchPhraseQuery(t *testing.T) {
13 q := NewMatchPhraseQuery("message", "this is a test").
14 Analyzer("my_analyzer").
15 Boost(0.7)
16 src, err := q.Source()
17 if err != nil {
18 t.Fatal(err)
19 }
20 data, err := json.Marshal(src)
21 if err != nil {
22 t.Fatalf("marshaling to JSON failed: %v", err)
23 }
24 got := string(data)
25 expected := `{"match_phrase":{"message":{"analyzer":"my_analyzer","boost":0.7,"query":"this is a test"}}}`
26 if got != expected {
27 t.Errorf("expected\n%s\n,got:\n%s", expected, got)
28 }
29 }