Elasticsearch。错误:' content-type标头丢失了'

发布于 2025-02-06 10:31:30 字数 3349 浏览 2 评论 0原文

在AWS Elasticsearch v6.7上使用。为了使用ES使用库进行

 "@elastic/elasticsearch": "^6.8.8",

连接到ES使用库:

    "aws-elasticsearch-js": "^1.0.3",
    

连接没有任何类型的错误,我通过client.cluster.cluster.health({})对其进行了检查。 当我将请求发送到弹性时,我会收到此错误:

{
2022-06-09T13:30:49.589491939Z   meta: {
2022-06-09T13:30:49.589499754Z     body: { error: 'Content-Type header is missing', status: 406 },
2022-06-09T13:30:49.589508230Z     statusCode: 406,
2022-06-09T13:30:49.589516335Z     headers: {
2022-06-09T13:30:49.589523800Z       date: 'Thu, 09 Jun 2022 13:30:49 GMT',
2022-06-09T13:30:49.589531895Z       'content-type': 'application/json; charset=UTF-8',
2022-06-09T13:30:49.589540211Z       'content-length': '55',
2022-06-09T13:30:49.589548456Z       connection: 'keep-alive',
2022-06-09T13:30:49.589556442Z       'access-control-allow-origin': '*'
2022-06-09T13:30:49.589564667Z     },
2022-06-09T13:30:49.589572222Z     warnings: null,
2022-06-09T13:30:49.589580247Z     meta: {
2022-06-09T13:30:49.589587831Z       context: null,
2022-06-09T13:30:49.589595736Z       request: {
2022-06-09T13:30:49.589603151Z         params: {
2022-06-09T13:30:49.589610985Z           method: 'POST',
2022-06-09T13:30:49.589618951Z           path: '/api-index/_search',
2022-06-09T13:30:49.589629831Z           body: '<HUGE REQUESRT>',
2022-06-09T13:30:49.589649769Z           querystring: 'from=0&size=20',
2022-06-09T13:30:49.589658326Z           headers: {
2022-06-09T13:30:49.589668395Z             'User-Agent': 'elasticsearch-js/6.8.8 (linux 5.13.0-48-generic-x64; Node.js v16.15.0)',
2022-06-09T13:30:49.589681500Z             'Content-Type': 'application/json',
2022-06-09T13:30:49.589703652Z             'Content-Length': '971'
2022-06-09T13:30:49.589712749Z           },
2022-06-09T13:30:49.589720554Z           timeout: 30000
2022-06-09T13:30:49.589728680Z         },
2022-06-09T13:30:49.589736384Z         options: {
2022-06-09T13:30:49.589745772Z           headers: { 'Content-Type': 'application/json' },
2022-06-09T13:30:49.589757514Z           warnings: null
2022-06-09T13:30:49.589768034Z         },
2022-06-09T13:30:49.589778705Z         id: 8
2022-06-09T13:30:49.589789325Z       },
2022-06-09T13:30:49.589799224Z       name: 'elasticsearch-js',
2022-06-09T13:30:49.589810044Z       connection: {
2022-06-09T13:30:49.589820344Z         url: '<AWS_ES_URL>',
2022-06-09T13:30:49.589831866Z         id: '<AWS_ES_URL>',
2022-06-09T13:30:49.589843258Z         headers: {},
2022-06-09T13:30:49.589853748Z         deadCount: 0,
2022-06-09T13:30:49.589864799Z         resurrectTimeout: 0,
2022-06-09T13:30:49.589875569Z         _openRequests: 0,
2022-06-09T13:30:49.589886239Z         status: 'alive',
2022-06-09T13:30:49.589896579Z         roles: { master: true, data: true, ingest: true, ml: false }
2022-06-09T13:30:49.589908782Z       },
2022-06-09T13:30:49.589918832Z       attempts: 0,
2022-06-09T13:30:49.589928911Z       aborted: false
2022-06-09T13:30:49.589939952Z     }
2022-06-09T13:30:49.589950211Z   }
2022-06-09T13:30:49.589960531Z }

从错误描述中,我看到主要错误是content-type-header缺少。但是,作为他们的同时,我在请求中看到了元数据'content-type':'application/json',。 这个问题仅在ES v6.7发生。对于本地开发,我使用v7.2并成功起作用。 我不知道为什么ES Engine 6.7无法解析此标头。请帮助我,如果您遇到了同样的问题。

Use on AWS ElasticSearch v6.7. For working with ES use library

 "@elastic/elasticsearch": "^6.8.8",

For connecting to ES use also library:

    "aws-elasticsearch-js": "^1.0.3",
    

There is no any kind of errors with connection, I checked it by client.cluster.health({}).
When I send request to Elastic I got this error:

{
2022-06-09T13:30:49.589491939Z   meta: {
2022-06-09T13:30:49.589499754Z     body: { error: 'Content-Type header is missing', status: 406 },
2022-06-09T13:30:49.589508230Z     statusCode: 406,
2022-06-09T13:30:49.589516335Z     headers: {
2022-06-09T13:30:49.589523800Z       date: 'Thu, 09 Jun 2022 13:30:49 GMT',
2022-06-09T13:30:49.589531895Z       'content-type': 'application/json; charset=UTF-8',
2022-06-09T13:30:49.589540211Z       'content-length': '55',
2022-06-09T13:30:49.589548456Z       connection: 'keep-alive',
2022-06-09T13:30:49.589556442Z       'access-control-allow-origin': '*'
2022-06-09T13:30:49.589564667Z     },
2022-06-09T13:30:49.589572222Z     warnings: null,
2022-06-09T13:30:49.589580247Z     meta: {
2022-06-09T13:30:49.589587831Z       context: null,
2022-06-09T13:30:49.589595736Z       request: {
2022-06-09T13:30:49.589603151Z         params: {
2022-06-09T13:30:49.589610985Z           method: 'POST',
2022-06-09T13:30:49.589618951Z           path: '/api-index/_search',
2022-06-09T13:30:49.589629831Z           body: '<HUGE REQUESRT>',
2022-06-09T13:30:49.589649769Z           querystring: 'from=0&size=20',
2022-06-09T13:30:49.589658326Z           headers: {
2022-06-09T13:30:49.589668395Z             'User-Agent': 'elasticsearch-js/6.8.8 (linux 5.13.0-48-generic-x64; Node.js v16.15.0)',
2022-06-09T13:30:49.589681500Z             'Content-Type': 'application/json',
2022-06-09T13:30:49.589703652Z             'Content-Length': '971'
2022-06-09T13:30:49.589712749Z           },
2022-06-09T13:30:49.589720554Z           timeout: 30000
2022-06-09T13:30:49.589728680Z         },
2022-06-09T13:30:49.589736384Z         options: {
2022-06-09T13:30:49.589745772Z           headers: { 'Content-Type': 'application/json' },
2022-06-09T13:30:49.589757514Z           warnings: null
2022-06-09T13:30:49.589768034Z         },
2022-06-09T13:30:49.589778705Z         id: 8
2022-06-09T13:30:49.589789325Z       },
2022-06-09T13:30:49.589799224Z       name: 'elasticsearch-js',
2022-06-09T13:30:49.589810044Z       connection: {
2022-06-09T13:30:49.589820344Z         url: '<AWS_ES_URL>',
2022-06-09T13:30:49.589831866Z         id: '<AWS_ES_URL>',
2022-06-09T13:30:49.589843258Z         headers: {},
2022-06-09T13:30:49.589853748Z         deadCount: 0,
2022-06-09T13:30:49.589864799Z         resurrectTimeout: 0,
2022-06-09T13:30:49.589875569Z         _openRequests: 0,
2022-06-09T13:30:49.589886239Z         status: 'alive',
2022-06-09T13:30:49.589896579Z         roles: { master: true, data: true, ingest: true, ml: false }
2022-06-09T13:30:49.589908782Z       },
2022-06-09T13:30:49.589918832Z       attempts: 0,
2022-06-09T13:30:49.589928911Z       aborted: false
2022-06-09T13:30:49.589939952Z     }
2022-06-09T13:30:49.589950211Z   }
2022-06-09T13:30:49.589960531Z }

From error description I see that main error is Content-Type header is missing. But as them same time I see in request metadata 'Content-Type': 'application/json',.
This problem happened only with ES v6.7. For local development I use v7.2 and it works successfully.
I don't know why ES engine 6.7 cannot parse this header. Please, help me if you got the same issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文