doc.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 provides an interface to the Elasticsearch server
  6. (https://www.elastic.co/products/elasticsearch).
  7. The first thing you do is to create a Client. If you have Elasticsearch
  8. installed and running with its default settings
  9. (i.e. available at http://127.0.0.1:9200), all you need to do is:
  10. client, err := elastic.NewClient()
  11. if err != nil {
  12. // Handle error
  13. }
  14. If your Elasticsearch server is running on a different IP and/or port,
  15. just provide a URL to NewClient:
  16. // Create a client and connect to http://192.168.2.10:9201
  17. client, err := elastic.NewClient(elastic.SetURL("http://192.168.2.10:9201"))
  18. if err != nil {
  19. // Handle error
  20. }
  21. You can pass many more configuration parameters to NewClient. Review the
  22. documentation of NewClient for more information.
  23. If no Elasticsearch server is available, services will fail when creating
  24. a new request and will return ErrNoClient.
  25. A Client provides services. The services usually come with a variety of
  26. methods to prepare the query and a Do function to execute it against the
  27. Elasticsearch REST interface and return a response. Here is an example
  28. of the IndexExists service that checks if a given index already exists.
  29. exists, err := client.IndexExists("twitter").Do(context.Background())
  30. if err != nil {
  31. // Handle error
  32. }
  33. if !exists {
  34. // Index does not exist yet.
  35. }
  36. Look up the documentation for Client to get an idea of the services provided
  37. and what kinds of responses you get when executing the Do function of a service.
  38. Also see the wiki on Github for more details.
  39. */
  40. package elastic