File tree 2 files changed +38
-30
lines changed
2 files changed +38
-30
lines changed Original file line number Diff line number Diff line change
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_test
6
+
7
+ import (
8
+ "context"
9
+
10
+ "gopkg.in/olivere/elastic.v5"
11
+ )
12
+
13
+ func ExamplePrefixQuery () {
14
+ // Get a client to the local Elasticsearch instance.
15
+ client , err := elastic .NewClient ()
16
+ if err != nil {
17
+ // Handle error
18
+ panic (err )
19
+ }
20
+
21
+ // Define wildcard query
22
+ q := elastic .NewPrefixQuery ("user" , "oli" )
23
+ q = q .QueryName ("my_query_name" )
24
+
25
+ searchResult , err := client .Search ().
26
+ Index ("twitter" ).
27
+ Query (q ).
28
+ Pretty (true ).
29
+ Do (context .Background ())
30
+ if err != nil {
31
+ // Handle error
32
+ panic (err )
33
+ }
34
+ _ = searchResult
35
+ }
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a MIT-license.
3
3
// See http://olivere.mit-license.org/license.txt for details.
4
4
5
- package elastic_test
5
+ package elastic
6
6
7
7
import (
8
- "context"
9
8
"encoding/json"
10
9
"testing"
11
-
12
- "gopkg.in/olivere/elastic.v5"
13
10
)
14
11
15
- func ExamplePrefixQuery () {
16
- // Get a client to the local Elasticsearch instance.
17
- client , err := elastic .NewClient ()
18
- if err != nil {
19
- // Handle error
20
- panic (err )
21
- }
22
-
23
- // Define wildcard query
24
- q := elastic .NewPrefixQuery ("user" , "oli" )
25
- q = q .QueryName ("my_query_name" )
26
-
27
- searchResult , err := client .Search ().
28
- Index ("twitter" ).
29
- Query (q ).
30
- Pretty (true ).
31
- Do (context .Background ())
32
- if err != nil {
33
- // Handle error
34
- panic (err )
35
- }
36
- _ = searchResult
37
- }
38
-
39
12
func TestPrefixQuery (t * testing.T ) {
40
- q := elastic . NewPrefixQuery ("user" , "ki" )
13
+ q := NewPrefixQuery ("user" , "ki" )
41
14
src , err := q .Source ()
42
15
if err != nil {
43
16
t .Fatal (err )
@@ -54,7 +27,7 @@ func TestPrefixQuery(t *testing.T) {
54
27
}
55
28
56
29
func TestPrefixQueryWithOptions (t * testing.T ) {
57
- q := elastic . NewPrefixQuery ("user" , "ki" )
30
+ q := NewPrefixQuery ("user" , "ki" )
58
31
q = q .QueryName ("my_query_name" )
59
32
src , err := q .Source ()
60
33
if err != nil {
You can’t perform that action at this time.
0 commit comments