Debian Codegraph @

search_queries_fuzzy_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 TestFuzzyQuery(t *testing.T) {
13 q := NewFuzzyQuery("user", "ki").Boost(1.5).Fuzziness(2).PrefixLength(0).MaxExpansions(100)
14 src, err := q.Source()
15 if err != nil {
16 t.Fatal(err)
17 }
18 data, err := json.Marshal(src)
19 if err != nil {
20 t.Fatalf("marshaling to JSON failed: %v", err)
21 }
22 got := string(data)
23 expected := `{"fuzzy":{"user":{"boost":1.5,"fuzziness":2,"max_expansions":100,"prefix_length":0,"value":"ki"}}}`
24 if got != expected {
25 t.Errorf("expected\n%s\n,got:\n%s", expected, got)
26 }
27 }