Skip to content

Instantly share code, notes, and snippets.

@thoellrich
Created June 25, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoellrich/fbe650e8e23b78f866ff82034bcf75a4 to your computer and use it in GitHub Desktop.
Save thoellrich/fbe650e8e23b78f866ff82034bcf75a4 to your computer and use it in GitHub Desktop.
Test sniffing/healthcheck
package main
import (
"fmt"
"flag"
"github.com/olivere/elastic"
)
func main() {
url := flag.String("url", "http://localhost:9200/", "Elasticsearch server (default: http://localhost:9200/)")
flag.Parse()
for _, c := range []struct{ health, sniff bool }{
{true, true},
{true, false},
{false, true},
{false, false},
} {
opts := []elastic.ClientOptionFunc{
elastic.SetURL(*url),
elastic.SetHealthcheck(c.health),
elastic.SetSniff(c.sniff),
}
fmt.Printf("health=%v, sniff=%v - ", c.health, c.sniff)
client, err := elastic.NewClient(opts...)
if err != nil {
fmt.Printf("err=%v\n", err)
} else {
v, e := client.ElasticsearchVersion(*url)
fmt.Printf("version=%v, version_err=%v, ", v, e)
i, e := client.IndexNames()
fmt.Printf("index_count=%d, index_err=%v\n", len(i), e)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment