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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content-Type header being changed to "text/plain" from "application/json" somewhere in the process of publishing a document to self-hosted Elasticsearch #2092
Comments
@ghettosamson Can you use the observability EventEmitter to listen to 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. |
@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
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]. |
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
Here, I just pass a simple {"a":"b"} object |
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. |
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 |
馃悰 Bug Report
When running my NodeJS application deployed on AWS Lambda, the
Content-Type
header is being changed totext/plain
which causes Elasticsearch to not ingest the document.To Reproduce
Steps to reproduce the behavior:
Error below:
AWS Event being processed
Paste your code here:
Here is the entire Dockerfile
Here is the javascript code processing the event:
elasticsearch client configuration:
Expected behavior
I expect the document to successfully be published to elasticsearch instead of getting a header error.
Paste the results here:
Creating the new document in elasticsearch with id ses-event-f43f4a04ec2a46ca to stream filebeat-8.10.2 All Promises settled 2
When I run this code locally on an M2 Mac with the latest MacOS, it works. It works as a node app outside of Docker and inside of Docker with the same Dockerfile as above using the following link to testing images locally but it fails when deployed to AWS Lambda
Environment
@elastic/elasticsearch
version: >=8.10.0The text was updated successfully, but these errors were encountered: