Skip to content

Unable to connect to elasticsearch instance running on non-root path #1709

@karatekaneen

Description

@karatekaneen

🐛 Bug Report

I'm unable to connect to elasticsearch instance running on non-root path, in my case /elastic. This is due to this function in Undici that does not allow non-root paths. Might be related to #1625 but not sure so opening a new issue.

To Reproduce

const client = new Client({
  node: "http://secret.com/elastic",
  auth: {
    username: "admin",
    password: "admin",
  },
});

Expected behavior

I would love to be able to connect to an Elasticsearch instance that is hidden behind a k8s ingress.

Output:

InvalidArgumentError: invalid url
    at Object.parseOrigin (/workspace/node_modules/undici/lib/core/util.js:83:11)
    at new Pool (/workspace/node_modules/undici/lib/pool.js:62:23)
    at new Connection (/workspace/node_modules/@elastic/transport/src/connection/UndiciConnection.ts:113:17)
    at WeightedConnectionPool.createConnection (/workspace/node_modules/@elastic/transport/src/pool/BaseConnectionPool.ts:133:24)
    at WeightedConnectionPool.addConnection (/workspace/node_modules/@elastic/transport/src/pool/BaseConnectionPool.ts:158:53)
    at new Client (/workspace/node_modules/@elastic/elasticsearch/src/client.ts:231:27)
    at /workspace/src/server.ts:26:18
    at Generator.next (<anonymous>)
    at /workspace/src/server.ts:8:71
    at new Promise (<anonymous>)
    at __awaiter (/workspace/src/server.ts:4:12)
    at init (/workspace/src/server.ts:23:12)
    at Object.<anonymous> (/workspace/src/index.ts:3:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module.m._compile (/workspace/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
  code: 'UND_ERR_INVALID_ARG'
}

Your Environment

  • node version: 18
  • @elastic/elasticsearch 8.2.1
  • os: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions