search_queries_prefix_example_test.go 721 B

1234567891011121314151617181920212223242526272829303132333435
  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. package elastic_test
  5. import (
  6. "context"
  7. "gopkg.in/olivere/elastic.v5"
  8. )
  9. func ExamplePrefixQuery() {
  10. // Get a client to the local Elasticsearch instance.
  11. client, err := elastic.NewClient()
  12. if err != nil {
  13. // Handle error
  14. panic(err)
  15. }
  16. // Define wildcard query
  17. q := elastic.NewPrefixQuery("user", "oli")
  18. q = q.QueryName("my_query_name")
  19. searchResult, err := client.Search().
  20. Index("twitter").
  21. Query(q).
  22. Pretty(true).
  23. Do(context.Background())
  24. if err != nil {
  25. // Handle error
  26. panic(err)
  27. }
  28. _ = searchResult
  29. }