a command line interface for elastic (work in progress)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
538 B

  1. package main
  2. import (
  3. "fmt"
  4. elastic "github.com/olivere/elastic/v7"
  5. "os"
  6. )
  7. func ClientFromConfig(cfg ElasticConfiguration) *elastic.Client {
  8. opts := []elastic.ClientOptionFunc{
  9. elastic.SetURL(cfg.URL),
  10. elastic.SetSniff(false),
  11. elastic.SetGzip(true),
  12. }
  13. if cfg.User != "" && cfg.Pass != "" {
  14. opts = append(opts, elastic.SetBasicAuth(
  15. cfg.User, cfg.Pass,
  16. ))
  17. }
  18. es, err := elastic.NewClient(opts...)
  19. if err != nil {
  20. fmt.Fprintf(os.Stderr, "Elastic connection error: %s\n", err.Error())
  21. os.Exit(1)
  22. }
  23. return es
  24. }