2016-09-16 68 views
0

我面临着nodejs elasticsearch库的问题。如果我删除console.log(hello),以下代码正在工作并给出结果;但是,如果我添加这个,那么就没有错误发生。我期待未定义变量“hello”的错误消息。我需要查看错误消息以进行调试。可能是什么原因?Nodejs Elasticsearch错误未显示

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);  
}); 

回答

0

您确定代码到达then函数内吗?也许搜索是抛出一个错误,你没有catch块???

尝试:

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

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

看到,如果你得到任何错误呢?

+0

是的,我错过了“catch”块。谢谢 :) –