Comments (5)
@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.
@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.
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.
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.
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)
- Support Cloudflare Workers / Vercel Edge Functions HOT 3
- The query attribute on the `EnrichPolicy` should be `QueryDslQueryContainer | QueryDslQueryContainer[]` not `string` HOT 3
- Bulk helper not giving indications on failure when using stream as datasource HOT 1
- Number of open connections spikes when retryable errors occur HOT 7
- Deno: Module '"npm:@elastic/elasticsearch"' has no exported member 'CatIndicesIndicesRecord'. HOT 1
- Internal module error HOT 1
- bulk helper add onSuccess callback HOT 3
- Global client context not passed to Transport in 7.13.0 HOT 1
- Support for ES|QL HOT 2
- enum and/or type guard for QueryDslTextQueryType HOT 1
- search_after with sort on nested fields HOT 1
- Redaction mechanism transform arrays properties into objects HOT 1
- Nuxt 3 compatibility HOT 2
- Using the `[]` chars for an enrich policy name isn't wrapped correctly on `deletePolicy` method HOT 1
- ProductNotSupportedError: The client noticed that the server is not a supported distribution of Elasticsearch HOT 1
- Add types for plugins HOT 2
- Error parsing undici module in Next.js 14 project HOT 3
- MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 product-check listeners added HOT 3
- test issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-js.