Skip to content

ES 6.x: Content-Type header is missing #5

Open
@sagimann

Description

@sagimann

Hi, I can't seem to use the module (v6.8.8), steps to reproduce below:

// env on Elastic Beanstalk EC2 machine:
npm i @elastic/elasticsearch@6
export AWS_REGION='xx-xxxx-1'
export ES_ENDPOINT='https://.../'

// code:
const ES = require('@elastic/elasticsearch');
const { createConnector } = require('aws-elasticsearch-js');
_es = new ES.Client({
    node: process.env.ES_ENDPOINT,
    Connection: createConnector()
});
const q = {
    "index": "lyrics_catalog",
    "type": "_doc",
    "size":1,
    "body": {
        "query": {
            "match_all":{}
       }
    }
}
_es.search(q).then(console.log, console.error)

// output:
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 3468,
  [Symbol(trigger_async_id_symbol)]: 3465,
  [Symbol(destroyed)]: { destroyed: false }
}
> ResponseError: Response Error
    at IncomingMessage.<anonymous> (/xxx/node_modules/@elastic/elasticsearch/lib/Transport.js:310:25)
    at IncomingMessage.emit (node:events:532:35)
    at IncomingMessage.emit (node:domain:537:15)
    at endReadableNT (node:internal/streams/readable:1346:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  meta: {
    body: { error: 'Content-Type header is missing', status: 406 },
    statusCode: 406,
    headers: {
      date: 'Sun, 27 Feb 2022 16:06:53 GMT',
      'content-type': 'application/json; charset=UTF-8',
      'content-length': '55',
      connection: 'keep-alive',
      'access-control-allow-origin': '*'
    },
    warnings: null,
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 0,
      aborted: false
    }
  }
}

Note that adding headers option to the ES client (as described here) breaks the initialization with another error:

Uncaught TypeError: Cannot read properties of undefined (reading 'username')
    at getAuth (/xxx/node_modules/@elastic/elasticsearch/index.js:231:16)
    at new Client (/xxx/node_modules/@elastic/elasticsearch/index.js:70:23)

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