Giter Club home page Giter Club logo

Comments (5)

JoshMock avatar JoshMock commented on June 8, 2024

@ghettosamson Can you use the observability EventEmitter to listen to request events and paste the output here? Just make sure to scrub any private info from the data before pasting.

I'd also like to know where your Elasticsearch instance is hosted in relation to your Lambda code. On AWS in an EC2 instance? On Elastic Cloud? Any details about what networking or proxies sit between them may be useful for debugging this.

from elasticsearch-js.

ghettosamson avatar ghettosamson commented on June 8, 2024

@JoshMock I added the following code:

esClient.diagnostic.on('request', (err, result) => {
    if (err) {
        console.log('Received error from request, log below');
        console.error(err);
    } else {
        console.log('Received non-error from request, log below');
        console.info(result);

        if (result?.meta?.connection?.headers) {
            console.log('Logging the headers', result.meta.connection.headers);
        } else {
            console.log('The result.meta.connection.headers was not populated');
        }
    }
});

and here are the log messages

INFO Received non-error from request, log below
INFO	{
  body: undefined,
  statusCode: 0,
  headers: {},
  meta: {
    context: null,
    request: { params: [Object], options: {}, id: 2 },
    name: 'elasticsearch-js',
    connection: {
      url: 'https://myurl:9200/',
      id: 'https://myurl:9200/',
      headers: [Object],
      status: 'alive'
    },
    attempts: 0,
    aborted: false
  },
  warnings: [Getter]
}
INFO { body: undefined, statusCode: 0, headers: {}, meta: { context: null, request: { params: [Object], options: {}, id: 2 }, name: 'elasticsearch-js', connection: { url: 'https://myurl:9200/', id: 'https://myurl:9200/', headers: [Object], status: 'alive' }, attempts: 0, aborted: false }, warnings: [Getter] }
INFO	Logging the headers {
  'content-type': 'application/vnd.elasticsearch+json; compatible-with=8',
  authorization: 'Basic abunchofrandomcharacterssendthemtothemoon='
}


ERROR	Promise was not fulfilled {
  status: 'rejected',
  reason: ResponseError: {"error":"Content-Type header [text/plain] is not supported","status":406}
      at SniffingTransport.request (/var/task/node_modules/@elastic/transport/lib/Transport.js:479:27)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Client.CreateApi [as create] (/var/task/node_modules/@elastic/elasticsearch/lib/api/api/create.js:43:12)
      at async Promise.allSettled (index 1)
      at async Runtime.processEvent [as handler] (/var/task/index.js:123:27) {
    meta: {
      body: [Object],
      statusCode: 406,
      headers: [Object],
      meta: [Object],
      warnings: [Getter]
    }
  }
}
ERROR Promise was not fulfilled { status: 'rejected', reason: ResponseError: {"error":"Content-Type header [text/plain] is not supported","status":406} at SniffingTransport.request (/var/task/node_modules/@elastic/transport/lib/Transport.js:479:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Client.CreateApi [as create] (/var/task/node_modules/@elastic/elasticsearch/lib/api/api/create.js:43:12) at async Promise.allSettled (index 1) at async Runtime.processEvent [as handler] (/var/task/index.js:123:27) { meta: { body: [Object], statusCode: 406, headers: [Object], meta: [Object], warnings: [Getter] } } }

ERROR	reason.meta {
  body: {
    error: 'Content-Type header [text/plain] is not supported',
    status: 406
  },
  statusCode: 406,
  headers: {
    date: 'Wed, 13 Dec 2023 23:08:07 GMT',
    'content-type': 'application/json',
    'content-length': '74',
    connection: 'keep-alive',
    'set-cookie': [
      'AWSALB=dUQ2JX1P/YW/IKgpBcPjeIlT6d3rZLVkHOY7jqRzEYibZrPMHIev4baEc1QZEpNsQNFCgUE7nmvPA8pC; Expires=Wed, 20 Dec 2023 23:08:07 GMT; Path=/',
      'AWSALBCORS=dUQ2JX1P/YW/lT6d3rZLVkHOY7jqRzEYibZrPMHIev4baEc1QZEpNsQNFCgUE7nmvPA8pC; Expires=Wed, 20 Dec 2023 23:08:07 GMT; Path=/; SameSite=None; Secure'
    ],
    'x-elastic-product': 'Elasticsearch'
  },
  meta: {
    context: null,
    request: { params: [Object], options: {}, id: 2 },
    name: 'elasticsearch-js',
    connection: {
      url: 'https://myurl:9200/',
      id: 'https://myurl:9200/',
      headers: [Object],
      status: 'alive'
    },
    attempts: 0,
    aborted: false
  },
  warnings: [Getter]
}
ERROR reason.meta { body: { error: 'Content-Type header [text/plain] is not supported', status: 406 }, statusCode: 406, headers: { date: 'Wed, 13 Dec 2023 23:08:07 GMT', 'content-type': 'application/json', 'content-length': '74', connection: 'keep-alive', 'set-cookie': [ 'AWSALB=dUQ2JX1P/YW/xs6h6Wn74jIKgpBcPjeIlT6d3rZLVkHOY7jqRzEYibZrPMHIev4baEc1QZEpNsQNFCgUE7nmvPA8pC; Expires=Wed, 20 Dec 2023 23:08:07 GMT; Path=/', 'AWSALBCORS=dUQ2JX1P/YW/s6h6Wn74jIKgpBcPjeIlT6d3rZLVkHOY7jqRzEYibZrPMHIev4baEc1QZEpNsQNFCgUE7nmvPA8pC; Expires=Wed, 20 Dec 2023 23:08:07 GMT; Path=/; SameSite=None; Secure' ], 'x-elastic-product': 'Elasticsearch' }, meta: { context: null, request: { params: [Object], options: {}, id: 2 }, name: 'elasticsearch-js', connection: { url: 'https://myurl:9200/', id: 'https://myurl:9200/', headers: [Object], status: 'alive' }, attempts: 0, aborted: false }, warnings: [Getter] }

settledPromise.reason.meta.meta.connection.headers {
  'content-type': 'application/vnd.elasticsearch+json; compatible-with=8',
  authorization: 'Basic abunchofrandomcharacterssendthemtothemoon='

My Elasticsearch instance is running as a Docker container in Fargate in the same VPC, in one of 3 private subnets, behind an ALB also in one of the same 3 private subnets. I don't see in any of the logs the content-type header being [text/plain].

from elasticsearch-js.

picheljitsu avatar picheljitsu commented on June 8, 2024

I ran into the same issue. I'm thinking it has something to do with how the body/document parameter is read into the buffer? I've tried multiple techniques to handle the encoding and it looks like it attempts to detect the type or the encoding, fails, thus also failing to set the content-type header? just a swag

{
  index: 'test',
  type: '_doc',
  body: '\x00\x00\x00\x00\x00\x00\x00\x00\x00{"a":"b"}'
}

Here, I just pass a simple {"a":"b"} object

from elasticsearch-js.

picheljitsu avatar picheljitsu commented on June 8, 2024

Ok, for my instance, I believe our reverse proxy was replace the content-type which was causing es to incorrectly parse the request. I noticed on the error response the host field said the response was from the rev proxy.

from elasticsearch-js.

JoshMock avatar JoshMock commented on June 8, 2024

Reverse proxies are definitely an important place to check when you get an unexpected content type on a response.

@ghettosamson Are you still experiencing this or is yours also caused by a reverse proxy or similar? If it's still an issue, in your sample output, instead of logging result can you serialize to JSON (JSON.stringify) first so that we can see the nested data rather than just [Object]?

from elasticsearch-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.