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
550 B

package main
import (
"fmt"
elastic "github.com/olivere/elastic/v7"
"os"
)
func ClientFromConfig(server *ElasticServer) *elastic.Client {
opts := []elastic.ClientOptionFunc{
elastic.SetURL(server.URL),
elastic.SetSniff(false),
elastic.SetGzip(true),
}
if server.User != "" && server.Pass != "" {
opts = append(opts, elastic.SetBasicAuth(
server.User, server.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
}