首页 > 解决方案 > 未处理的拒绝错误:不支持 Content-Type 标头 []

问题描述

我的 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 天。有人可以帮我解决这个问题吗?

标签: node.jsexpresselasticsearchmongoosemean-stack

解决方案


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

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

})

从以下文档中, Link1

链接2


推荐阅读