doc.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. /*
  18. Package elasticsearch provides a Go client for Elasticsearch.
  19. Create the client with the NewDefaultClient function:
  20. elasticsearch.NewDefaultClient()
  21. The ELASTICSEARCH_URL environment variable is used instead of the default URL, when set.
  22. Use a comma to separate multiple URLs.
  23. To configure the client, pass a Config object to the NewClient function:
  24. cfg := elasticsearch.Config{
  25. Addresses: []string{
  26. "http://localhost:9200",
  27. "http://localhost:9201",
  28. },
  29. Username: "foo",
  30. Password: "bar",
  31. Transport: &http.Transport{
  32. MaxIdleConnsPerHost: 10,
  33. ResponseHeaderTimeout: time.Second,
  34. DialContext: (&net.Dialer{Timeout: time.Second}).DialContext,
  35. TLSClientConfig: &tls.Config{
  36. MinVersion: tls.VersionTLS12,
  37. },
  38. },
  39. }
  40. elasticsearch.NewClient(cfg)
  41. When using the Elastic Service (https://elastic.co/cloud), you can use CloudID instead of Addresses.
  42. When either Addresses or CloudID is set, the ELASTICSEARCH_URL environment variable is ignored.
  43. See the elasticsearch_integration_test.go file and the _examples folder for more information.
  44. Call the Elasticsearch APIs by invoking the corresponding methods on the client:
  45. res, err := es.Info()
  46. if err != nil {
  47. log.Fatalf("Error getting response: %s", err)
  48. }
  49. log.Println(res)
  50. See the github.com/elastic/go-elasticsearch/esapi package for more information about using the API.
  51. See the github.com/elastic/go-elasticsearch/estransport package for more information about configuring the transport.
  52. */
  53. package elasticsearch