Skip to content
Oliver Eilhard edited this page Feb 28, 2015 · 10 revisions

A client uses a sniffing process to find all nodes of your cluster by default, automatically. The official clients for e.g. Ruby do the same.

When you create a new client with elastic.NewClient(...), it starts a sniffing process. The sniffing process invokes the Cluster Nodes Info API on all provided URLs. If you did not specify a URL to connect to in NewClient(...), the default URL of http://127.0.0.1:9200 is used.

Here's what the Cluster Nodes Info API of Elasticsearch returns when successful:

$ curl -XGET 'http://127.0.0.1:9200/_nodes/http?pretty=1'
{
  "cluster_name" : "elasticsearch",
  "nodes" : {
    "msEWB6vOQ6qVzC2y8fTOhw" : {
      "name" : "Blackheath",
      "transport_address" : "inet[/127.0.0.1:9300]",
      "host" : "aero",
      "ip" : "192.168.10.10",
      "version" : "1.4.4",
      "build" : "c88f77f",
      "http_address" : "inet[/127.0.0.1:9200]",
      "http" : {
        "bound_address" : "inet[/127.0.0.1:9200]",
        "publish_address" : "inet[/127.0.0.1:9200]"
      }
    }
  }
}

You see that it returns a map with the node ID as its key, and the HTTP (or HTTPS) address to connect to the given node. Elastic will now happily use the results of this call to update its internal list of nodes/connections.

This sniffing process happens periodically (every 15 minutes by default). This ensures that Elastic always has an up-to-date list of nodes in your cluster. When a node in your cluster goes down, or you add a new node to your cluster, Elastic happily picks it up and uses it. You can control the sniffing interval with SetSnifferInterval(...) (see setting up a new client.

When sniffing the cluster fails as you create the new client, an error is returned: Elastic might have a problem to find any suitable node in your cluster. In subsequent sniffing processes, the sniffer might you fail silently (it logs failures of course).

If you don't want sniffing, you can disable it when creating a client:

client, err := elastic.NewClient(elastic.SetSniff(false))

Notice that the sniffing process has a companion health check process.

Clone this wiki locally