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

package main
import (
"fmt"
elastic "github.com/olivere/elastic/v7"
"os"
)
func ClientFromConfig(cfg ElasticConfiguration) *elastic.Client {
opts := []elastic.ClientOptionFunc{
elastic.SetURL(cfg.URL),
elastic.SetSniff(false),
elastic.SetGzip(true),
}
if cfg.User != "" && cfg.Pass != "" {
opts = append(opts, elastic.SetBasicAuth(
cfg.User, cfg.Pass,
))
}
es, err := elastic.NewClient(opts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Elastic connection error: %s\n", err.Error())
os.Exit(1)
}
return es
}