Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to elastic search : no active connection found: no Elasticsearch node available

I just cannot understand what is happening. My go application is unable to connect to elastic search. The node is available, is up and running. What am I doing wrong here?

import (
    "fmt"
    "github.com/olivere/elastic/v7"
    "github.com/sirupsen/logrus"
    "gitlab.com/codereverie/anuvadak-api-server/app_config"
    "gopkg.in/sohlich/elogrus.v7"
    "gopkg.in/validator.v2"
    "io"
    "os"
)

eurl := "http://ip:port"
eUsername := "username"
ePassword := "password"

client, err := elastic.NewClient(elastic.SetURL(eurl), elastic.SetBasicAuth(eUsername, ePassword))

if err != nil {
    fmt.Println("Some error", err.Error())
    panic("Failed to initialize elastic-search client")
}

What is incorrect here? The error says no active connection found: no Elasticsearch node available

Here is the data returned from elastic search when I hit the GET request in browser

  {
"name": "ABC-1",
"cluster_name": "ABC",
"cluster_uuid": "3oo05v6lSSmE7DpRh_68Yg",
"version": {
  "number": "7.6.2",
  "build_flavor": "default",
  "build_type": "deb",
  "build_hash": "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
  "build_date": "2020-03-26T06:34:37.794943Z",
  "build_snapshot": false,
  "lucene_version": "8.4.0",
  "minimum_wire_compatibility_version": "6.8.0",
  "minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"

}

like image 356
Amanda Avatar asked Jan 25 '23 02:01

Amanda


1 Answers

Error no active connection found: no Elasticsearch node available usually happens when you keep sniffing in client enabled but your cluster doesn't have any nodes available. You can check status of your cluster by hitting: http://host:port/_nodes/http?pretty=true.

If you don't disable sniffing elastic Golang client will run process in background that polls /_nodes API (URL above) every 15 minutes and maintains list of healthy nodes. If there are no healthy nodes it ends with this error.

This can happen (NOTE: we had chat with OP where we debugged issue) also when your cluster is configured with private IPs (so in /_nodes API output you see private and not public IPs). Client with sniffing starts polling, gets the list of nodes and tries to connect to private IP but gets HTTP error because such node doesn't respond (or can't be even resolved in network where client is). So it marks it dead and progresses to other one. When there are no further nodes in cluster it reports no active connection found: no Elasticsearch node available.

To disable sniffing on client side (and to connect directly to specified node - but without any resiliency) you need to add &sniff=false to Elastic URL.

Sniffing can be disabled like this:

config, _ := config.Parse("http://user:pwd@host:port/index?sniff=false")
client, _ := elastic.NewClientFromConfig(config)

EDIT: or (preferred) via configuration setting elastic.SetSniff():

client, _ := elastic.NewClient(..., elastic.SetSniff(false), ...)
like image 179
blami Avatar answered Jan 31 '23 03:01

blami