connect.go 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // Connect simply connects to Elasticsearch.
  5. //
  6. // Example
  7. //
  8. //
  9. // connect -url=http://127.0.0.1:9200 -sniff=false
  10. //
  11. package main
  12. import (
  13. "flag"
  14. "fmt"
  15. "log"
  16. "gopkg.in/olivere/elastic.v5"
  17. )
  18. func main() {
  19. var (
  20. url = flag.String("url", "http://localhost:9200", "Elasticsearch URL")
  21. sniff = flag.Bool("sniff", true, "Enable or disable sniffing")
  22. )
  23. flag.Parse()
  24. log.SetFlags(0)
  25. if *url == "" {
  26. *url = "http://127.0.0.1:9200"
  27. }
  28. // Create an Elasticsearch client
  29. client, err := elastic.NewClient(elastic.SetURL(*url), elastic.SetSniff(*sniff))
  30. if err != nil {
  31. log.Fatal(err)
  32. }
  33. _ = client
  34. // Just a status message
  35. fmt.Println("Connection succeeded")
  36. }