【问题标题】:Unhandled rejection Error: Content-Type header [] is not supported未处理的拒绝错误:不支持 Content-Type 标头 []
【发布时间】:2018-11-10 19:47:19
【问题描述】:

我的 Node.js 应用程序中有一个弹性查询,如下所示。我正在使用弹性搜索版本 6.2.2。但是当我从邮递员执行 API 时,它显示以下错误:

Unhandled rejection Error: Content-Type header [] is not supported


exports.radix = function (req, res) {
        var elasticsearch = require('elasticsearch'),
client = new elasticsearch.Client({
  host: 'localhost:9200'
});
client.search({
index: 'xpertradix',
type: 'search',
size: 20,
body: {
  query: {
    match: {
      name: req.param('term')
    }
  }
}
 }).then(function (resp) {
   var data = helper.prepareRadix(resp.hits.hits);
   res.json(data);
});
};

我已经苦苦挣扎了 2 天来解决这个问题。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 在编程笔记中,如果您使用的是then,请务必同时添加.catch,这样您就可以实际调试/检查您的错误案例。

标签: node.js express elasticsearch mongoose mean-stack


【解决方案1】:

问题是从 Elastic search 6 开始,我们必须在查询中发送 headers。所以我添加了 headers 如下,

var client = elasticsearch.Client({
hosts: [{
  host: 'loalhost,
  port: 9200,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
}]

})

从以下文档中, Link1

LINK2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2019-05-24
    • 2018-05-12
    • 2018-06-20
    • 1970-01-01
    • 2017-06-08
    • 2018-07-09
    相关资源
    最近更新 更多