Skip to content

Commit 3f49414

Browse files
committed
Split prefix tests and example
1 parent 10924ba commit 3f49414

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

search_queries_prefix_example_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

search_queries_prefix_test.go

+3-30
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,15 @@
22
// Use of this source code is governed by a MIT-license.
33
// See http://olivere.mit-license.org/license.txt for details.
44

5-
package elastic_test
5+
package elastic
66

77
import (
8-
"context"
98
"encoding/json"
109
"testing"
11-
12-
"gopkg.in/olivere/elastic.v5"
1310
)
1411

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-
3912
func TestPrefixQuery(t *testing.T) {
40-
q := elastic.NewPrefixQuery("user", "ki")
13+
q := NewPrefixQuery("user", "ki")
4114
src, err := q.Source()
4215
if err != nil {
4316
t.Fatal(err)
@@ -54,7 +27,7 @@ func TestPrefixQuery(t *testing.T) {
5427
}
5528

5629
func TestPrefixQueryWithOptions(t *testing.T) {
57-
q := elastic.NewPrefixQuery("user", "ki")
30+
q := NewPrefixQuery("user", "ki")
5831
q = q.QueryName("my_query_name")
5932
src, err := q.Source()
6033
if err != nil {

0 commit comments

Comments
 (0)