Connection Error (NodejsClient 8.0)

Hi,
I am trying to connect to my Elasticsearch 8.0 cluster through a Javascript client 8.0 and I am having this error

ConnectionError: other side closed - Local: 172.31.0.1:60684, Remote: 172.31.0.4:9200
    at SniffingTransport.request (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/transport/lib/Transport.js:525:31)
    at async Client.SearchApi [as search] (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/elasticsearch/lib/api/api/search.js:65:12)
    at async data_aggregation (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:340:22)
    at async getAggregatedData (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:233:19)
    at async responseMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:173:19)
    at async isFayvedMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:159:24)
    at async get_results (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:95:27)
    at async exports.get_web (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:79:23)
    at async Object.exports.get_trends (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/api_caller.js:46:40)
    at async exports.get_trend (/home/ilsa/work/fayvo/nodeexpress/controllers/suggestionController.js:5:16) {
  meta: {
    body: undefined,
    statusCode: 0,
    headers: {},
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 3,
      aborted: false
    },
    warnings: [Getter]
  }
}



{
    "data": {
        "name": "ConnectionError",
        "meta": {
            "statusCode": 0,
            "headers": {},
            "meta": {
                "context": null,
                "request": {
                    "params": {
                        "method": "POST",
                        "path": "/_search",
                        "body": "{\"query\":{\"bool\":{\"must\":[{\"match_all\":{}}]}}}",,
                        "querystring": "",
                        "headers": {
                            "user-agent": "elastic-transport-js/8.0.2 (linux 5.13.0-30-generic-x64; Node.js v14.18.3)",
                            "x-elastic-client-meta": "es=8.0.0,js=14.18.3,t=8.0.2,hc=14.18.3",
                            "content-type": "application/vnd.elasticsearch+json; compatible-with=8",
                            "accept": "application/vnd.elasticsearch+json; compatible-with=8",
                            "content-length": "4485"
                        }
                    },
                    "options": {},
                    "id": 1
                },
                "name": "elasticsearch-js",
                "connection": {
                    "url": "http://172.31.0.4:9200/",
                    "id": "http://172.31.0.4:9200/",
                    "headers": {},
                    "status": "alive"
                },
                "attempts": 3,
                "aborted": false
            },
            "warnings": null
        }
    }
}

The client that i'm preparing to connect looks something like this


let url = new URL(ELASICSEARCH_HOST)
url['username'] = ELASICSEARCH_USER
url['password'] = ELASICSEARCH_PASS
const client = new Client({
    node: {
        url: url
    }
});

const client = new Client({
    node: {
        url: new URL(ELASICSEARCH_HOST),
        auth: {
            username: ELASICSEARCH_USER,
            password: ELASICSEARCH_PASS
        }
    }
});

I have mentioned two client definitions above (i have tried to make connection using both but no success)

can anyone please help me in making a connection to Elasticsearch 8.0 cluster

i randomly sometime get this error

ConnectionError: unable to verify the first certificate
    at SniffingTransport.request (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/transport/lib/Transport.js:525:31)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Client.SearchApi [as search] (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/elasticsearch/lib/api/api/search.js:65:12)
    at async data_aggregation (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:350:17)
    at async getAggregatedData (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:235:19)
    at async responseMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:175:19)
    at async isFayvedMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:161:24)
    at async get_results (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:97:27)
    at async exports.get_web (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:81:23)
    at async Object.exports.get_trends (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/api_caller.js:46:40)
    at async exports.get_trend (/home/ilsa/work/fayvo/nodeexpress/controllers/suggestionController.js:5:16) {
  meta: {
    body: undefined,
    statusCode: 0,
    headers: {},
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 3,
      aborted: false
    },
    warnings: [Getter]
  }
}

Hello! Can you try the following code and let me know if you encounter the same issue?

const { Client, HttpConnection } = require('@elastic/elasticsearch')
const client = new Client({
  node: url.toString(),
  Connection: HttpConnection
})

hi, i have tried this but still i got error "ConnectionError: socket hang up - Local: 172.24.0.1:47080, Remote: 172.24.0.3:9200"

i want add a that even on browser I'm able to access the ip with a https request and going in unsafe mode and providing a username and password as well.
I'm using the docker-compose file exactly same on this page Install Elasticsearch with Docker | Elasticsearch Guide [8.0] | Elastic

mainly i need to understand from where this error is coming from and where do i need to put certificates for verifications

It looks like the problem is caused by a self-signed certificate, take a look here to see how to configure custom TLS options.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.