Nodejs Elasticsearch错误未显示

时间:2016-09-16 09:34:01

标签: node.js elasticsearch

我遇到了nodejs elasticsearch库的问题。如果我删除 console.log(hello); ,下面的代码正在运行并给出结果但是如果我添加它,那么就不会出现错误。我期待未定义变量“hello”的错误消息。我需要查看错误消息以进行调试。可能是什么原因?

var elasticsearch = require('elasticsearch');
var esClient = new elasticsearch.Client({
  host: 'http://mywebsite.com',
  // log: 'trace'
});


body = {};

esClient.search({
          index: 'test',
          type: 'data',
          body: body
        }).then(function (resp) {

            console.log(hello);
            console.log(resp);    
});

1 个答案:

答案 0 :(得分:0)

您确定代码到达then功能吗?也许搜索会抛出一个错误而你没有catch阻止???

尝试:

esClient.search({...})
        .then(function (resp) {

            console.log(hello);
            console.log(resp);    
        })
        .catch(function(error){
            console.log(error);    
        });

看看你是否收到任何错误?