Skip to content
Oliver Eilhard edited this page Oct 8, 2015 · 7 revisions

The Ping service connects to an Elasticsearch server (http://127.0.0.1:9200 by default, see below) and gets e.g. the version number.

// Ping the Elasticsearch server to get e.g. the version number
info, code, err := client.Ping().Do()
if err != nil {
    // Handle error
    panic(err)
}
fmt.Printf("Elasticsearch returned with code %d and version %s", code, info.Version.Number)

Notice: In elastic v2, the Ping service is special in that it doesn't use the URLs of the client but the one specified via the URL function of the PingService (which is http://127.0.0.1:9200 by default).

So to use the PingService in v2 correctly, specify the URL directly:

info, code, err := client.Ping().URL("<es-node-url>").Do()
...

The reason for this special behavior are as follows: First, you typically use Ping to not only find your current cluster, but also other Elasticsearch instances as well. Second, you can specify many URLs for your cluster and Elastic happily does round-robin to load balance between the nodes. If you use many URLs, which one do you use by default for the PingService?

Anyway, just specify a URL with your Ping and you should be fine. :-)

As this is probably the no. 1 question asked via GitHub issues, the behavior of Ping has changed in elastic v3. In v3, you always have to specify the URL of the server you want to Ping in the PingService.

Clone this wiki locally