Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sagimann opened this issue Feb 27, 2022 · 0 comments
Open

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

sagimann opened this issue Feb 27, 2022 · 0 comments

Comments

@sagimann
Copy link

sagimann commented Feb 27, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant