| 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 |
} |